Example #1
0
    // Connect to the database
    $res = Database::Connect($config->db->host, $config->db->dbname, $config->db->username, $config->db->password);
    if (true !== $res) {
        throw new Exception('Error connecting to the database:<br/><div class="nested-error">' . $res . '</div>');
    }
    // If version = 0, run the initial schema
    if ($current_version == 0) {
        $res = Database::RunFolder($root . '/protected/install/database/schema/');
        if (true !== $res) {
            throw new Exception('Error loading database schema:<br/><div class="nested-error">' . $res . '</div>');
        }
    }
    // Run the update scripts
    while ($current_version < DATABASE_VERSION) {
        $next_version = $current_version + 1;
        $folder = sprintf($root . '/protected/install/database/update/%03d/', $next_version);
        $res = Database::RunFolder($folder);
        if (true !== $res) {
            throw new Exception('Error running database upgrade script:<br/><div class="nested-error">' . $res . '</div><p>While processing folder ' . $folder . '</p>');
        }
        // Save the new version and move to the next one
        @file_put_contents($root . '/protected/install/database/version', $next_version);
        Check::good("Applied upgrade script to version {$next_version}.");
        $current_version++;
    }
    // Done !
    Check::good("Successfully upgraded the database !");
} catch (Exception $e) {
    Check::bad($e->getMessage());
}
return "Database upgrade";
Example #2
0
         $form_errors[$field] = 'Field is required.';
     }
 }
 // Installation
 try {
     if (0 == count($form_errors)) {
         $res = Database::Connect($_POST['mysql_host'], $_POST['mysql_database'], $_POST['mysql_user'], $_POST['mysql_password']);
         if (true !== $res) {
             $form_errors['mysql_host'] = 'Please check this field.';
             $form_errors['mysql_database'] = 'Please check this field.';
             $form_errors['mysql_user'] = '******';
             $form_errors['mysql_password'] = '******';
             throw new Exception($res);
         }
         Check::good('[' . date('H:i:s') . '] Connected to database.');
         $res = Database::RunFolder($root . '/protected/install/database/schema/');
         if (true !== $res) {
             throw new Exception('Error loading database schema:<br/><div class="nested-error">' . $res . '</div>');
         }
         // Save the new version
         @file_put_contents($root . '/protected/install/database/version', DATABASE_VERSION);
         Check::good('[' . date('H:i:s') . '] Loaded database schema.');
         $subs = array('username' => $_POST['config_username'], 'userpass' => md5($_POST['config_password']));
         $res = Database::RunFile($root . '/protected/install/database/data/add_user.sql', $subs);
         if (true !== $res) {
             throw new Exception('Error loading database data:<br/><div class="nested-error">' . $res . '</div>');
         }
         Check::good('[' . date('H:i:s') . '] Loaded database data.');
         $substitutions = array('mysql_host' => $_POST['mysql_host'], 'mysql_database' => $_POST['mysql_database'], 'mysql_password' => $_POST['mysql_password'], 'mysql_username' => $_POST['mysql_user'], 'security_cookie' => sha1(time() . $_SERVER['SERVER_NAME']), 'host' => $_SERVER['SERVER_NAME'], 'path' => $_SERVER['REQUEST_URI'], 'user' => $_POST['config_username'], 'flickr_comment' => empty($_POST['config_flickr_api_key']) ? ';' : '', 'flickr_key' => $_POST['config_flickr_api_key'], 'google_map_comment' => empty($_POST['config_google_maps_api_key']) ? ';' : '', 'google_map_key' => $_POST['config_google_maps_api_key']);
         if (Config::SaveFile($root . '/protected/install/config.ini.template', $root . '/protected/config/config.ini', $substitutions)) {
             Check::good('[' . date('H:i:s') . '] Saved config file.');