]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/DatabaseStructure.php
Improve communication
[friendica.git] / src / Core / Console / DatabaseStructure.php
index 11904843102a64aa4e34fd9d6031c1c922c37beb..13ed29b9df9872c22306b8890f56a4ccce0c6626 100644 (file)
@@ -3,13 +3,15 @@
 namespace Friendica\Core\Console;
 
 use Friendica\Core;
+use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
+use RuntimeException;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
 
 /**
- * @brief Does database updates from the command line
+ * @brief Performs database updates from the command line
  *
  * @author Hypolite Petovan <mrpetovan@gmail.com>
  */
@@ -20,7 +22,7 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
        protected function getHelp()
        {
                $help = <<<HELP
-console dbstructure - Does database updates
+console dbstructure - Performs database updates
 Usage
        bin/console dbstructure <command> [-h|--help|-?] [-v]
 
@@ -56,8 +58,8 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if (!\dba::connected()) {
-                       throw new \RuntimeException('Unable to connect to database');
+               if (!DBA::connected()) {
+                       throw new RuntimeException('Unable to connect to database');
                }
 
                Core\Config::load();
@@ -67,8 +69,6 @@ HELP;
                                $output = DBStructure::update(true, false);
                                break;
                        case "update":
-                               $output = DBStructure::update(true, true);
-
                                $build = Core\Config::get('system', 'build');
                                if (empty($build)) {
                                        Core\Config::set('system', 'build', DB_UPDATE_VERSION);
@@ -78,9 +78,19 @@ HELP;
                                $stored = intval($build);
                                $current = intval(DB_UPDATE_VERSION);
 
-                               // run any left update_nnnn functions in update.php
+                               // run the pre_update_nnnn functions in update.php
+                               for ($x = $stored; $x < $current; $x ++) {
+                                       $r = run_update_function($x, 'pre_update');
+                                       if (!$r) {
+                                               break;
+                                       }
+                               }
+
+                               $output = DBStructure::update(true, true);
+
+                               // run the update_nnnn functions in update.php
                                for ($x = $stored; $x < $current; $x ++) {
-                                       $r = run_update_function($x);
+                                       $r = run_update_function($x, 'update');
                                        if (!$r) {
                                                break;
                                        }