first commit
This commit is contained in:
152
admin/lists/DbbackupList.php
Normal file
152
admin/lists/DbbackupList.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
use KupShop\AdminBundle\AdminList\BaseList;
|
||||
use KupShop\KupShopBundle\Util\HtmlBuilder\HTML;
|
||||
|
||||
class DbbackupList extends BaseList
|
||||
{
|
||||
protected $template = 'list/dbbackup.tpl';
|
||||
|
||||
protected $tableDef = [
|
||||
'id' => '',
|
||||
'fields' => [
|
||||
'Záloha' => ['field' => 'name'],
|
||||
'Velikost' => ['field' => 'size', 'render' => 'renderSize'],
|
||||
'Datum vytvoření' => ['field' => 'date', 'render' => 'renderTimestamp'],
|
||||
'Smazat zálohu' => ['field' => 'name', 'render' => 'renderDelete'],
|
||||
'Pojmenovat zálohu' => ['field' => 'name', 'render' => 'renderRename'],
|
||||
'Obnovit zálohu databáze' => ['field' => 'name', 'render' => 'renderRestore'],
|
||||
'Stáhnout' => ['field' => 'download', 'render' => 'renderDownload'],
|
||||
],
|
||||
'class' => 'dbbackup',
|
||||
];
|
||||
|
||||
protected $showExport = false;
|
||||
|
||||
public function renderDownload($values, $column)
|
||||
{
|
||||
return HTML::create('a')
|
||||
->attr('href', 'launch.php?s=dbbackup.php&acn=download&file='.$values['name'])
|
||||
->text('Stáhnout');
|
||||
}
|
||||
|
||||
public function renderSize($values, $column)
|
||||
{
|
||||
return $this->getListRowValue($values, $column['field']).' kB';
|
||||
}
|
||||
|
||||
public function renderTimestamp($values, $column)
|
||||
{
|
||||
return date('d.m.Y H:i:s', $this->getListRowValue($values, $column['field']));
|
||||
}
|
||||
|
||||
public function renderDelete($values, $column)
|
||||
{
|
||||
if (findRight('OTH_BACKUP_ERASE')) {
|
||||
$value = $this->getListRowValue($values, $column['field']);
|
||||
|
||||
return HTML::create('a')
|
||||
->class('confirm')
|
||||
->attr('title', 'Smazat zálohu')
|
||||
->attr('href', 'launch.php?s=dbbackup.php&acn=do&do=erase&dbBackup='.urlencode($value))
|
||||
->tag('span')
|
||||
->class('btn btn-xs btn-secondary')
|
||||
->tag('i')
|
||||
->class('bi bi-trash')
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function renderRename($values, $column)
|
||||
{
|
||||
if (findRight('OTH_BACKUP_ERASE')) {
|
||||
$value = $this->getListRowValue($values, $column['field']);
|
||||
$name = preg_replace('/.sql(.bz2)?/i', '', $value);
|
||||
|
||||
return HTML::create('a')
|
||||
->attr('data-rename', $name)
|
||||
->attr('title', 'Pojmenovat zálohu')
|
||||
->attr('href', 'launch.php?s=dbbackup.php&acn=do&do=rename&dbBackup='.urlencode($value))
|
||||
->tag('span')
|
||||
->class('btn btn-xs btn-secondary')
|
||||
->tag('i')
|
||||
->class('bi bi-tag')
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function renderRestore($values, $column)
|
||||
{
|
||||
if (findRight('OTH_BACKUP_REFRESH') && !isLive()) {
|
||||
$value = $this->getListRowValue($values, $column['field']);
|
||||
|
||||
return HTML::create('a')
|
||||
->class('confirm')
|
||||
->attr('title', 'Obnovit zálohu databáze?
|
||||
|
||||
Pozor! Budou obnovena všechna data.
|
||||
Veškeré změny provedené v e-shopu po datu zálohy budou ztraceny. Včetně objednávek, stránek a dalších.
|
||||
|
||||
Chcete pokračovat')
|
||||
->attr('href', 'launch.php?s=dbbackup.php&acn=do&do=restore&dbBackup='.urlencode($value))
|
||||
->tag('span')
|
||||
->class('btn btn-xs btn-secondary')
|
||||
->tag('i')
|
||||
->class('bi bi-check-circle')
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getSQL(Query\QueryBuilder $qb)
|
||||
{
|
||||
$SQL = [];
|
||||
|
||||
if ($Dir = @opendir($GLOBALS['cfg']['Path']['db_backup'])) {
|
||||
$files = [];
|
||||
|
||||
while ($fileThis = @readdir($Dir)) {
|
||||
if (!@is_dir($fileThis) && preg_match('/\\.(sql|gz|bz2)$/i', $fileThis)) {
|
||||
$files[] = $fileThis;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$path = $GLOBALS['cfg']['Path']['db_backup'].$file;
|
||||
|
||||
$SQL[] = [
|
||||
'name' => $file,
|
||||
'date' => filemtime($path),
|
||||
'size' => ceil(filesize($path) / 1000),
|
||||
];
|
||||
}
|
||||
|
||||
// Sort by creation date
|
||||
usort($SQL, function ($a, $b) {
|
||||
return $a['date'] > $b['date'] ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
return ['SQL' => $SQL];
|
||||
}
|
||||
|
||||
public function getQuery()
|
||||
{
|
||||
return sqlQueryBuilder();
|
||||
}
|
||||
|
||||
public function handleExportDataFiles()
|
||||
{
|
||||
$exportDataFiles = \KupShop\KupShopBundle\Util\Compat\ServiceContainer::getService(\KupShop\AdminBundle\Util\Export\ExportDataFiles::class);
|
||||
|
||||
$exportDataFiles->export();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user