Exemple #1
0
function run_db_upgrade($db_version_now)
{
    // Dirty, but need it here
    global $setting;
    // Drop caches from our settings for live data
    $setting->flushCache();
    // Find upgrades
    $files = glob(dirname(__FILE__) . "/definitions/{$db_version_now}_to_*");
    if (count($files) == 0) {
        die('No upgrade definitions found for ' . $db_version_now . PHP_EOL);
    }
    foreach ($files as $file) {
        $db_version_to = preg_replace("/(.*)\\/definitions\\/{$db_version_now}_to_/", '', $file);
        $db_version_to = preg_replace("/.inc.php/", '', $db_version_to);
        $run_string = preg_replace("/\\./", '', $db_version_to);
        if (!(require_once $file)) {
            die('Failed to load upgrade definition: ' . $file);
        }
        echo "+ Running upgrade from {$db_version_now} to {$db_version_to}" . PHP_EOL;
        $run = "run_{$run_string}";
        if (function_exists($run)) {
            $run();
            run_db_upgrade($db_version_to);
        } else {
            echo 'Could find upgrade function ' . $run . '!' . PHP_EOL;
            exit(1);
        }
    }
}
Exemple #2
0
 public function make_upgrade()
 {
     //cp_check_perm('cp_autoupdate');
     if (!function_exists('ftp_connect')) {
         showMessage(lang("FTP_connect function is not available", "admin"), false, 'r');
         exit;
     }
     $this->load->library('ftp');
     $this->load->helper('string');
     $this->load->helper('file');
     $status = $this->_check_status();
     if ($status['is_update'] == TRUE and $status['upgrade_file'] != '') {
         $upgrade_file = $status['upgrade_file'];
     } else {
         showMessage(lang("You are using the latest version", "admin"), lang("Congratulations!", "admin"), 'g');
         exit;
     }
     $path_to_index_php = $_POST['root_folder'];
     $config['hostname'] = $_POST['host'];
     $config['username'] = $_POST['login'];
     $config['password'] = $_POST['password'];
     $config['port'] = $_POST['port'];
     $config['passive'] = FALSE;
     $config['debug'] = FALSE;
     if ($this->ftp->connect($config) == FALSE) {
         showMessage(lang("Server connection error:Check username and password"), false, 'r');
         exit;
     }
     $root = '/' . trim_slashes($path_to_index_php) . '/';
     if ($root == '//') {
         $root = '/';
     }
     // Try to find self.
     $list = $this->ftp->list_files($root . 'application/modules/core/');
     $error = TRUE;
     foreach ($list as $k => $v) {
         if ($v == 'core' . EXT) {
             $error = FALSE;
         }
     }
     if ($error == TRUE) {
         $this->ftp->close();
         showMessage(lang("Error: Wrong path to the root directory."), false, 'r');
         exit;
     } else {
         // download zip archive
         $file = $this->upgrade_server . $upgrade_file;
         if (($fh = fopen($file, 'r')) == FALSE) {
             $this->ftp->close();
             showMessage(lang("Error downloading update file", "admin"), false, 'r');
             exit;
         } else {
             $contents = stream_get_contents($fh);
             $tmp_folder = BASEPATH . 'cache/' . time() . '/';
             // Save file
             $tmp_file = BASEPATH . 'cache/cms_upgrade.zip';
             if (file_exists($tmp_file)) {
                 @unlink($tmp_file);
             }
             write_file($tmp_file, $contents);
             if (!file_exists($tmp_folder)) {
                 mkdir($tmp_folder);
             }
             $this->load->library('pclzip', $tmp_file);
             if (($zip_result = $this->pclzip->extract(PCLZIP_OPT_PATH, $tmp_folder)) == 0) {
                 $this->ftp->close();
                 delete_files($tmp_folder, TRUE);
                 @rmdir($tmp_folder);
                 @unlink($tmp_file);
                 showMessage(lang("Exploding error", "admin"), false, 'r');
                 exit;
             }
             // Update DB
             if (file_exists($tmp_folder . 'migrations.php')) {
                 include $tmp_folder . 'migrations.php';
                 if (function_exists('run_db_upgrade')) {
                     run_db_upgrade();
                 }
                 @unlink($tmp_folder . 'migrations.php');
             }
             $this->ftp->mirror($tmp_folder, $root);
             delete_files($tmp_folder, TRUE);
             @rmdir($tmp_folder);
             @unlink($tmp_file);
             $this->ftp->close();
             // Clear system cache
             $this->load->library('cache');
             $this->cache->delete_all();
             // Rebuild sys hooks
             $this->load->library('cms_hooks');
             $this->cms_hooks->build_hooks();
             showMessage(lang("Updating has been completed", "admin"), false, 'g');
             updateDiv('page', site_url('admin/dashboard/index'));
         }
     }
 }