szurubooru/upgrade.php
Marcin Kurczewski 0ef5f1b46d Absolute paths used where necessary
- No random chdir() calls
- No more exceptions when executing scripts from dirs other than root
- find-posts.php prints absolute paths making piping more useful
2013-11-23 20:52:41 +01:00

33 lines
987 B
PHP

<?php
require_once 'src/core.php';
$config = \Chibi\Registry::getConfig();
$dbVersion = Model_Property::get(Model_Property::DbVersion);
printf('DB version = %d' . PHP_EOL, $dbVersion);
$upgradesPath = TextHelper::absolutePath(\Chibi\Registry::getContext()->rootDir . DS . 'src' . DS . 'Upgrades');
$upgrades = glob($upgradesPath . DS . '*.sql');
natcasesort($upgrades);
foreach ($upgrades as $upgradePath)
{
preg_match('/(\d+)\.sql/', $upgradePath, $matches);
$upgradeVersion = intval($matches[1]);
if ($upgradeVersion > $dbVersion)
{
printf('Executing %s...' . PHP_EOL, $upgradePath);
$upgradeSql = file_get_contents($upgradePath);
$upgradeSql = preg_replace('/^[ \t]+(.*);/m', '\0--', $upgradeSql);
$queries = preg_split('/;\s*[\r\n]+/s', $upgradeSql);
$queries = array_map('trim', $queries);
foreach ($queries as $query)
{
echo $query . PHP_EOL;
R::exec($query);
echo PHP_EOL;
}
}
Model_Property::set(Model_Property::DbVersion, $upgradeVersion);
}