Пример #1
0
function process_theme_update()
{
    try {
        $log = 'Theme update: ' . Date('Y-m-d H:i:s') . "\r\n";
        set_time_limit(0);
        // Backup files
        $log .= 'Backuping files...' . "\r\n";
        if (!file_exists(dirname(__FILE__) . '/backup/')) {
            mkdir(dirname(__FILE__) . '/backup/', 0777);
        }
        $backupFolder = dirname(__FILE__) . '/';
        $time = time();
        $finalZip = dirname(__FILE__) . '/backup/backup_' . $time . '.zip';
        $exclude = array('carrental/backup', 'carrental/zip', 'carrental/download');
        $eza = new ExtZipArchive();
        $res = $eza->open($finalZip, ZipArchive::CREATE);
        if ($res === TRUE) {
            $eza->addDir($backupFolder, basename($backupFolder), $exclude);
            $eza->close();
        } else {
            throw new Exception('Could not create backup.');
        }
        $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
        // Download new files and unzip
        $log .= 'Downloading...' . "\r\n";
        $check = unserialize(get_option('carrental_theme_update_check'));
        if (isset($check['new_version_url']) && !empty($check['new_version_url'])) {
            $zip = file_get_contents($check['new_version_url']);
            $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
            if ($zip && !empty($zip)) {
                if (!file_exists(dirname(__FILE__) . '/download/')) {
                    mkdir(dirname(__FILE__) . '/download/', 0777);
                }
                if (!file_exists(dirname(__FILE__) . '/zip/')) {
                    mkdir(dirname(__FILE__) . '/zip/', 0777);
                }
                $tempFileName = dirname(__FILE__) . '/download/theme_update.zip';
                if (file_exists($tempFileName)) {
                    unlink($tempFileName);
                }
                file_put_contents($tempFileName, $zip);
                $log .= 'Unziping...' . "\r\n";
                $zip = new ZipArchive();
                $res = $zip->open($tempFileName);
                if ($res === TRUE) {
                    $zip->extractTo(dirname(__FILE__) . '/zip/');
                    $zip->close();
                } else {
                    $zip->close();
                    throw new Exception('ZIP error.');
                }
                $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
            } else {
                throw new Exception('Invalid file.');
            }
        } else {
            throw new Exception('Invalid download URL.');
        }
        update_option('carrental_theme_update_check', '');
        @file_put_contents(dirname(__FILE__) . '/backup/log_' . $time . '.txt', $log);
        // Redirect to rewrite files
        $_SESSION['carrental_flash_msg'] = array('status' => 'success', 'msg' => __('Theme was successfully updated.', 'carrental'));
        Header('Location: ' . CARRENTAL__THEME_URL . '/carrental-theme-updater.php?key=CR157TUXX&time=' . $time);
        exit;
        return true;
    } catch (Exception $e) {
        exit($e->getMessage());
        return false;
    }
}
Пример #2
0
 public function process_plugin_update()
 {
     try {
         $log = 'Plugin update: ' . Date('Y-m-d H:i:s') . "\r\n";
         set_time_limit(0);
         // Backup files
         $log .= 'Backuping files...' . "\r\n";
         if (!file_exists(dirname(__FILE__) . '/backup/')) {
             mkdir(dirname(__FILE__) . '/backup/', 0777);
         }
         if (!file_exists(dirname(__FILE__) . '/assets/swf/')) {
             mkdir(dirname(__FILE__) . '/assets/swf/', 0777);
         }
         $backupFolder = dirname(__FILE__) . '/';
         $time = time();
         $finalZip = dirname(__FILE__) . '/backup/backup_' . $time . '.zip';
         $exclude = array('carrental-client-area/backup', 'carrental-client-area/zip', 'carrental-client-area/download');
         $eza = new ExtZipArchive();
         $res = $eza->open($finalZip, ZipArchive::CREATE);
         if ($res === TRUE) {
             $eza->addDir($backupFolder, basename($backupFolder), $exclude);
             $eza->close();
         } else {
             throw new Exception('Could not create backup.');
         }
         $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
         // Backup DB
         $log .= 'Backuping database...' . "\r\n";
         $_POST['export_structure'] = $_POST['export_data'] = 1;
         file_put_contents(dirname(__FILE__) . '/backup/sql_' . $time . '.sql', parent::export_database());
         $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
         // Download new files and unzip
         $log .= 'Downloading...' . "\r\n";
         $check = unserialize(get_option('carrental_client_area_update_check'));
         if (isset($check['new_version_url']) && !empty($check['new_version_url'])) {
             $zip = file_get_contents($check['new_version_url']);
             $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
             if ($zip && !empty($zip)) {
                 if (!file_exists(dirname(__FILE__) . '/download/')) {
                     mkdir(dirname(__FILE__) . '/download/', 0777);
                 }
                 if (!file_exists(dirname(__FILE__) . '/zip/')) {
                     mkdir(dirname(__FILE__) . '/zip/', 0777);
                 }
                 $tempFileName = dirname(__FILE__) . '/download/plugin_update.zip';
                 if (file_exists($tempFileName)) {
                     unlink($tempFileName);
                 }
                 file_put_contents($tempFileName, $zip);
                 $log .= 'Unziping...' . "\r\n";
                 $zip = new ZipArchive();
                 $res = $zip->open($tempFileName);
                 if ($res === TRUE) {
                     $zip->extractTo(dirname(__FILE__) . '/zip/');
                     $zip->close();
                 } else {
                     $zip->close();
                     throw new Exception('ZIP error.');
                 }
                 $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
             } else {
                 throw new Exception('Invalid file.');
             }
         } else {
             throw new Exception('Invalid download URL.');
         }
         // Update DB
         $log .= 'Updating database...' . "\r\n";
         update_option('carrental_client_area_do_database_update', 1);
         $log .= 'Done: ' . Date('Y-m-d H:i:s') . "\r\n";
         update_option('carrental_client_area_update_check', '');
         @file_put_contents(dirname(__FILE__) . '/backup/log_' . $time . '.txt', $log);
         self::get_plugin_translations();
         // Redirect to rewrite files
         self::set_flash_msg('success', __('Plugin was successfully updated.', 'carrental'));
         Header('Location: ' . CARRENTAL_CLIENT_AREA__PLUGIN_URL . 'carrental-client-area-plugin-updater.php?key=e7c4c0ce5&time=' . $time);
         exit;
         return true;
     } catch (Exception $e) {
         exit($e->getMessage());
         return false;
     }
 }