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