예제 #1
0
    }
}
if ($dryRun) {
    print "---- DRY RUN ONLY ----\n";
}
$schemaVersion = db_tableExists('Variable') ? Variable::peek('Schema.version', '00000') : '00000';
print "Current schema version is <{$schemaVersion}>\n";
$patchFiles = getPatches(PATCH_DIR, $schemaVersion);
$numPatches = 0;
foreach ($patchFiles as $fileName) {
    runPatch(PATCH_DIR . $fileName, $dryRun);
    $numPatches++;
    $schemaVersion = stripExtension($fileName);
    if (!$dryRun) {
        // Update after each patch, in case one of the patches terminates with error.
        Variable::poke('Schema.version', $schemaVersion);
    }
}
print "{$numPatches} patches applied.\n";
print "New schema version is <{$schemaVersion}>\n";
/*****************************************************************/
function getPatches($dir, $after)
{
    $result = array();
    if ($dirHandle = opendir($dir)) {
        while (($fileName = readdir($dirHandle)) !== false) {
            if (preg_match(PATCH_REGEXP, $fileName) && stripExtension($fileName) > $after && !StringUtil::endsWith($fileName, '~')) {
                $result[] = $fileName;
            }
        }
        closedir($dirHandle);