// MERGE with 1.4 r7770
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7776 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+49
-4
@@ -31,6 +31,10 @@ class BackupCore
|
||||
public $id;
|
||||
/** @var string Last error messages */
|
||||
public $error;
|
||||
/** @var string default backup directory. */
|
||||
public static $backupDir = '/backups/';
|
||||
/** @var string custom backup directory. */
|
||||
public $customBackupDir = NULL;
|
||||
|
||||
/**
|
||||
* Creates a new backup object
|
||||
@@ -40,24 +44,65 @@ class BackupCore
|
||||
public function __construct($filename = NULL)
|
||||
{
|
||||
if ($filename)
|
||||
$this->id = self::getBackupPath($filename);
|
||||
$this->id = $this->getRealBackupPath($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* you can set a different path with that function
|
||||
*
|
||||
* @TODO include the prefix name
|
||||
* @param string $dir
|
||||
* @return boolean bo
|
||||
*/
|
||||
public function setCustomBackupPath($dir)
|
||||
{
|
||||
$customDir = DIRECTORY_SEPARATOR.trim($dir,'/').DIRECTORY_SEPARATOR;
|
||||
if(is_dir(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.$customDir.DIRECTORY_SEPARATOR))
|
||||
$this->customBackupDir = $customDir;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get the path to use for backup (customBackupDir if specified, or default)
|
||||
*
|
||||
* @param string $filename filename to use
|
||||
* @return string full path
|
||||
*/
|
||||
public function getRealBackupPath($filename = NULL)
|
||||
{
|
||||
$backupDir = Backup::getBackupPath($filename);
|
||||
if (!empty($this->customBackupDir))
|
||||
{
|
||||
$backupDir = str_replace(_PS_ADMIN_DIR_.self::$backupDir, _PS_ADMIN_DIR_.$this->customBackupDir, $backupDir);
|
||||
|
||||
if(strrpos($backupDir,DIRECTORY_SEPARATOR))
|
||||
$backupDir .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
return $backupDir;
|
||||
}
|
||||
/**
|
||||
* Get the full path of the backup file
|
||||
*
|
||||
* @param string $filename Filename of the backup file
|
||||
* @param string $filename prefix of the backup file (datetime will be the second part)
|
||||
* @return The full path of the backup file, or false if the backup file does not exists
|
||||
*/
|
||||
public static function getBackupPath($filename)
|
||||
{
|
||||
$backupdir = realpath(PS_ADMIN_DIR.'/backups/');
|
||||
$backupdir = realpath(_PS_ADMIN_DIR_.self::$backupDir);
|
||||
|
||||
if ($backupdir === false)
|
||||
die(Tools::displayError('Backups directory does not exist.'));
|
||||
|
||||
// Check the realpath so we can validate the backup file is under the backup directory
|
||||
if(!empty($filename))
|
||||
$backupfile = realpath($backupdir.'/'.$filename);
|
||||
else
|
||||
$backupfile = $backupdir.DIRECTORY_SEPARATOR;
|
||||
|
||||
if ($backupfile === false OR strncmp($backupdir, $backupfile, strlen($backupdir)) != 0)
|
||||
die (Tools::displayError());
|
||||
|
||||
@@ -132,7 +177,7 @@ class BackupCore
|
||||
// Generate some random number, to make it extra hard to guess backup file names
|
||||
$rand = dechex ( mt_rand(0, min(0xffffffff, mt_getrandmax() ) ) );
|
||||
$date = time();
|
||||
$backupfile = PS_ADMIN_DIR . '/backups/' . $date . '-' . $rand . '.sql';
|
||||
$backupfile = $this->getRealBackupPath().$date.'-'.$rand.'.sql';
|
||||
|
||||
// Figure out what compression is available and open the file
|
||||
if (function_exists('bzopen'))
|
||||
|
||||
Reference in New Issue
Block a user