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 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 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 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->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()
 {
     $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;
 }