Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion everblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ public function getContent()

if ((bool) Tools::isSubmit('submitBackupBlocks') === true) {
$backuped = EverblockTools::exportModuleTablesSQL();
if ((bool) $backuped === true) {
$configBackuped = EverblockTools::exportConfigurationSQL();
if ((bool) $backuped === true && (bool) $configBackuped === true) {
$this->postSuccess[] = $this->l('Backup done');
} else {
$this->postErrors[] = $this->l('Backup failed');
Expand Down
49 changes: 49 additions & 0 deletions models/EverblockTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,55 @@ public static function exportModuleTablesSQL(): bool
return false;
}

/**
* Exporte la table de configuration dans un fichier SQL.
*
* @return bool True en cas de succès, sinon False.
*/
public static function exportConfigurationSQL(): bool
{
$tableName = _DB_PREFIX_ . 'configuration';
if (!static::ifTableExists($tableName)) {
return false;
}
$db = Db::getInstance();
$sqlData = '';
$tableName = bqSQL(trim($tableName));
$createTableSql = static::getTableStructure($tableName);
$sqlData .= "DROP TABLE IF EXISTS `$tableName`;\n";
$sqlData .= "$createTableSql;\n";
$sql = 'SELECT * FROM `' . $tableName . '`';
$result = $db->executeS($sql);
if ($result) {
foreach ($result as $row) {
$sqlData .= "INSERT INTO `$tableName` (";
$escapedKeys = array_map([Db::getInstance(), 'escape'], array_keys($row));
$escapedKeys = array_map(function ($key) {
return "`$key`";
}, $escapedKeys);
$sqlData .= implode(',', $escapedKeys);
$sqlData .= ") VALUES (";
$escapedValues = [];
foreach ($row as $value) {
if (is_null($value)) {
$escapedValues[] = 'NULL';
} elseif (is_numeric($value)) {
$escapedValues[] = (int) $value;
} else {
$escapedValues[] = "'" . pSQL($value) . "'";
}
}
$sqlData .= implode(',', $escapedValues);
$sqlData .= ");\n";
}
}
$filePath = _PS_MODULE_DIR_ . 'everblock/configuration.sql';
if (file_put_contents($filePath, $sqlData)) {
return true;
}
return false;
}

/**
* Récupère la structure d'une table dans la base de données.
* @param string $tableName Nom de la table.
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ExecuteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
if ($action === 'saveblocks') {
$backuped = EverblockTools::exportModuleTablesSQL();
if ((bool) $backuped === true) {
$configBackuped = EverblockTools::exportConfigurationSQL();
if ((bool) $backuped === true && (bool) $configBackuped === true) {
try {
$modulePath = _PS_MODULE_DIR_ . 'everblock/';
$this->copyDirectory($modulePath . 'views/css', $modulePath . 'views/backup/css');
Expand Down