'.Date::format($filename, BACKUP_DATE_FORMAT, 'F j, Y, g:i a').'
';
// Allow download if a zip file
if ($this->zip) {
$html .= ' '.$L->get('download').'';
}
$html .= '';
$html .= '';
$html .= '
';
$html .= '';
}
return $html;
}
/**
* Downloading Backups is not allowed by default server config
* This webhook is to allow downloads for admins
* Webhook: plugin-backup-download?file={backup-name.zip}
*/
public function beforeAll()
{
global $L;
$webhook = 'plugin-backup-download';
if ($this->webhook($webhook)) {
if (!empty($_GET['file'])) {
$login = new Login();
if ($login->role() === 'admin') {
downloadRestrictedFile(PATH_WORKSPACES.'backup/'.$_GET['file']);
} else {
Alert::set($L->g('You do not have sufficient permissions'));
Redirect::page('dashboard');
}
}
exit(0);
}
}
public function backupList()
{
if ($this->zip) {
$backups = Filesystem::listFiles($this->workspace(), '*', 'zip', true);
} else {
$backups = Filesystem::listDirectories($this->workspace(), '*', true);
}
return $backups;
}
public function createBackup()
{
// Current backup directory
$currentDate = Date::current(BACKUP_DATE_FORMAT);
$backupDir = $this->workspace().$currentDate;
// Copy directories to backup directory
// $directoriesToBackup is a private variable of this class
foreach ($this->directoriesToBackup as $dir) {
$destination = $backupDir.DS.basename($dir);
Filesystem::copyRecursive($dir, $destination);
}
// Compress backup directory
if ($this->zip) {
if (Filesystem::zip($backupDir, $backupDir.'.zip')) {
Filesystem::deleteRecursive($backupDir);
}
}
return true;
}
public function restoreBackup($filename)
{
// Remove current files
foreach ($this->directoriesToBackup as $dir) {
Filesystem::deleteRecursive($dir);
}
// Recover backuped files
// Zip format
if ($this->zip) {
$tmp = $this->workspace().$filename.'.zip';
return Filesystem::unzip($tmp, PATH_CONTENT);
}
// Directory format
$tmp = $this->workspace().$filename;
return Filesystem::copyRecursive($tmp, PATH_CONTENT);
}
public function deleteBackup($filename)
{
// Zip format
if ($this->zip) {
$tmp = $this->workspace().$filename.'.zip';
return Filesystem::rmfile($tmp);
}
// Directory format
$tmp = $this->workspace().$filename;
return Filesystem::deleteRecursive($tmp);
}
}