mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
CLISetup:
- added --update command to automaticly apply sql-updates (e.g. via post-merge hook)
This commit is contained in:
@@ -40,7 +40,7 @@ function finish()
|
|||||||
die("\n");
|
die("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$scriptOpt = getopt('', ['account', 'dbconfig', 'siteconfig', 'sql', 'build', 'sync']);
|
$scriptOpt = getopt('', ['account', 'dbconfig', 'siteconfig', 'sql', 'build', 'sync', 'update']);
|
||||||
if (!$scriptOpt)
|
if (!$scriptOpt)
|
||||||
{
|
{
|
||||||
echo "\nAowow Setup\n";
|
echo "\nAowow Setup\n";
|
||||||
@@ -50,6 +50,7 @@ if (!$scriptOpt)
|
|||||||
echo "--sql : generate db content from your world tables\n";
|
echo "--sql : generate db content from your world tables\n";
|
||||||
echo "--build : create server specific files\n";
|
echo "--build : create server specific files\n";
|
||||||
echo "--sync=<tabelList,> : regenerate tables/files that depend on given world-table\n";
|
echo "--sync=<tabelList,> : regenerate tables/files that depend on given world-table\n";
|
||||||
|
echo "--update : apply new sql updates fetched from github\n";
|
||||||
// echo "--firstrun : goes through the nessecary hoops of the initial setup. Can be interrupted and --resume'd";
|
// echo "--firstrun : goes through the nessecary hoops of the initial setup. Can be interrupted and --resume'd";
|
||||||
echo "additional options\n";
|
echo "additional options\n";
|
||||||
echo "--log logfile : write ouput to file\n";
|
echo "--log logfile : write ouput to file\n";
|
||||||
@@ -65,6 +66,11 @@ else
|
|||||||
$cmd = array_pop(array_keys($scriptOpt));
|
$cmd = array_pop(array_keys($scriptOpt));
|
||||||
switch ($cmd) // we accept only one main parameter
|
switch ($cmd) // we accept only one main parameter
|
||||||
{
|
{
|
||||||
|
case 'update':
|
||||||
|
require_once 'setup/tools/clisetup/update.func.php';
|
||||||
|
update();
|
||||||
|
|
||||||
|
return;
|
||||||
case 'account':
|
case 'account':
|
||||||
case 'dbconfig':
|
case 'dbconfig':
|
||||||
case 'siteconfig':
|
case 'siteconfig':
|
||||||
|
|||||||
73
setup/tools/clisetup/update.func.php
Normal file
73
setup/tools/clisetup/update.func.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('AOWOW_REVISION'))
|
||||||
|
die('invalid access');
|
||||||
|
|
||||||
|
if (!CLI)
|
||||||
|
die('not in cli mode');
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************/
|
||||||
|
/* automaticly apply sql-updates */
|
||||||
|
/*********************************/
|
||||||
|
|
||||||
|
function update()
|
||||||
|
{
|
||||||
|
$createQuery = "
|
||||||
|
CREATE TABLE `aowow_dbversion` (
|
||||||
|
`date` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`part` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'
|
||||||
|
) ENGINE=MyISAM";
|
||||||
|
|
||||||
|
$date = $part = 0;
|
||||||
|
if (!DB::Aowow()->selectCell('SHOW TABLES LIKE "%dbversion"'))
|
||||||
|
{
|
||||||
|
DB::Aowow()->query($createQuery);
|
||||||
|
DB::Aowow()->query('INSERT INTO ?_dbversion VALUES (0, 0)');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
list($date, $part) = array_values(DB::Aowow()->selectRow('SELECT `date`, `part` FROM ?_dbversion'));
|
||||||
|
|
||||||
|
CLISetup::log('checking sql updates');
|
||||||
|
|
||||||
|
$nFiles = 0;
|
||||||
|
foreach (glob('setup/updates/*.sql') as $file)
|
||||||
|
{
|
||||||
|
$pi = pathinfo($file);
|
||||||
|
list($fDate, $fPart) = explode('_', $pi['filename']);
|
||||||
|
|
||||||
|
if ($date && $fDate < $date)
|
||||||
|
continue;
|
||||||
|
else if ($part && $date && $fDate == $date && $fPart <= $part)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$nFiles++;
|
||||||
|
|
||||||
|
$updQuery = '';
|
||||||
|
$nQuerys = 0;
|
||||||
|
foreach (file($file) as $line)
|
||||||
|
{
|
||||||
|
// skip comments
|
||||||
|
if (substr($line, 0, 2) == '--' || $line == '')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$updQuery .= $line;
|
||||||
|
|
||||||
|
// semicolon at the end -> end of query
|
||||||
|
if (substr(trim($line), -1, 1) == ';')
|
||||||
|
{
|
||||||
|
if (DB::Aowow()->query($updQuery))
|
||||||
|
$nQuerys++;
|
||||||
|
|
||||||
|
$updQuery = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::Aowow()->query('UPDATE ?_dbversion SET `date`= ?d, `part` = ?d', $fDate, $fPart);
|
||||||
|
CLISetup::log(' -> '.date('d.m.Y', $fDate).' #'.$fPart.': '.$nQuerys.' queries applied', CLISetup::LOG_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
CLISetup::log($nFiles ? 'applied '.$nFiles.' update(s)' : 'db is already up to date', CLISetup::LOG_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user