Exemple #1
0
function execute_update(array $types)
{
    if (!array_key_exists($_REQUEST['db_type'], $types)) {
        throw new Exception("Unknown database type, '" . $_REQUEST['db_type'] . "'.");
    }
    switch ($_REQUEST['db_type']) {
        case MYSQL:
            $utilClass = "MySqlUtils";
            break;
        case POSTGRESQL:
            $utilClass = "PostgreSQLUtils";
            break;
        default:
            throw new Exception($types[$_REQUEST['db_type']] . " databases are not currently supported for updates.");
    }
    // Now execute the update.
    $configuration = new ConfigurationProperties();
    $context = new OSIDContext();
    Services::startManagerAsService("DatabaseManager", $context, $configuration);
    $dbc = Services::getService('DBHandler');
    $dbIndex = $dbc->createDatabase($_REQUEST['db_type'], $_REQUEST['db_host'], $_REQUEST['db_name'], $_REQUEST['db_user'], $_REQUEST['db_pass']);
    $dbc->connect($dbIndex);
    // Harmoni_Db
    if ($_REQUEST['use_harmoni_db']) {
        switch ($_REQUEST['db_type']) {
            case MYSQL:
                $dbType = 'Pdo_Mysql';
                break;
            case POSTGRESQL:
                $dbType = 'Pdo_Postgresql';
                break;
            default:
                throw new Exception($types[$_REQUEST['db_type']] . " databases are not currently supported for updates.");
        }
        $db = Harmoni_Db::factory($dbType, array('host' => $_REQUEST['db_host'], 'username' => $_REQUEST['db_user'], 'password' => $_REQUEST['db_pass'], 'dbname' => $_REQUEST['db_name'], 'adapterNamespace' => 'Harmoni_Db_Adapter'));
        Harmoni_Db::registerDatabase('migration_db', $db);
    }
    try {
        $updater = new AuthZ2Updater();
        if ($updater->isInPlace($dbIndex)) {
            print "Update is already in place.";
        } else {
            $updater->runUpdate($dbIndex);
        }
    } catch (Exception $e) {
        // Close our connection
        $dbc->disconnect($dbIndex);
        throw $e;
    }
    $dbc->disconnect($dbIndex);
}