예제 #1
0
/**
 * Run any php upgrade scripts which are required
 *
 * @param int  $version Version upgrading from.
 * @param bool $quiet   Suppress errors.  Don't use this.
 *
 * @return bool
 * @access private
 */
function upgrade_code($version, $quiet = FALSE)
{
    // do not remove - upgrade scripts depend on this
    global $CONFIG;
    $version = (int) $version;
    $upgrade_path = elgg_get_config('path') . 'engine/lib/upgrades/';
    $processed_upgrades = elgg_get_processed_upgrades();
    // upgrading from 1.7 to 1.8. Need to bootstrap.
    if (!$processed_upgrades) {
        elgg_upgrade_bootstrap_17_to_18();
        // grab accurate processed upgrades
        $processed_upgrades = elgg_get_processed_upgrades();
    }
    $upgrade_files = elgg_get_upgrade_files($upgrade_path);
    if ($upgrade_files === false) {
        return false;
    }
    $upgrades = elgg_get_unprocessed_upgrades($upgrade_files, $processed_upgrades);
    // Sort and execute
    sort($upgrades);
    foreach ($upgrades as $upgrade) {
        $upgrade_version = elgg_get_upgrade_file_version($upgrade);
        $success = true;
        // hide all errors.
        if ($quiet) {
            // hide include errors as well as any exceptions that might happen
            try {
                if (!@(include "{$upgrade_path}/{$upgrade}")) {
                    $success = false;
                    error_log("Could not include {$upgrade_path}/{$upgrade}");
                }
            } catch (Exception $e) {
                $success = false;
                error_log($e->getmessage());
            }
        } else {
            if (!(include "{$upgrade_path}/{$upgrade}")) {
                $success = false;
                error_log("Could not include {$upgrade_path}/{$upgrade}");
            }
        }
        if ($success) {
            // incrementally set upgrade so we know where to start if something fails.
            $processed_upgrades[] = $upgrade;
            // don't set the version to a lower number in instances where an upgrade
            // has been merged from a lower version of Elgg
            if ($upgrade_version > $version) {
                datalist_set('version', $upgrade_version);
            }
            elgg_set_processed_upgrades($processed_upgrades);
        } else {
            return false;
        }
    }
    return true;
}
예제 #2
0
function file_tools_upgrade_handler()
{
    $upgrades_path = dirname(dirname(__FILE__)) . "/upgrades/";
    // find all upgrade files
    $upgrade_files = elgg_get_upgrade_files($upgrades_path);
    // get processed upgrade file, so we can add our own files when done
    $processed_upgrades = elgg_get_processed_upgrades();
    // get unprocessed upgrade files
    if ($unprocessed_upgrades = elgg_get_unprocessed_upgrades($upgrade_files, $processed_upgrades)) {
        foreach ($unprocessed_upgrades as $upgrade_file) {
            // make sure we don't try to run someone elses upgrade files
            if (in_array($upgrade_file, $upgrade_files) && file_exists($upgrades_path . $upgrade_file)) {
                // run upgrade
                include $upgrades_path . $upgrade_file;
                // make sure we don't do it again
                $processed_upgrades[] = $upgrade_file;
            }
        }
        // store processed upgrade files
        elgg_set_processed_upgrades($processed_upgrades);
    }
}