diff --git a/setup/setup.php b/setup/setup.php index 477cf97b..eb72fc75 100644 --- a/setup/setup.php +++ b/setup/setup.php @@ -58,6 +58,8 @@ else CLISetup::init(); $cmd = array_pop(array_keys($opt)); +$s = []; +$b = []; switch ($cmd) // we accept only one main parameter { case 'firstrun': @@ -77,13 +79,26 @@ switch ($cmd) // we accept only on finish(); case 'update': require_once 'setup/tools/clisetup/update.func.php'; - if (update()) // return true if we do not rebuild stuff + list($s, $b) = update(); // return true if we do not rebuild stuff + if (!$s && !$b) return; case 'sync': require_once 'setup/tools/clisetup/sql.func.php'; require_once 'setup/tools/clisetup/build.func.php'; - sql(); - build(); + $_s = sql($s); + $_b = build($b); + + if ($s) + { + $_ = array_diff($s, $_s); + DB::Aowow()->query('UPDATE ?_dbversion SET `sql` = ?', $_ ? implode(' ', $_) : ''); + } + + if ($b) + { + $_ = array_diff($b, $_b); + DB::Aowow()->query('UPDATE ?_dbversion SET `build` = ?', $_ ? implode(' ', $_) : ''); + } finish(); } diff --git a/setup/tools/clisetup/build.func.php b/setup/tools/clisetup/build.func.php index 4db68163..2160d590 100644 --- a/setup/tools/clisetup/build.func.php +++ b/setup/tools/clisetup/build.func.php @@ -11,12 +11,13 @@ if (!CLI) /* Create required files */ /*************************/ -function build() +function build($syncMe = null) { require_once 'setup/tools/fileGen.class.php'; - FileGen::init(); + FileGen::init($syncMe !== null ? FileGen::MODE_UPDATE : FileGen::MODE_NORMAL, $syncMe); + $done = []; if (FileGen::$subScripts) { $allOk = true; @@ -46,9 +47,10 @@ function build() $syncIds = []; // todo: fetch what exactly must be regenerated $ok = FileGen::generate($name, $syncIds); - if (!$ok) $allOk = false; + else + $done[] = $name; CLISetup::log(' - subscript \''.$file.'\' returned '.($ok ? 'sucessfully' : 'with errors'), $ok ? CLISetup::LOG_OK : CLISetup::LOG_ERROR); set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script @@ -63,9 +65,10 @@ function build() $syncIds = []; // todo: fetch what exactly must be regenerated $ok = FileGen::generate($file, $syncIds); - if (!$ok) $allOk = false; + else + $done[] = $file; CLISetup::log(' - subscript \''.$file.'\' returned '.($ok ? 'sucessfully' : 'with errors'), $ok ? CLISetup::LOG_OK : CLISetup::LOG_ERROR); set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script @@ -80,6 +83,8 @@ function build() } else CLISetup::log('no valid script names supplied', CLISetup::LOG_ERROR); + + return $done; } ?> diff --git a/setup/tools/clisetup/sql.func.php b/setup/tools/clisetup/sql.func.php index ad30dfcf..7fc254d6 100644 --- a/setup/tools/clisetup/sql.func.php +++ b/setup/tools/clisetup/sql.func.php @@ -11,12 +11,13 @@ if (!CLI) /* Create content from world tables / dbc files */ /************************************************/ -function sql($syncMe = []) +function sql($syncMe = null) { require_once 'setup/tools/sqlGen.class.php'; - SqlGen::init(); + SqlGen::init($syncMe !== null ? SqlGen::MODE_UPDATE : SqlGen::MODE_NORMAL, $syncMe); + $done = []; if (SqlGen::$subScripts) { $allOk = true; @@ -30,9 +31,10 @@ function sql($syncMe = []) $syncIds = []; // todo: fetch what exactly must be regenerated $ok = SqlGen::generate($tbl, $syncIds); - if (!$ok) $allOk = false; + else + $done[] = $tbl; CLISetup::log(' - subscript \''.$tbl.'\' returned '.($ok ? 'sucessfully' : 'with errors'), $ok ? CLISetup::LOG_OK : CLISetup::LOG_ERROR); set_time_limit(SqlGen::$defaultExecTime); // reset to default for the next script @@ -47,6 +49,8 @@ function sql($syncMe = []) } else CLISetup::log('no valid script names supplied', CLISetup::LOG_ERROR); + + return $done; } ?> diff --git a/setup/tools/clisetup/update.func.php b/setup/tools/clisetup/update.func.php index 053639fa..f2db5cd6 100644 --- a/setup/tools/clisetup/update.func.php +++ b/setup/tools/clisetup/update.func.php @@ -13,7 +13,7 @@ if (!CLI) function update() { - list($date, $part) = array_values(DB::Aowow()->selectRow('SELECT `date`, `part` FROM ?_dbversion')); + list($date, $part, $sql, $build) = array_values(DB::Aowow()->selectRow('SELECT `date`, `part`, `sql`, `build` FROM ?_dbversion')); CLISetup::log('checking sql updates'); @@ -56,7 +56,10 @@ function update() CLISetup::log($nFiles ? 'applied '.$nFiles.' update(s)' : 'db is already up to date', CLISetup::LOG_OK); - return true; + $sql = trim($sql) ? explode(' ', trim($sql)) : []; + $build = trim($build) ? explode(' ', trim($build)) : []; + + return [$sql, $build]; } ?> diff --git a/setup/tools/fileGen.class.php b/setup/tools/fileGen.class.php index 103870a4..01a80814 100644 --- a/setup/tools/fileGen.class.php +++ b/setup/tools/fileGen.class.php @@ -10,6 +10,10 @@ if (!CLI) class FileGen { + const MODE_NORMAL = 0; + const MODE_FIRSTRUN = 1; + const MODE_UPDATE = 2; + public static $tplPath = 'setup/tools/filegen/templates/'; public static $cliOpts = []; @@ -65,14 +69,14 @@ class FileGen 'STATIC_URL' => STATIC_URL ); - public static function init($firstrun = false) + public static function init($mode = self::MODE_NORMAL, array $updScripts = []) { self::$defaultExecTime = ini_get('max_execution_time'); - $doScripts = []; + $doScripts = null; - if (getopt(self::$shortOpts, self::$longOpts) || $firstrun) + if (getopt(self::$shortOpts, self::$longOpts) || $mode == self::MODE_FIRSTRUN) self::handleCLIOpts($doScripts); - else + else if ($mode != self::MODE_UPDATE) { self::printCLIHelp(); exit; @@ -80,8 +84,8 @@ class FileGen // check passed subscript names; limit to real scriptNames self::$subScripts = array_merge(array_keys(self::$tplFiles), array_keys(self::$datasets)); - if ($doScripts) - self::$subScripts = array_intersect($doScripts, self::$subScripts); + if ($doScripts || $updScripts) + self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts); else if ($doScripts === null) self::$subScripts = []; diff --git a/setup/tools/sqlGen.class.php b/setup/tools/sqlGen.class.php index 13131121..49e2a5d7 100644 --- a/setup/tools/sqlGen.class.php +++ b/setup/tools/sqlGen.class.php @@ -21,6 +21,10 @@ if (!CLI) class SqlGen { + const MODE_NORMAL = 0; + const MODE_FIRSTRUN = 1; + const MODE_UPDATE = 2; + private static $tables = array( // [dbcName, saveDbc, AowowDeps, TCDeps] 'achievementcategory' => ['achievement_category', false, null, null], 'achievementcriteria' => ['achievement_criteria', false, null, null], @@ -77,14 +81,14 @@ class SqlGen public static $defaultExecTime = 30; public static $stepSize = 1000; - public static function init($firstrun = false) + public static function init($mode = self::MODE_NORMAL, array $updScripts = []) { self::$defaultExecTime = ini_get('max_execution_time'); - $doScripts = []; + $doScripts = null; - if (getopt(self::$shortOpts, self::$longOpts) || $firstrun) + if (getopt(self::$shortOpts, self::$longOpts) || $mode == self::MODE_FIRSTRUN) self::handleCLIOpts($doScripts); - else + else if ($mode != self::MODE_UPDATE) { self::printCLIHelp(); exit; @@ -92,8 +96,8 @@ class SqlGen // check passed subscript names; limit to real scriptNames self::$subScripts = array_keys(self::$tables); - if ($doScripts) - self::$subScripts = array_intersect($doScripts, self::$subScripts); + if ($doScripts || $updScripts) + self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts); else if ($doScripts === null) self::$subScripts = [];