-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from WeareJH/bugfix/fix-import-command
Fix DB dump import command
- Loading branch information
Showing
7 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jh\StrippedDbProvider\Model\Db; | ||
|
||
use Ifsnop\Mysqldump\Mysqldump; | ||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
use Jh\StrippedDbProvider\Model\Config; | ||
use Jh\StrippedDbProvider\Model\ProjectMeta; | ||
use Magento\Framework\Shell; | ||
|
||
class DbAdminAccountsManager | ||
{ | ||
private const BACKUP_FILENAME = 'admin_accounts.sql'; | ||
|
||
public function __construct( | ||
private Config $config, | ||
private Shell $shell | ||
) { | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function backupAdminAccounts(ProjectMeta $projectMeta): void | ||
{ | ||
$hostName = $this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_HOST); | ||
$dbName = $this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_NAME); | ||
$dumper = new Mysqldump( | ||
"mysql:host={$hostName};dbname={$dbName}", | ||
$this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_USER), | ||
$this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_PASSWORD), | ||
[ | ||
'skip-definer' => true, | ||
'add-drop-table' => true, | ||
'include-tables' => [ | ||
'admin_passwords', | ||
'admin_system_messages', | ||
'admin_user', | ||
'admin_user_session', | ||
'authorization_role', | ||
'authorization_rule' | ||
] | ||
] | ||
); | ||
|
||
$dumper->start($this->getAdminAccountsBackupFilePath($projectMeta)); | ||
} | ||
|
||
public function restoreAdminAccountsBackup(ProjectMeta $projectMeta): void | ||
{ | ||
$hostName = $this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_HOST); | ||
$dbName = $this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_NAME); | ||
$dumper = new Mysqldump( | ||
"mysql:host={$hostName};dbname={$dbName}", | ||
$this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_USER), | ||
$this->config->getLocalDbConfigData(ConfigOptionsListConstants::KEY_PASSWORD), | ||
['skip-definer' => true] | ||
); | ||
$dumper->restore($this->getAdminAccountsBackupFilePath($projectMeta)); | ||
} | ||
|
||
public function cleanUp(ProjectMeta $projectMeta): void | ||
{ | ||
try { | ||
$this->shell->execute("rm %s", [$this->getAdminAccountsBackupFilePath($projectMeta)]); | ||
} catch (\Exception $e) { | ||
//empty | ||
} | ||
} | ||
|
||
private function getAdminAccountsBackupFilePath(ProjectMeta $projectMeta): string | ||
{ | ||
return $projectMeta->getLocalDumpStoragePath() . self::BACKUP_FILENAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters