public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_dropbox_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     $ad = $this->params['access_details'];
     WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false));
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     if (is_array($files)) {
         foreach ($files as $file) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError());
         $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError();
     }
     WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false));
     if (count($errors) > 0) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_local_send_to_s3_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     WPAdm_Core::log('Start copy files to Amazon S3');
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     foreach ($files as $file) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'local_send_to_s3')->addParam('file', ABSPATH . $file)->addParam('bucket', $this->params['bucket'])->addParam('AccessKeyId', $this->params['AccessKeyId'])->addParam('SecretAccessKey', $this->params['SecretAccessKey']);
         if (isset($this->params['dir']) && !empty($this->params['dir'])) {
             $commandContext->addParam('dir', $this->params['dir']);
         }
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log('S3: ' . $this->queue->getError());
         $errors[] = 'S3: ' . $this->queue->getError();
     }
     WPAdm_Core::log('End copy files to Amazon S3');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/aws-autoloader.php';
     $credentials = new Aws\Common\Credentials\Credentials($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     $client = Aws\S3\S3Client::factory(array('credentials' => $credentials));
     $dir = $context->get('dir') ? $context->get('dir') . "/" : '';
     try {
         if (!empty($dir)) {
             $logs = $client->putObject(array('Bucket' => $context->get('bucket'), 'Key' => $dir, 'Body' => ''));
             WPAdm_Core::log('Create folder ' . $dir);
         }
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $client->putObject(array("Bucket" => $context->get('bucket'), 'Key' => $key, 'Body' => fopen($filePath, 'r+')));
         if ((int) $putRes == 1) {
             WPAdm_Core::log("File({$key}) Upload successfully to Amazon S3");
         }
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     ini_set("memory_limit", "256M");
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     ini_set("memory_limit", "256M");
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     if (!file_exists($af)) {
         WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af));
     }
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         if (!file_exists($af)) {
             WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af));
         }
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     $files_str = implode(',', $files);
     $files_archive = WPAdm_Running::getCommandResultData('archive');
     if (!in_array($files_str, $files_archive)) {
         $archive->add($files_str);
         $files_archive = WPAdm_Running::getCommandResultData('archive');
         $files_archive[] = $files_str;
         if (!empty($files_archive)) {
             WPAdm_Running::setCommandResultData('archive', $files_archive);
         }
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     $archive->add(implode(',', $files));
     return true;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_s3_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     # КОПИРОВАНИЕ ФАЙЛОВ НА S3
     $ad = $this->params['access_details'];
     WPAdm_Core::log('Start copy files to Amazon S3');
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     foreach ($files as $file) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'send_to_s3')->addParam('file', ABSPATH . $file)->addParam('bucket', $ad['bucket'])->addParam('AccessKeyId', $ad['AccessKeyId'])->addParam('SecretAccessKey', $ad['SecretAccessKey'])->addParam('SessionToken', $ad['SessionToken']);
         if (isset($ad['mkdir_for_backup']) && $ad['mkdir_for_backup'] == 1) {
             $commandContext->addParam('dir', $dir);
         }
         if (isset($ad['dir']) && !empty($ad['dir'])) {
             $commandContext->addParam('dir', $dir);
         }
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log('S3: ' . $this->queue->getError());
         $errors[] = 'S3: ' . $this->queue->getError();
     }
     WPAdm_Core::log('Закончили копирование файлов на S3');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     // если привышен максимальный размер архива, создадим новый
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         //WPAdm_Core::log(filesize($af) . ', max=' . $context->get('max_file_size'));
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     //WPAdm_Core::log('Add to archive ' . $af);
     $archive->add(implode(',', $files));
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     //WPAdm_Core::log(print_r($context, true));
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
     $mysqldump = new WPAdm_Mysqldump();
     $mysqldump->host = $context->get('host');
     $mysqldump->user = $context->get('user');
     $mysqldump->password = $context->get('password');
     try {
         $mysqldump->mysqldump($context->get('db'), $context->get('to_file'));
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $res = $dropbox->uploadFile($fromFile, $toFile);
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
     }
     return true;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_dropbox_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     if (isset($this->params['local']) && $this->params['local']) {
         $params_data_cron = WPAdm_Running::getCommandResultData('local_backup');
         $this->params['files'] = $params_data_cron['data'];
         $this->params['access_details']['dir'] = $params_data_cron['name'];
         WPAdm_Core::log(langWPADM::get('', false));
     }
     $this->queue = new WPAdm_Queue($this->id);
     $ad = $this->params['access_details'];
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     if (is_array($files)) {
         $send = false;
         foreach ($files as $file) {
             if (isset($this->params['local']) && $this->params['local']) {
                 $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
                 $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
                 if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) {
                     $msg = langWPADM::get('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.', false, '%file%', $file);
                     WPAdm_Core::log($msg);
                     $errors[] = $msg;
                     break;
                 }
                 if (!empty($data_command) && in_array(ABSPATH . $file, $data_command)) {
                     continue;
                 }
             }
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file);
             if (isset($this->params['local']) && $this->params['local']) {
                 $commandContext->addParam('local', true);
             }
             $this->queue->add($commandContext);
             unset($commandContext);
             $send = true;
         }
     }
     if ($send) {
         WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false));
         $res = $this->queue->save()->execute();
         WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false));
     }
     if (isset($res) && !$res) {
         WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError());
         $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError();
     }
     if (count($errors) > 0) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     } else {
         if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists(WPAdm_Core::getTmpDir() . "/notice-star")) {
             wpadm_wp_full_backup_dropbox::setFlagToTmp('notice-star', time() . "_1d");
         }
         if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) {
             $this->result->setData($this->params['files']);
             $this->result->setSize($params_data_cron['size']);
             $this->result->setValue('md5_data', md5(print_r($this->result->toArray(), 1)));
             $this->result->setValue('name', $params_data_cron['name']);
             $this->result->setValue('time', $params_data_cron['time']);
             $this->result->setValue('type', 'dropbox');
             $this->result->setValue('counts', $params_data_cron['counts']);
             WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}");
         }
     }
     return $this->result;
 }
 public function getResult()
 {
     if ($this->start === false) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         $this->result->setError('Backup process was started, please, wait a few minutes...');
         return $this->result;
     }
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log('Start Backup process...');
     # create db dump
     if (in_array('db', $this->params['types'])) {
         WPAdm_Core::log('Creating Database Dump');
         WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
         $mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
         if (file_exists($mysql_dump_file)) {
             unlink($mysql_dump_file);
         }
         $wp_mysql_params = $this->getWpMysqlParams();
         if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
             WPAdm_Core::log('Optimize Database Tables');
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
             $this->queue->clear()->add($commandContext);
             unset($commandContext);
         }
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
         $res = $this->queue->add($commandContext)->save()->execute();
         if (!$res) {
             WPAdm_Core::log('Error: Dump of Database wasn\'t created(' . $this->queue->getError() . ')');
             $errors[] = 'MySQL Error: ' . $this->queue->getError();
         } elseif (0 == (int) filesize($mysql_dump_file)) {
             $errors[] = 'MySQL Error: Database-Dump File is empty';
             WPAdm_Core::log('Dump of Database wasn\'t created (File of Database-Dump is empty!)');
         } else {
             $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
             WPAdm_Core::log('Database Dump was successfully created(' . $size_dump . 'Mb):' . $mysql_dump_file);
         }
         unset($commandContext);
     }
     $files = array();
     if (in_array('files', $this->params['types'])) {
         WPAdm_Core::log('Create a list of files for Backup');
         $files = $this->createListFilesForArchive();
     }
     if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Error: the list of Backup files is empty';
     }
     // split the file list by 170kbayt lists, To break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) @filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log('List of Backup-Files was successfully created');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log('Backup of Files was started');
     $this->queue->save()->execute();
     WPAdm_Core::log('End of File Backup');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $size = $totalSize / 1024 / 1024;
     /// MByte
     $size = round($size, 2);
     WPAdm_Core::log('Backup Size ' . $size . " Mb");
     $remove_from_server = 0;
     #Removing TMP-files
     WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
     #Removind old backups(if limit the number of stored backups)
     if ($this->params['limit'] != 0) {
         WPAdm_Core::log('Limits of Backups ' . $this->params['limit']);
         WPAdm_Core::log('Removing of old Backups was started');
         $files = glob(ABSPATH . 'wpadm_backups/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
         WPAdm_Core::log('Removing of old Backups was Finished');
     }
     wpadm_class::setBackup(1);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
         WPAdm_Core::log('Backup creating is completed successfully!');
     }
     wpadm_class::backupSend();
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log(langWPADM::get('Start backup', false));
     # create db dump
     WPAdm_Core::log(langWPADM::get('Start create db dump', false));
     $error = WPAdm_Core::mkdir(WPADM_DIR_BACKUP);
     if (!empty($error)) {
         $this->result->setError($error);
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         return $this->result;
     }
     $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log(langWPADM::get('Table optimization', false));
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
         $this->queue->clear()->add($commandContext);
         unset($commandContext);
     }
     $commandContext = new WPAdm_Command_Context();
     $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
     $res = $this->queue->add($commandContext)->save()->execute();
     if (!$res) {
         $log = str_replace('%s', $this->queue->getError(), langWPADM::get('Error: Dump of Database wasn\'t created (%s)', false));
         WPAdm_Core::log($log);
         $errors[] = $log;
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $errors[] = langWPADM::get('MySQL Error: Database-Dump File is empty', false);
         WPAdm_Core::log(langWPADM::get('Dump of Database wasn\'t created (File of Database-Dump is empty!)', false));
     } else {
         $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
         $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
         WPAdm_Core::log($log . $mysql_dump_file);
     }
     unset($commandContext);
     #ЗАРХИВИРУЕМ ФАЙЛЫ
     WPAdm_Core::log(langWPADM::get('Create a list of files for Backup', false));
     $files = $this->createListFilesForArchive();
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = langWPADM::get('Error: the list of Backup files is empty', false);
     }
     // split the file list by 170kbayt lists, To break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('file ' . $f . ' size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log(langWPADM::get('List of Backup-Files was successfully created', false));
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log(langWPADM::get('Backup of Files was started', false));
     $this->queue->save()->execute();
     WPAdm_Core::log(langWPADM::get('End of File Backup', false));
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $remove_from_server = 0;
     if (isset($this->params['storage'])) {
         foreach ($this->params['storage'] as $storage) {
             if ($storage['type'] == 'ftp') {
                 WPAdm_Core::log(langWPADM::get('Begin copying files to FTP', false));
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_ftp')->addParam('file', $file)->addParam('host', $ad['host'])->addParam('port', isset($ad['port']) ? $ad['port'] : 21)->addParam('user', $ad['user'])->addParam('password', $ad['password'])->addParam('dir', $dir)->addParam('http_host', isset($ad['http_host']) ? $ad['http_host'] : '');
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     $log = langWPADM::get('FTP: ', false);
                     WPAdm_Core::log($log . $this->queue->getError());
                     $errors[] = $log . $this->queue->getError();
                 }
                 WPAdm_Core::log(langWPADM::get('Finished copying files to FTP', false));
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             } elseif ($storage['type'] == 's3') {
                 WPAdm_Core::log(langWPADM::get('Begin coping files to S3', false));
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_s3')->addParam('file', $file)->addParam('bucket', $ad['bucket'])->addParam('AccessKeyId', $ad['AccessKeyId'])->addParam('SecretAccessKey', $ad['SecretAccessKey'])->addParam('SessionToken', $ad['SessionToken']);
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     WPAdm_Core::log('S3: ' . $this->queue->getError());
                     $errors[] = 'S3: ' . $this->queue->getError();
                 }
                 WPAdm_Core::log(langWPADM::get('Finished copying files to S3', false));
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             }
         }
         if ($remove_from_server) {
             // удаляем файлы на сервере
             WPAdm_Core::log(langWPADM::get('Remove the backup server', false));
             WPAdm_Core::rmdir($this->dir);
         }
     }
     if (isset($this->params['gd']) && isset($this->params['gd']['key']) && isset($this->params['gd']['secret'])) {
         $this->queue->clear();
         $files = glob($this->dir . '/' . $this->name . '*');
         $files = array_merge_recursive(array($mysql_dump_file), $files);
         WPAdm_Core::log(langWPADM::get('files to google: ', false) . print_r($files, true));
         $n = count($files);
         for ($i = 0; $i < $n; $i++) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_google_drive')->addParam('key', $this->params['gd']['key'])->addParam('secret', $this->params['gd']['secret'])->addParam('token', $this->params['gd']['token'])->addParam('folder_project', $this->params['gd']['folder'])->addParam('folder', $this->name)->addParam('files', $files[$i]);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         $res = $this->queue->save()->execute();
         if (!$res) {
             WPAdm_Core::log(langWPADM::get('Google drive: ', false) . $this->queue->getError());
         }
         //WPAdm_Core::log('google drive' . print_r($this->params, true));
     }
     if (isset($this->params['dropbox']) && isset($this->params['dropbox']['key']) && isset($this->params['dropbox']['secret'])) {
         $this->queue->clear();
         $files = glob($this->dir . '/' . $this->name . '*');
         $files = array_merge_recursive(array($mysql_dump_file), $files);
         WPAdm_Core::log(langWPADM::get('files to dropbox: ', false) . print_r($files, true));
         $n = count($files);
         for ($i = 0; $i < $n; $i++) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $this->params['dropbox']['key'])->addParam('secret', $this->params['dropbox']['secret'])->addParam('token', $this->params['dropbox']['token'])->addParam('folder_project', $this->params['dropbox']['folder'])->addParam('folder', $this->name)->addParam('files', $files[$i]);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         $this->queue->save()->execute();
         if (!$res) {
             WPAdm_Core::log(langWPADM::get('Dropbox: ', false) . $this->queue->getError());
         }
     }
     #Removing TMP-files
     WPAdm_Core::rmdir(WPADM_DIR_BACKUP . '/mysqldump.sql');
     #Removind old backups(if limit the number of stored backups)
     WPAdm_Core::log(langWPADM::get('Start removing old backups', false));
     if ($this->params['limit'] != 0) {
         $files = glob(WPADM_DIR_BACKUP . '/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
     }
     WPAdm_Core::log(langWPADM::get('Finished removing old backups', false));
     WPAdm_Core::log(langWPADM::get('Creating a backup is completed', false));
     wpadm_class::setBackup(2);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
     }
     wpadm_class::backupSend();
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log('Start backup');
     WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
     $mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log('Optimize database tables');
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
         $this->queue->clear()->add($commandContext);
         unset($commandContext);
     }
     $commandContext = new WPAdm_Command_Context();
     $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
     $res = $this->queue->add($commandContext)->save()->execute();
     if (!$res) {
         WPAdm_Core::log('Database dump was not created(' . $this->queue->getError() . ')');
         $errors[] = 'MySQL error: ' . $this->queue->getError();
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $errors[] = 'MySQL error: empty dump-file';
         WPAdm_Core::log('Database dump was not created(empty file)');
     } else {
         WPAdm_Core::log('Database dump created(' . filesize($mysql_dump_file) . 'b):' . $mysql_dump_file);
     }
     unset($commandContext);
     WPAdm_Core::log('Start preparing a list of files');
     $files = array();
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Empty list files';
     }
     // Divide the list of files on the lists from 170 kbytes to break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('file ' . $f . ' size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log('List of files prepared');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log('Getting back up files');
     $this->queue->save()->execute();
     WPAdm_Core::log('Ended up files');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $remove_from_server = 0;
     if (isset($this->params['storage'])) {
         foreach ($this->params['storage'] as $storage) {
             if ($storage['type'] == 's3') {
                 WPAdm_Core::log('Begin coping files to S3');
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_s3')->addParam('file', $file)->addParam('bucket', $ad['bucket'])->addParam('AccessKeyId', $ad['AccessKeyId'])->addParam('SecretAccessKey', $ad['SecretAccessKey'])->addParam('SessionToken', $ad['SessionToken']);
                     if (isset($ad['mkdir_for_backup']) && $ad['mkdir_for_backup'] == 1) {
                         $commandContext->addParam('dir', $this->name);
                     }
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     WPAdm_Core::log('S3: ' . $this->queue->getError());
                     $errors[] = 'S3: ' . $this->queue->getError();
                 }
                 WPAdm_Core::log('Finished copying files to S3');
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             }
         }
         if ($remove_from_server) {
             // удаляем файлы на сервере
             WPAdm_Core::log('Remove the backup server');
             WPAdm_Core::rmdir($this->dir);
         }
     }
     # delete tmpf-files
     WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
     #Remove old archives (over limit)
     WPAdm_Core::log('Start removing old files');
     if ($this->params['limit'] != 0) {
         $files = glob(ABSPATH . 'wpadm_backups/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
     }
     WPAdm_Core::log('Finished delete the old files');
     WPAdm_Core::log('backup completed');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function getResult()
 {
     if ($this->restore) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
         $this->result->setError('');
         WPAdm_Core::log(langWPADM::get('Start Restore process', false));
         $n = count($this->md5_info);
         if (in_array('files', $this->params['types'])) {
             foreach ($this->files_resotre as $key => $file) {
                 if (file_exists($file)) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'restore_backup')->addParam('zip_file', $file);
                     $this->queue->clear()->add($commandContext)->save()->execute();
                     unset($commandContext);
                 }
             }
         }
         if (in_array('db', $this->params['types'])) {
             $this->getWpMysqlParams();
             for ($i = 0; $i < $n; $i++) {
                 if (strpos($this->md5_info[$i], "mysqldump.sql") !== false) {
                     $data = explode("\t", $this->md5_info[$i]);
                     if (isset($this->files_resotre[$data[2]]) && file_exists($this->files_resotre[$data[2]])) {
                         $commandContext = new WPAdm_Command_Context();
                         $commandContext->addParam('command', 'restore_backup')->addParam('file', $data[0])->addParam('zip_file', $this->files_resotre[$data[2]]);
                         $commandContext->addParam('db_password', $this->db_data['password'])->addParam('db_name', $this->db_data['db'])->addParam('db_user', $this->db_data['user'])->addParam('db_host', $this->db_data['host']);
                         $this->queue->clear()->add($commandContext)->save()->execute();
                         unset($commandContext);
                     } else {
                         $log = langWPADM::get('Website "%d" returned an error during backup restoration: Part Backup is not exist "%s" ', false, array('%d', '%s'), array(SITE_HOME, $data[2]));
                         $this->setError($log);
                         WPAdm_Core::log($log);
                         break;
                     }
                 }
             }
         }
     } else {
         WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during restore backup: Files for restore is not exist, check permission your backup data or You can send to us support request using "Help" button on plugin page.', false, array('%d'), array(SITE_HOME)));
     }
     return $this->result;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $local = $context->get('local');
     $file_dropbox = $dropbox->listing($folder_project . $context->get('folder') . '/' . $file_name);
     $send = true;
     if (!isset($file_dropbox['error'])) {
         if ($file_dropbox['bytes'] != filesize($fromFile)) {
             $delete_file = $dropbox->deleteFile($folder_project . $context->get('folder') . '/' . $file_name);
             if (isset($delete_file['error'])) {
                 $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $delete_file['text'] . '"');
                 return false;
             }
             $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
             if (isset($data_command[$fromFile])) {
                 $data_error_command[$fromFile]['count'] += 1;
             } else {
                 $data_error_command[$fromFile] = array();
                 $data_error_command[$fromFile]['count'] = 1;
             }
             WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
         } else {
             $send = false;
         }
     }
     if ($local) {
         $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
         if (empty($data_command) || !in_array($fromFile, $data_command)) {
             if ($send) {
                 $res = $dropbox->uploadFile($fromFile, $toFile, true);
             } else {
                 $this->saveDataCommand($fromFile);
             }
         }
     } else {
         $res = $dropbox->uploadFile($fromFile, $toFile, true);
     }
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
         $this->saveDataCommand($fromFile);
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     if (file_exists($context->get('zip_file'))) {
         require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
         $this->archive = new PclZip($context->get('zip_file'));
         $file = $context->get('file');
         $is_dump = $file && strpos($file, "mysqldump.sql");
         WPAdm_Core::log("Decompression Archive " . basename($context->get('zip_file')));
         if ($is_dump !== false) {
             $inzip = str_replace(ABSPATH, "", $file);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_BY_NAME, $inzip);
         } else {
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_REPLACE_NEWER);
         }
         if ($file_in_zip == 0) {
             WPAdm_Core::log("ERROR Archived: " . $this->archive->errorInfo(true));
             $context->setError("ERROR Archived: " . $this->archive->errorInfo(true));
             return false;
         }
         //WPAdm_Core::log(print_r($file_in_zip, 1));
         if ($is_dump !== false) {
             $db_host = $context->get('db_host');
             if ($db_host !== false) {
                 require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
                 $mysqldump = new WPAdm_Mysqldump();
                 $mysqldump->host = $context->get('db_host');
                 $mysqldump->user = $context->get('db_user');
                 $mysqldump->password = $context->get('db_password');
                 try {
                     $mysqldump->restore($context->get('db_name'), $file);
                 } catch (Exception $e) {
                     $context->setError($e->getMessage());
                     return false;
                 }
             }
         }
     } else {
         $context->setError("File Archive Not Exist " . $context->get('zip_file'));
         WPAdm_Core::log("File Archive Not Exist " . $context->get('zip_file'));
         return false;
     }
     return true;
 }
 public function getResult()
 {
     if ($this->restore) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
         $this->result->setError('');
         WPAdm_Core::log('Start Restore process');
         $n = count($this->md5_info);
         if (in_array('db', $this->params['types'])) {
         }
         if (in_array('files', $this->params['types'])) {
             foreach ($this->files_resotre as $key => $file) {
                 if (file_exists($file)) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'restore_backup')->addParam('zip_file', $file);
                     $this->queue->clear()->add($commandContext)->save()->execute();
                     unset($commandContext);
                 }
             }
         }
         if (in_array('db', $this->params['types'])) {
             $this->getWpMysqlParams();
             for ($i = 0; $i < $n; $i++) {
                 if (strpos($this->md5_info[$i], "mysqldump.sql") !== false) {
                     $data = explode("\t", $this->md5_info[$i]);
                     if (isset($this->files_resotre[$data[2]]) && file_exists($this->files_resotre[$data[2]])) {
                         $commandContext = new WPAdm_Command_Context();
                         $commandContext->addParam('command', 'restore_backup')->addParam('file', $data[0])->addParam('zip_file', $this->files_resotre[$data[2]]);
                         $commandContext->addParam('db_password', $this->db_data['password'])->addParam('db_name', $this->db_data['db'])->addParam('db_user', $this->db_data['user'])->addParam('db_host', $this->db_data['host']);
                         $this->queue->clear()->add($commandContext)->save()->execute();
                         unset($commandContext);
                     } else {
                         $this->setError('File(' . $data[2] . ') not Exist');
                         WPAdm_Core::log('File(' . $data[2] . ') not Exist');
                         break;
                     }
                 }
             }
         }
     } else {
         WPAdm_Core::log('Files to restore is empty');
     }
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log(langWPADM::get('Start Backup process...', false));
     # create db dump
     if (in_array('db', $this->params['types'])) {
         WPAdm_Core::log(langWPADM::get('Creating Database Dump', false));
         $error = WPAdm_Core::mkdir(WPADM_DIR_BACKUP);
         if (!empty($error)) {
             $this->result->setError($error);
             $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
             return $this->result;
         }
         $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
         if (file_exists($mysql_dump_file)) {
             unlink($mysql_dump_file);
         }
         $wp_mysql_params = $this->getWpMysqlParams();
         if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
             WPAdm_Core::log(langWPADM::get('Optimize Database Tables', false));
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
             $this->queue->clear()->add($commandContext);
             unset($commandContext);
         }
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
         $res = $this->queue->add($commandContext)->save()->execute();
         if (!$res) {
             $log = langWPADM::get('Website "%d" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%d', '%s'), array(SITE_HOME, $this->queue->getError()));
             WPAdm_Core::log($log);
             $errors[] = $log;
         } elseif (0 == (int) filesize($mysql_dump_file)) {
             $log = langWPADM::get('Website "%d" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".', false, array('%d', '%dir'), array(SITE_HOME, WPADM_DIR_BACKUP));
             $errors[] = $log;
             WPAdm_Core::log($log);
         } else {
             $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
             $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
             WPAdm_Core::log($log . $mysql_dump_file);
         }
         unset($commandContext);
     }
     if (count($errors) == 0) {
         if (in_array('files', $this->params['types'])) {
             WPAdm_Core::log(langWPADM::get('Create a list of files for Backup', false));
             $files = $this->createListFilesForArchive();
         }
         if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
             $files[] = $mysql_dump_file;
         }
         if (empty($files)) {
             $errors[] = langWPADM::get('Website "%d" returned an error during creation of the list of files for a backup: list of files for a backup is empty. To solve this problem, please check files and folders permissions for website "%d".', false, array('%d'), array(SITE_HOME));
         }
         // split the file list by 170kbayt lists, To break one big task into smaller
         $files2 = array();
         $files2[0] = array();
         $i = 0;
         $size = 0;
         foreach ($files as $f) {
             if ($size > 170000) {
                 //~170kbyte
                 $i++;
                 $size = 0;
                 $files2[$i] = array();
             }
             $f_size = (int) @filesize($f);
             if ($f_size == 0 || $f_size > 1000000) {
                 WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
             }
             $size += $f_size;
             $files2[$i][] = $f;
         }
         WPAdm_Core::log(langWPADM::get('List of Backup-Files was successfully created', false));
         $this->queue->clear();
         foreach ($files2 as $files) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         WPAdm_Core::log(langWPADM::get('Backup of Files was started', false));
         $this->queue->save()->execute();
         WPAdm_Core::log(langWPADM::get('End of File Backup', false));
         $files = glob($this->dir . '/' . $this->name . '*');
         $urls = array();
         $totalSize = 0;
         foreach ($files as $file) {
             $urls[] = str_replace(ABSPATH, '', $file);
             $totalSize += @intval(filesize($file));
         }
         $this->result->setData($urls);
         $this->result->setSize($totalSize);
         $size = $totalSize / 1024 / 1024;
         /// MByte
         $size = round($size, 2);
         $log = str_replace("%s", $size, langWPADM::get('Backup Size %s Mb', false));
         WPAdm_Core::log($log);
         $remove_from_server = 0;
         #Removing TMP-files
         WPAdm_Core::rmdir($mysql_dump_file);
         #Removind old backups(if limit the number of stored backups)
         if ($this->params['limit'] != 0) {
             WPAdm_Core::log(langWPADM::get('Limits of Backups ', false) . $this->params['limit']);
             WPAdm_Core::log(langWPADM::get('Removing of old Backups was started', false));
             $files = glob(WPADM_DIR_BACKUP . '/*');
             if (count($files) > $this->params['limit']) {
                 $files2 = array();
                 foreach ($files as $f) {
                     $fa = explode('-', $f);
                     if (count($fa) != 3) {
                         continue;
                     }
                     $files2[$fa[2]] = $f;
                 }
                 ksort($files2);
                 $d = count($files2) - $this->params['limit'];
                 $del = array_slice($files2, 0, $d);
                 foreach ($del as $d) {
                     WPAdm_Core::rmdir($d);
                 }
             }
             WPAdm_Core::log(langWPADM::get('Removing of old Backups was Finished', false));
         }
     }
     wpadm_class::setBackup(1);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         WPAdm_Core::rmdir($this->dir);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
         WPAdm_Core::log(langWPADM::get('Backup creation was complete successfully!', false));
     }
     wpadm_class::backupSend();
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     @unlink(dirname(__FILE__) . '/../tmp/log.log');
     WPAdm_Core::log('Start backup create');
     WPAdm_Core::log('Create dump Data Base');
     $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log('optimization Database');
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
         $this->queue->clear()->add($commandContext);
         unset($commandContext);
     }
     $commandContext = new WPAdm_Command_Context();
     $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
     $res = $this->queue->add($commandContext)->save()->execute();
     if (!$res) {
         $log = langWPADM::get('Website "%d" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%d', '%s'), array(SITE_HOME, $this->queue->getError()));
         WPAdm_Core::log($log);
         $errors[] = $log;
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $log = langWPADM::get('Website "%d" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".', false, array('%d', '%dir'), array(SITE_HOME, WPADM_DIR_BACKUP));
         $errors[] = $log;
         WPAdm_Core::log($log);
     } else {
         $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
         $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
         WPAdm_Core::log($log . ' ' . str_replace(ABSPATH, '', $mysql_dump_file));
     }
     unset($commandContext);
     WPAdm_Core::log('Start Created List Files');
     if ($this->type == 'full') {
         $files = $this->createListFilesForArchive();
     } else {
         $files = array();
     }
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Empty list files';
     }
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('file ' . $f . ' size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log('Сreated List Files is successfully');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log('Start archived files');
     // сохраним и выполним
     $this->queue->save()->execute();
     WPAdm_Core::log('End archived files');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
     }
     $this->result->setData($urls);
     WPAdm_Core::rmdir(WPADM_DIR_BACKUP . '/mysqldump.sql');
     if ($this->params['limit'] != 0) {
         WPAdm_Core::log('Start deleted old backup');
         $files = glob(WPADM_DIR_BACKUP . '/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
         WPAdm_Core::log('Finish deleted old backups');
     }
     WPAdm_Core::log('Finish create');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     if (file_exists($context->get('zip_file'))) {
         require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
         $this->archive = new PclZip($context->get('zip_file'));
         $file = $context->get('file');
         $is_dump = $file && strpos($file, "mysqldump.sql");
         WPAdm_Core::log("Data decompression " . basename($context->get('zip_file')));
         if ($is_dump !== false) {
             $inzip = str_replace(ABSPATH, "", $file);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_BY_NAME, $inzip);
         } else {
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_REPLACE_NEWER);
         }
         if ($file_in_zip == 0) {
             WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             $context->setError(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             return false;
         }
         //WPAdm_Core::log(print_r($file_in_zip, 1));
         if ($is_dump !== false) {
             $db_host = $context->get('db_host');
             if ($db_host !== false) {
                 require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
                 $mysqldump = new WPAdm_Mysqldump();
                 $mysqldump->host = $context->get('db_host');
                 $mysqldump->user = $context->get('db_user');
                 $mysqldump->password = $context->get('db_password');
                 try {
                     $mysqldump->restore($context->get('db_name'), $file);
                 } catch (Exception $e) {
                     $context->setError($e->getMessage());
                     return false;
                 }
             }
         }
     } else {
         $context->setError(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         return false;
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/S3.php';
     $s3 = new S3($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     //new S3Wrapper();
     //S3::setAuth($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     /*(array(
       'key'    => $context->get('AccessKeyId'),
       'secret' => $context->get('SecretAccessKey'),
       'token'  => $context->get('SessionToken')
       ));   */
     // $s3->setTimeCorrectionOffset(60);
     $dir = $context->get('dir') ? $context->get('dir') : '';
     if ($dir) {
         //$s3->mkdir('s3://' . $context->get('bucket') . '/' . $dir);
         $logs = $s3->putObject($dir, $context->get('bucket'), $dir . "/", s3::ACL_PUBLIC_READ);
         //$logs = $s3->putObjectString($dir, $context->get('bucket'), $context->get('bucket') . '/' . $dir, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('create folder logs ' . serialize($logs));
         /*$s3->registerStreamWrapper("s3");
           @mkdir('s3://'.$context->get('bucket').'/'.$dir);*/
     }
     try {
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $s3->putObjectFile($filePath, $context->get('bucket'), $key, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('putObjectFile ' . $filePath . ' == ' . $context->get('bucket') . " == " . $key . ' == ' . (int) $putRes);
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }