2017-12-14 16:38:51 +00:00
|
|
|
#!/usr/bin/env php
|
2017-11-19 21:21:54 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file scripts/dbstructure.php
|
|
|
|
* @brief Does database updates from the command line
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Friendica\App;
|
2017-12-01 08:35:05 +00:00
|
|
|
use Friendica\Core\Config;
|
2017-12-14 21:13:02 +00:00
|
|
|
use Friendica\Database\DBStructure;
|
2017-11-19 21:21:54 +00:00
|
|
|
|
2017-12-14 21:32:53 +00:00
|
|
|
require_once "boot.php";
|
|
|
|
require_once "include/dba.php";
|
|
|
|
|
2017-11-19 21:21:54 +00:00
|
|
|
$a = new App(dirname(__DIR__));
|
2018-03-07 17:34:47 +00:00
|
|
|
BaseObject::setApp($a);
|
2017-11-19 21:21:54 +00:00
|
|
|
|
|
|
|
@include ".htconfig.php";
|
|
|
|
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
|
|
|
unset($db_host, $db_user, $db_pass, $db_data);
|
|
|
|
|
|
|
|
if ($_SERVER["argc"] == 2) {
|
|
|
|
switch ($_SERVER["argv"][1]) {
|
|
|
|
case "dryrun":
|
2017-12-14 22:18:53 +00:00
|
|
|
DBStructure::update(true, false);
|
2017-11-19 21:21:54 +00:00
|
|
|
return;
|
|
|
|
case "update":
|
2017-12-14 22:18:53 +00:00
|
|
|
DBStructure::update(true, true);
|
2017-11-19 21:21:54 +00:00
|
|
|
|
|
|
|
$build = Config::get('system','build');
|
|
|
|
if (!x($build)) {
|
|
|
|
Config::set('system', 'build', DB_UPDATE_VERSION);
|
|
|
|
$build = DB_UPDATE_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
$stored = intval($build);
|
|
|
|
$current = intval(DB_UPDATE_VERSION);
|
|
|
|
|
|
|
|
// run any left update_nnnn functions in update.php
|
|
|
|
for ($x = $stored; $x < $current; $x ++) {
|
|
|
|
$r = run_update_function($x);
|
|
|
|
if (!$r) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Config::set('system','build',DB_UPDATE_VERSION);
|
|
|
|
return;
|
|
|
|
case "dumpsql":
|
2017-12-14 22:22:44 +00:00
|
|
|
DBStructure::printStructure();
|
2017-11-19 21:21:54 +00:00
|
|
|
return;
|
|
|
|
case "toinnodb":
|
2017-12-14 21:13:02 +00:00
|
|
|
DBStructure::convertToInnoDB();
|
2017-11-19 21:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// print help
|
|
|
|
echo $_SERVER["argv"][0]." <command>\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "Commands:\n";
|
|
|
|
echo "dryrun show database update schema queries without running them\n";
|
|
|
|
echo "update update database schema\n";
|
|
|
|
echo "dumpsql dump database schema\n";
|
|
|
|
echo "toinnodb convert all tables from MyISAM to InnoDB\n";
|
|
|
|
killme();
|
|
|
|
|