]> git.mxchange.org Git - friendica.git/blob - scripts/dbstructure.php
Move scripts/auth_ejabberd.php to bin/
[friendica.git] / scripts / dbstructure.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * @file scripts/dbstructure.php
5  * @brief Does database updates from the command line
6  */
7
8 use Friendica\App;
9 use Friendica\Core\Config;
10 use Friendica\Database\DBStructure;
11
12 require_once "boot.php";
13 require_once "include/dba.php";
14
15 $a = new App(dirname(__DIR__));
16 BaseObject::setApp($a);
17
18 @include ".htconfig.php";
19 dba::connect($db_host, $db_user, $db_pass, $db_data);
20 unset($db_host, $db_user, $db_pass, $db_data);
21
22 if ($_SERVER["argc"] == 2) {
23         switch ($_SERVER["argv"][1]) {
24                 case "dryrun":
25                         DBStructure::update(true, false);
26                         return;
27                 case "update":
28                         DBStructure::update(true, true);
29
30                         $build = Config::get('system','build');
31                         if (!x($build)) {
32                                 Config::set('system', 'build', DB_UPDATE_VERSION);
33                                 $build = DB_UPDATE_VERSION;
34                         }
35
36                         $stored = intval($build);
37                         $current = intval(DB_UPDATE_VERSION);
38
39                         // run any left update_nnnn functions in update.php
40                         for ($x = $stored; $x < $current; $x ++) {
41                                 $r = run_update_function($x);
42                                 if (!$r) {
43                                         break;
44                                 }
45                         }
46
47                         Config::set('system','build',DB_UPDATE_VERSION);
48                         return;
49                 case "dumpsql":
50                         DBStructure::printStructure();
51                         return;
52                 case "toinnodb":
53                         DBStructure::convertToInnoDB();
54                         return;
55         }
56 }
57
58 // print help
59 echo $_SERVER["argv"][0]." <command>\n";
60 echo "\n";
61 echo "Commands:\n";
62 echo "dryrun            show database update schema queries without running them\n";
63 echo "update            update database schema\n";
64 echo "dumpsql           dump database schema\n";
65 echo "toinnodb  convert all tables from MyISAM to InnoDB\n";
66 killme();
67