Add db backup/restore
This commit is contained in:
25
inc/db.php
25
inc/db.php
@@ -122,6 +122,29 @@ class Db extends PhpObject
|
||||
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
||||
}
|
||||
|
||||
public function getBackup() {
|
||||
$sBackupFile = uniqid('backup_').'.sql';
|
||||
|
||||
$sAppPath = '';
|
||||
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $sAppPath = 'C:\ProgramData\xampp\mysql\bin\\';
|
||||
exec($sAppPath.'mysqldump --user='.Settings::DB_LOGIN.' --password='.Settings::DB_PASS.' --databases '.Settings::DB_NAME.' --add-drop-database --result-file='.$sBackupFile);
|
||||
if(file_exists($sBackupFile)) {
|
||||
$sBackup = file_get_contents($sBackupFile);
|
||||
unlink($sBackupFile);
|
||||
return $sBackup;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public function restoreBackup($sBackupFile) {
|
||||
$sAppPath = '';
|
||||
if(file_exists($sBackupFile)) {
|
||||
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $sAppPath = 'C:\ProgramData\xampp\mysql\bin\\';
|
||||
return exec($sAppPath.'mysql --user='.Settings::DB_LOGIN.' --password='.Settings::DB_PASS.' '.Settings::DB_NAME.' < '.$sBackupFile);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public function loadFile($sFilePath) {
|
||||
set_time_limit(0);
|
||||
$bResult = false;
|
||||
@@ -474,7 +497,7 @@ class Db extends PhpObject
|
||||
//linked tables
|
||||
switch($sTableName)
|
||||
{
|
||||
case array_key_exists($sTableName, $this->asOptions['cascading_delete']) :
|
||||
case (array_key_exists('cascading_delete', $this->asOptions) && array_key_exists($sTableName, $this->asOptions['cascading_delete'])) :
|
||||
$asTables = array_merge(is_array($sTableName)?array_values($sTableName):array($sTableName), array_values($this->asOptions['cascading_delete'][$sTableName]));
|
||||
break;
|
||||
case is_string($sTableName) :
|
||||
|
||||
@@ -93,13 +93,13 @@ abstract class Main extends PhpObject
|
||||
$this->setMasks();
|
||||
}
|
||||
|
||||
public static function addTimestampToFilePath($sFile)
|
||||
public static function addTimestampToFilePath($sFilePath)
|
||||
{
|
||||
//Remove timestamp
|
||||
$sFilePath = preg_replace('/(.*)\?[\d]{14}$/', '$1', $sFile);
|
||||
$sCleanedFilePath = preg_replace('/(.*)\?[\d]{14}$/', '$1', $sFilePath);
|
||||
|
||||
//Add timestamp
|
||||
return file_exists($sFilePath)?$sFilePath.'?'.date("YmdHis", filemtime($sFilePath)):$sFile;
|
||||
return file_exists($sCleanedFilePath)?$sCleanedFilePath.'?'.date("YmdHis", filemtime($sCleanedFilePath)):$sFilePath;
|
||||
}
|
||||
|
||||
public function addUncaughtError($sError)
|
||||
|
||||
@@ -126,6 +126,32 @@ class ToolBox
|
||||
return json_encode($asData);
|
||||
}
|
||||
|
||||
public static function curl($sUrl, $bHeader=false, $asPostData=array(), $sCookie='', $sCreds='') {
|
||||
$oCurl = curl_init();
|
||||
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
|
||||
curl_setopt($oCurl, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, $bHeader);
|
||||
if($bHeader) curl_setopt($oCurl, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
if(!empty($asPostData)) {
|
||||
curl_setopt($oCurl, CURLOPT_POST, 1);
|
||||
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $asPostData);
|
||||
}
|
||||
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
||||
|
||||
if($sCookie!='') curl_setopt($oCurl, CURLOPT_COOKIE, $sCookie);
|
||||
if($sCreds!='') curl_setopt($oCurl, CURLOPT_USERPWD, $sCreds);
|
||||
|
||||
$sContent = curl_exec($oCurl);
|
||||
curl_close($oCurl);
|
||||
return $sContent;
|
||||
}
|
||||
|
||||
public static function getMimeType($sPath, $bSubTypeOnly=false)
|
||||
{
|
||||
$sMimetype = '';
|
||||
|
||||
Reference in New Issue
Block a user