Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop Minor Fixes
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #21151: Database Rollback not working M2.3.0 (by @Stepa4man)
 - #21458: Elasticsearch6 implementation. (by @romainruaud)
  • Loading branch information
magento-engcom-team authored Mar 2, 2019
2 parents 20627b0 + 6cb3da9 commit e51df41
Show file tree
Hide file tree
Showing 25 changed files with 2,266 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/AdvancedSearch/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@
</depends>
</field>
<!--<group id="suggestions">-->
<field id="search_suggestion_enabled" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="search_suggestion_enabled" translate="label comment" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Search Suggestions</label>
<comment>When you enable this option your site may slow down.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="search_suggestion_count" translate="label" type="text" sortOrder="71" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="search_suggestion_count" translate="label" type="text" sortOrder="91" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Search Suggestions Count</label>
<depends>
<field id="search_suggestion_enabled">1</field>
</depends>
</field>
<field id="search_suggestion_count_results_enabled" translate="label" type="select" sortOrder="72" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="search_suggestion_count_results_enabled" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Results Count for Each Suggestion</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>When you enable this option your site may slow down.</comment>
Expand Down
29 changes: 25 additions & 4 deletions app/code/Magento/Backup/Model/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Backup\Model;

use Magento\Backup\Helper\Data as Helper;
use Magento\Backup\Model\ResourceModel\Table\GetListTables;
use Magento\Backup\Model\ResourceModel\View\CreateViewsBackup;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\RuntimeException;

Expand Down Expand Up @@ -44,18 +46,35 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
private $helper;

/**
* @param \Magento\Backup\Model\ResourceModel\Db $resourceDb
* @var GetListTables
*/
private $getListTables;

/**
* @var CreateViewsBackup
*/
private $getViewsBackup;

/**
* Db constructor.
* @param ResourceModel\Db $resourceDb
* @param \Magento\Framework\App\ResourceConnection $resource
* @param Helper|null $helper
* @param GetListTables|null $getListTables
* @param CreateViewsBackup|null $getViewsBackup
*/
public function __construct(
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
ResourceModel\Db $resourceDb,
\Magento\Framework\App\ResourceConnection $resource,
?Helper $helper = null
?Helper $helper = null,
?GetListTables $getListTables = null,
?CreateViewsBackup $getViewsBackup = null
) {
$this->_resourceDb = $resourceDb;
$this->_resource = $resource;
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
$this->getListTables = $getListTables ?? ObjectManager::getInstance()->get(GetListTables::class);
$this->getViewsBackup = $getViewsBackup ?? ObjectManager::getInstance()->get(CreateViewsBackup::class);
}

/**
Expand Down Expand Up @@ -161,7 +180,7 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu

$this->getResource()->beginTransaction();

$tables = $this->getResource()->getTables();
$tables = $this->getListTables->execute();

$backup->write($this->getResource()->getHeader());

Expand Down Expand Up @@ -198,6 +217,8 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu
$backup->write($this->getResource()->getTableDataAfterSql($table));
}
}
$this->getViewsBackup->execute($backup);

$backup->write($this->getResource()->getTableForeignKeysSql());
$backup->write($this->getResource()->getTableTriggersSql());
$backup->write($this->getResource()->getFooter());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backup\Model\ResourceModel\Table;

use Magento\Framework\App\ResourceConnection;

/**
* Provides full list of tables in the database. This list excludes views, to allow different backup process.
*/
class GetListTables
{
private const TABLE_TYPE = 'BASE TABLE';

/**
* @var ResourceConnection
*/
private $resource;

/**
* @param ResourceConnection $resource
*/
public function __construct(ResourceConnection $resource)
{
$this->resource = $resource;
}

/**
* Get list of database tables excluding views.
*
* @return array
*/
public function execute(): array
{
return $this->resource->getConnection('backup')->fetchCol(
"SHOW FULL TABLES WHERE `Table_type` = ?",
self::TABLE_TYPE
);
}
}
116 changes: 116 additions & 0 deletions app/code/Magento/Backup/Model/ResourceModel/View/CreateViewsBackup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backup\Model\ResourceModel\View;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Backup\Db\BackupInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;

