-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database Rollback not working M2.3.0 #21151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
/** | ||
* Class GetListTables | ||
*/ | ||
class GetListTables | ||
{ | ||
private const TABLE_TYPE = 'BASE TABLE'; | ||
|
||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @param ResourceConnection $resource | ||
*/ | ||
public function __construct(ResourceConnection $resource) | ||
{ | ||
$this->resource = $resource; | ||
} | ||
|
||
/** | ||
* Get base tables | ||
* | ||
* @return array | ||
*/ | ||
public function execute() | ||
{ | ||
return $this->resource->getConnection('backup')->fetchCol( | ||
"SHOW FULL TABLES WHERE `Table_type` = ?", | ||
self::TABLE_TYPE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate constant... Delete one please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like github's suggested change doesn't work properly... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is a BETA feature. Maybe sometimes doesn't work properly. Sorry |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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; | ||
|
||
/** | ||
* Class GetListViews | ||
*/ | ||
class GetListViews | ||
{ | ||
private const TABLE_TYPE = 'VIEW'; | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @param ResourceConnection $resource | ||
*/ | ||
public function __construct(ResourceConnection $resource) | ||
{ | ||
$this->resource = $resource; | ||
} | ||
|
||
/** | ||
* Get view tables | ||
* | ||
* @return array | ||
*/ | ||
public function execute() | ||
{ | ||
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,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; | ||
|
||
/** | ||
* Class GetViewsBackup | ||
*/ | ||
class GetViewsBackup | ||
{ | ||
/** | ||
* @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; | ||
} | ||
|
||
/** | ||
* Backup | ||
* | ||
* @param BackupInterface $backup | ||
*/ | ||
public function execute(BackupInterface $backup) | ||
{ | ||
$views = $this->getListViews->execute(); | ||
|
||
foreach ($views as $view) { | ||
$backup->write($this->getViewHeader($view)); | ||
$backup->write($this->getDropViewSql($view)); | ||
$backup->write($this->getShowCreateView($view)); | ||
} | ||
} | ||
|
||
/** | ||
* Get connection | ||
* | ||
* @return AdapterInterface | ||
*/ | ||
private function getConnection() | ||
{ | ||
if (!$this->connection) { | ||
$this->connection = $this->resourceConnection->getConnection('backup'); | ||
} | ||
|
||
return $this->connection; | ||
} | ||
|
||
/** | ||
* Get show create view | ||
* | ||
* @param string $viewName | ||
* @return string | ||
*/ | ||
private function getShowCreateView($viewName) | ||
{ | ||
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName); | ||
$query = 'SHOW CREATE VIEW ' . $quotedViewName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creating View we have to use this syntax
the same we do in MSI - https://github.com/magento-engcom/msi/blob/2.3-develop/app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php#L69 https://dev.mysql.com/doc/refman/5.6/en/stored-programs-security.html
In opposite case, MySQL user working with Magento would not be possible to invoke the View after creation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So it's ok with the current implementation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, we already use |
||
$row = $this->getConnection()->fetchRow($query); | ||
$regExp = '/\sDEFINER\=\`([^`]*)\`\@\`([^`]*)\`/'; | ||
$sql = preg_replace($regExp, '', $row['Create View']); | ||
|
||
return $sql . ';' . "\n"; | ||
} | ||
|
||
/** | ||
* Get view header | ||
* | ||
* @param string $viewName | ||
* @return string | ||
*/ | ||
public function getViewHeader($viewName) | ||
{ | ||
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName); | ||
return "\n--\n" . "-- Structure for view {$quotedViewName}\n" . "--\n\n"; | ||
} | ||
|
||
/** | ||
* Get drop view SQL | ||
* | ||
* @param string $viewName | ||
* @return string | ||
*/ | ||
public function getDropViewSql($viewName) | ||
{ | ||
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName); | ||
return sprintf('DROP VIEW IF EXISTS %s;' . "\n", $quotedViewName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be added to end of the construct Backward Compatibility (Adding a constructor parameter)