/** * (non-PHPdoc) * @see Bgtask_Abstract::run() */ public function run() { $lang = Lang::lang(); $appConfig = Registry::get('main', 'config'); $deployCfg = Config::factory(Config::File_Array, $appConfig->get('configs') . 'deploy.php'); $this->setTotalCount(3); $dirName = $deployCfg->get('datadir') . $this->_config['server'] . DIRECTORY_SEPARATOR . date('Y-m-d_H_i_s'); if (!is_dir($dirName) && !mkdir($dirName, 0775, true)) { $this->error($lang->CANT_WRITE_FS . '(' . $dirName . ')'); } $dirName .= DIRECTORY_SEPARATOR; $this->_nextStep(); if (isset($this->_config['files']) && !empty($this->_config['files']) && is_array($this->_config['files'])) { if (!File::zipFiles($dirName . 'www.zip', $this->_config['files'], $dirName)) { $this->error($lang->CANT_WRITE_FS . '(' . $dirName . 'www.zip' . ')'); } } $this->_nextStep(); if (isset($this->_config['files_delete']) && !empty($this->_config['files_delete']) && is_array($this->_config['files_delete'])) { if (!@file_put_contents($dirName . 'delete.txt', implode("\n", $this->_config['files_delete']))) { $this->error($lang->CANT_WRITE_FS . '(' . $dirName . 'delete.txt' . ')'); } if (!File::zipFiles($dirName . 'www.zip', array($dirName . 'delete.txt'), $dirName)) { $this->error($lang->CANT_WRITE_FS . '(' . $dirName . 'www.zip' . ')'); } unlink($dirName . 'delete.txt'); } $this->_nextStep(); $this->finish(); }
/** * 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(); }