/**
* Creates backup of Views in the database.
*/
class CreateViewsBackup
{
/**
* @var GetListViews
*/
private $getListViews;

/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var AdapterInterface
*/
private $connection;

/**
* @param GetListViews $getListViews
* @param ResourceConnection $resourceConnection
*/
public function __construct(
GetListViews $getListViews,
ResourceConnection $resourceConnection
) {
$this->getListViews = $getListViews;
$this->resourceConnection = $resourceConnection;
}

/**
* Write backup data to backup file.
*
* @param BackupInterface $backup
*/
public function execute(BackupInterface $backup): void
{
$views = $this->getListViews->execute();

foreach ($views as $view) {
$backup->write($this->getViewHeader($view));
$backup->write($this->getDropViewSql($view));
$backup->write($this->getCreateView($view));
}
}

/**
* Retrieve Database connection for Backup.
*
* @return AdapterInterface
*/
private function getConnection(): AdapterInterface
{
if (!$this->connection) {
$this->connection = $this->resourceConnection->getConnection('backup');
}

return $this->connection;
}

/**
* Get CREATE VIEW query for the specific view.
*
* @param string $viewName
* @return string
*/
private function getCreateView(string $viewName): string
{
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
$query = 'SHOW CREATE VIEW ' . $quotedViewName;
$row = $this->getConnection()->fetchRow($query);
$regExp = '/\sDEFINER\=\`([^`]*)\`\@\`([^`]*)\`/';
$sql = preg_replace($regExp, '', $row['Create View']);

return $sql . ';' . "\n";
}

/**
* Prepare a header for View being dumped.
*
* @param string $viewName
* @return string
*/
public function getViewHeader(string $viewName): string
{
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
return "\n--\n" . "-- Structure for view {$quotedViewName}\n" . "--\n\n";
}

/**
* Make sure that View being created is deleted if already exists.
*
* @param string $viewName
* @return string
*/
public function getDropViewSql(string $viewName): string
{
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
return sprintf('DROP VIEW IF EXISTS %s;\n', $quotedViewName);
}
}
44 changes: 44 additions & 0 deletions app/code/Magento/Backup/Model/ResourceModel/View/GetListViews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backup\Model\ResourceModel\View;

use Magento\Framework\App\ResourceConnection;

/**
* Get list of database views.
*/
class GetListViews
{
private const TABLE_TYPE = 'VIEW';

/**
* @var ResourceConnection
*/
private $resource;

/**
* @param ResourceConnection $resource
*/
public function __construct(ResourceConnection $resource)
{
$this->resource = $resource;
}

/**
* Get list of database views.
*
* @return array
*/
public function execute(): array
{
return $this->resource->getConnection('backup')->fetchCol(
"SHOW FULL TABLES WHERE `Table_type` = ?",
self::TABLE_TYPE
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Elasticsearch6\Block\Adminhtml\System\Config;

/**
* Elasticsearch 6.x test connection block
*/
class TestConnection extends \Magento\AdvancedSearch\Block\Adminhtml\System\Config\TestConnection
{
/**
* @inheritdoc
*/
protected function _getFieldMapping()
{
$fields = [
'engine' => 'catalog_search_engine',
'hostname' => 'catalog_search_elasticsearch6_server_hostname',
'port' => 'catalog_search_elasticsearch6_server_port',
'index' => 'catalog_search_elasticsearch6_index_prefix',
'enableAuth' => 'catalog_search_elasticsearch6_enable_auth',
'username' => 'catalog_search_elasticsearch6_username',
'password' => 'catalog_search_elasticsearch6_password',
'timeout' => 'catalog_search_elasticsearch6_server_timeout',
];

return array_merge(parent::_getFieldMapping(), $fields);
}
}
Loading

0 comments on commit e51df41

Please sign in to comment.