/** * Create backups (DB data and object configs) * @return void */ public function makebackupAction() { $this->_checkCanEdit(); ini_set('ignore_user_abort', 'On'); ini_set('max_execution_time', 3600); $dumpdir = $this->_configMain->get('backups'); $destPath = $dumpdir . date('d-m-Y_H_i_s'); $docRoot = $this->_configMain->get('docroot'); $sqlPath = $this->_configMain->get('tmp') . 'dump.sql'; if (!is_writable($dumpdir)) { Response::jsonError($this->_lang->CANT_WRITE_FS); } $dbConfig = Registry::get('db', 'config'); $cmd = $this->_configMain->get('mysqlDumpExecPath') . ' -u' . $dbConfig->get('username') . ' -p' . $dbConfig->get('password') . ' --add-drop-table -R -K ' . $dbConfig->get('dbname') . ' > ' . $sqlPath; system($cmd); $files = array_merge(File::scanFiles($this->_configMain->get('object_configs'), array('.php'), true, File::Files_Only), File::scanFiles($this->_configMain->get('dictionary_folder'), array('.php'), true, File::Files_Only), File::scanFiles($this->_configMain->get('modules'), array('.php'), true, File::Files_Only), File::scanFiles($this->_configMain->get('lang_path'), array('.php'), true, File::Files_Only)); $files[] = $sqlPath; /** * This is hard fix for windows */ if (Utils::isWindows()) { foreach ($files as &$v) { $v = str_replace('\\', '/', $v); $v = str_replace('//', '/', $v); } unset($v); $docRoot .= '/'; } if ($this->_hasZipModule()) { if (!File::zipFiles($destPath, $files, $docRoot)) { Response::jsonError($this->_lang->CANT_WRITE_FS); } } else { $pathsToCheck = array(); foreach ($files as $file) { $pathsToCheck[] = str_replace($docRoot, $destPath . '/', $file); } $permCheck = File::checkWritePermission($pathsToCheck); if ($permCheck !== true) { Response::jsonError($this->_lang->CANT_WRITE_FS . ':<br>' . implode('<br>', $permCheck)); } File::copyFiles($destPath . '/', $files, $docRoot); } if (file_exists($sqlPath) && is_writable($sqlPath)) { @unlink($sqlPath); } Response::jsonSuccess(); }
protected function _updateFromSystem($from) { $files = File::scanFiles($from); if (empty($files)) { $this->_errorStatus = self::ERROR_EMPTY_BACKUP; return false; } $pathsToCheck = array(); if ($this->sql) { foreach ($files as $key => $file) { if (strrchr($file, '.') === '.sql') { $this->_sqlPaths[] = $file; unset($files[$key]); } $pathsToCheck[] = str_replace($from, $this->_docRoot, $file); } } $permCheck = File::checkWritePermission($pathsToCheck); if ($permCheck !== true) { $this->_errorStatus = self::ERROR_CANT_WRITE; $this->_errors = $permCheck; return false; } if ($this->execSql && !empty($this->_sqlPaths)) { foreach ($this->_sqlPaths as $path) { if (!$this->_restoreSql($path)) { $this->_errorStatus = self::ERROR_SQL_FAIL; return false; } if (file_exists($path)) { unlink($path); } } } if (!File::copyFiles($this->_docRoot, $files, $from)) { $this->_errorStatus = self::ERROR_CANT_WRITE; return false; } else { return true; } }