Skip to content

Commit

Permalink
Merge branch 2.3-develop into ENGCOM-4419-magento-magento2-20391
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-engcom-team committed Mar 6, 2019
2 parents d01854c + 75cf826 commit c172d5f
Show file tree
Hide file tree
Showing 184 changed files with 7,226 additions and 1,013 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
3 changes: 2 additions & 1 deletion app/code/Magento/Backend/App/Request/BackendValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ private function createException(
$exception = new InvalidRequestException($response);
} else {
//For regular requests.
$startPageUrl = $this->backendUrl->getStartupPageUrl();
$response = $this->redirectFactory->create()
->setUrl($this->backendUrl->getStartupPageUrl());
->setUrl($this->backendUrl->getUrl($startPageUrl));
$exception = new InvalidRequestException(
$response,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\Backend\Block\System\Design\Edit\Tab;

/**
* General system tab block.
*/
class General extends \Magento\Backend\Block\Widget\Form\Generic
{
/**
Expand Down Expand Up @@ -90,7 +93,7 @@ protected function _prepareForm()
]
);

$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
$dateFormat = $this->_localeDate->getDateFormatWithLongYear();
$fieldset->addField(
'date_from',
'date',
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
);
}
}
23 changes: 17 additions & 6 deletions app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ private function getDefaultListingMode()
}

/**
* Need use as _prepareLayout - but problem in declaring collection from
* another block (was problem with search result)
* Need use as _prepareLayout - but problem in declaring collection from another block.
* (was problem with search result)
*
* @return $this
*/
protected function _beforeToHtml()
Expand All @@ -188,7 +189,9 @@ protected function _beforeToHtml()

$this->addToolbarBlock($collection);

$collection->load();
if (!$collection->isLoaded()) {
$collection->load();
}

return parent::_beforeToHtml();
}
Expand Down Expand Up @@ -262,6 +265,8 @@ public function getToolbarHtml()
}

/**
* Set collection.
*
* @param AbstractCollection $collection
* @return $this
*/
Expand All @@ -272,7 +277,9 @@ public function setCollection($collection)
}

/**
* @param array|string|integer| Element $code
* Add attribute.
*
* @param array|string|integer|Element $code
* @return $this
*/
public function addAttribute($code)
Expand All @@ -282,6 +289,8 @@ public function addAttribute($code)
}

/**
* Get price block template.
*
* @return mixed
*/
public function getPriceBlockTemplate()
Expand Down Expand Up @@ -371,6 +380,8 @@ public function getAddToCartPostParams(Product $product)
}

/**
* Get product price.
*
* @param Product $product
* @return string
*/
Expand All @@ -396,8 +407,8 @@ public function getProductPrice(Product $product)
}

/**
* Specifies that price rendering should be done for the list of products
* i.e. rendering happens in the scope of product list, but not single product
* Specifies that price rendering should be done for the list of products.
* (rendering happens in the scope of product list, but not single product)
*
* @return Render
*/
Expand Down
Loading

0 comments on commit c172d5f

Please sign in to comment.