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