Пример #1
0
 public static function cloneBackupExtract()
 {
     try {
         MainWP_Helper::endSession();
         $file = isset($_POST['f']) ? $_POST['f'] : $_POST['file'];
         $testFull = false;
         if ('' === $file) {
             $dirs = MainWP_Helper::getMainWPDir('backup', false);
             $backupdir = $dirs[0];
             $files = glob($backupdir . 'download-*');
             $archiveFile = false;
             foreach ($files as $file) {
                 if (MainWP_Helper::isArchive($file, 'download-')) {
                     $archiveFile = $file;
                     break;
                 }
             }
             if (false === $archiveFile) {
                 throw new Exception(__('No download file found', 'mainwp-child'));
             }
             $file = $archiveFile;
         } else {
             if (file_exists($file)) {
                 $testFull = true;
             } else {
                 $file = ABSPATH . $file;
                 if (!file_exists($file)) {
                     throw new Exception(__('Backup file not found', 'mainwp-child'));
                 }
                 $testFull = true;
             }
         }
         //return size in kb
         $cloneInstall = new MainWP_Clone_Install($file);
         //todo: RS: refactor to get those plugins after install (after .18 release)
         $cloneInstall->readConfigurationFile();
         $plugins = get_option('mainwp_temp_clone_plugins');
         $themes = get_option('mainwp_temp_clone_themes');
         if ($testFull) {
             $cloneInstall->testDownload();
         }
         $cloneInstall->removeConfigFile();
         $cloneInstall->extractBackup();
         $pubkey = get_option('mainwp_child_pubkey');
         $uniqueId = get_option('mainwp_child_uniqueId');
         $server = get_option('mainwp_child_server');
         $nonce = get_option('mainwp_child_nonce');
         $nossl = get_option('mainwp_child_nossl');
         $nossl_key = get_option('mainwp_child_nossl_key');
         $sitesToClone = get_option('mainwp_child_clone_sites');
         $cloneInstall->install();
         $cloneInstall->updateWPConfig();
         //            $cloneInstall->update_option('mainwp_child_pubkey', $pubkey);
         //            $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId);
         //            $cloneInstall->update_option('mainwp_child_server', $server);
         //            $cloneInstall->update_option('mainwp_child_nonce', $nonce);
         //            $cloneInstall->update_option('mainwp_child_nossl', $nossl);
         //            $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
         //            $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
         //            $cloneInstall->update_option('mainwp_child_clone_permalink', true);
         MainWP_Helper::update_option('mainwp_child_pubkey', $pubkey, 'yes');
         MainWP_Helper::update_option('mainwp_child_uniqueId', $uniqueId);
         MainWP_Helper::update_option('mainwp_child_server', $server);
         MainWP_Helper::update_option('mainwp_child_nonce', $nonce);
         MainWP_Helper::update_option('mainwp_child_nossl', $nossl, 'yes');
         MainWP_Helper::update_option('mainwp_child_nossl_key', $nossl_key);
         MainWP_Helper::update_option('mainwp_child_clone_sites', $sitesToClone);
         if (!MainWP_Helper::startsWith(basename($file), 'download-backup-')) {
             MainWP_Helper::update_option('mainwp_child_restore_permalink', true, 'yes');
         } else {
             MainWP_Helper::update_option('mainwp_child_clone_permalink', true, 'yes');
         }
         $cloneInstall->clean();
         if (false !== $plugins) {
             $out = array();
             if (is_array($plugins)) {
                 $dir = WP_CONTENT_DIR . '/plugins/';
                 $fh = @opendir($dir);
                 while ($entry = @readdir($fh)) {
                     if (!is_dir($dir . $entry)) {
                         continue;
                     }
                     if ('.' === $entry || '..' === $entry) {
                         continue;
                     }
                     if (!in_array($entry, $plugins)) {
                         MainWP_Helper::delete_dir($dir . $entry);
                     }
                 }
                 @closedir($fh);
             }
             delete_option('mainwp_temp_clone_plugins');
         }
         if (false !== $themes) {
             $out = array();
             if (is_array($themes)) {
                 $dir = WP_CONTENT_DIR . '/themes/';
                 $fh = @opendir($dir);
                 while ($entry = @readdir($fh)) {
                     if (!is_dir($dir . $entry)) {
                         continue;
                     }
                     if ('.' === $entry || '..' === $entry) {
                         continue;
                     }
                     if (!in_array($entry, $themes)) {
                         MainWP_Helper::delete_dir($dir . $entry);
                     }
                 }
                 @closedir($fh);
             }
             delete_option('mainwp_temp_clone_themes');
         }
         $output = array('result' => 'ok');
         //todo: remove old tables if other prefix?
         wp_logout();
         wp_set_current_user(0);
     } catch (Exception $e) {
         $output = array('error' => $e->getMessage());
     }
     //return size in kb
     die(json_encode($output));
 }
Пример #2
0
 function backupPoll()
 {
     $fileNameUID = isset($_POST['fileNameUID']) ? $_POST['fileNameUID'] : '';
     $fileName = isset($_POST['fileName']) ? $_POST['fileName'] : '';
     if ('full' === $_POST['type']) {
         if ('' !== $fileName) {
             $backupFile = $fileName;
         } else {
             $backupFile = 'backup-' . $fileNameUID . '-';
         }
         $dirs = MainWP_Helper::getMainWPDir('backup');
         $backupdir = $dirs[0];
         $result = glob($backupdir . $backupFile . '*');
         $archiveFile = false;
         foreach ($result as $file) {
             if (MainWP_Helper::isArchive($file, $backupFile, '(.*)')) {
                 $archiveFile = $file;
                 break;
             }
         }
         if (false === $archiveFile) {
             MainWP_Helper::write(array());
         }
         MainWP_Helper::write(array('size' => filesize($archiveFile)));
     } else {
         $backupFile = 'dbBackup-' . $fileNameUID . '-*.sql';
         $dirs = MainWP_Helper::getMainWPDir('backup');
         $backupdir = $dirs[0];
         $result = glob($backupdir . $backupFile . '*');
         if (0 === count($result)) {
             MainWP_Helper::write(array());
         }
         $size = 0;
         foreach ($result as $f) {
             $size += filesize($f);
         }
         MainWP_Helper::write(array('size' => $size));
         exit;
     }
 }
 public function clean()
 {
     $files = glob(WP_CONTENT_DIR . '/dbBackup*.sql');
     foreach ($files as $file) {
         @unlink($file);
     }
     if (file_exists(ABSPATH . 'clone/config.txt')) {
         @unlink(ABSPATH . 'clone/config.txt');
     }
     if (MainWP_Helper::is_dir_empty(ABSPATH . 'clone')) {
         @rmdir(ABSPATH . 'clone');
     }
     try {
         $dirs = MainWP_Helper::getMainWPDir('backup', false);
         $backupdir = $dirs[0];
         $files = glob($backupdir . '*');
         foreach ($files as $file) {
             if (MainWP_Helper::isArchive($file)) {
                 @unlink($file);
             }
         }
     } catch (Exception $e) {
     }
 }