]> git.mxchange.org Git - friendica.git/commitdiff
Ability to set the database version
authorMichael <heluecht@pirati.ca>
Sun, 13 Sep 2020 15:57:24 +0000 (15:57 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 13 Sep 2020 15:57:24 +0000 (15:57 +0000)
src/Console/DatabaseStructure.php
src/Database/DBStructure.php
src/Module/Friendica.php

index 6b1fa8d4d6fecaad35db3b445e00ddec0735820d..a1b4fdbfe8150b28a4d759e2e296ea33df2de822 100644 (file)
@@ -55,6 +55,7 @@ Commands
        update   Update database schema
        dumpsql  Dump database schema
        toinnodb Convert all tables from MyISAM or InnoDB in the Antelope file format to InnoDB in the Barracuda file format
+       version  Set the database to a given number
 
 Options
     -h|--help|-?       Show help information
@@ -86,8 +87,10 @@ HELP;
                        return 0;
                }
 
-               if (count($this->args) > 1) {
+               if ((count($this->args) > 1) && ($this->getArgument(0) != 'version')) {
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+               } elseif ((count($this->args) != 2) && ($this->getArgument(0) == 'version')) {
+                       throw new \Asika\SimpleConsole\CommandArgsException('This command needs two arguments');
                }
 
                if (!$this->dba->isConnected()) {
@@ -115,6 +118,12 @@ HELP;
                                DBStructure::convertToInnoDB();
                                $output = ob_get_clean();
                                break;
+                       case "version":
+                               ob_start();
+                               DBStructure::setDatabaseVersion($this->getArgument(1));
+                               $output = ob_get_clean();
+                               break;
+                                       
                        default:
                                $output = 'Unknown command: ' . $this->getArgument(0);
                }
index bf76eccacb50edd3b6f19dcea3360477d3fc4e3c..bdd8cc208efe2e829183ef3e2ab6ab74d75c802a 100644 (file)
@@ -48,6 +48,22 @@ class DBStructure
         */
        private static $definition = [];
 
+       /**
+        * Set a database version to trigger update functions
+        *
+        * @param string $version
+        * @return void
+        */
+       public static function setDatabaseVersion(string $version)
+       {
+               if (!is_numeric($version)) {
+                       throw new \Asika\SimpleConsole\CommandArgsException('The version number must be numeric');
+               }
+
+               DI::config()->set('system', 'build', $version);
+               echo DI::l10n()->t('The database version had been set to %s.', $version);
+       }
+
        /**
         * Converts all tables from MyISAM/InnoDB Antelope to InnoDB Barracuda
         */
index 2d76f80d04a7185b95a69ad2ead8cc20da8c65bc..f02cc2610b803888d1f75232c720dcf69a9007cc 100644 (file)
@@ -95,7 +95,7 @@ class Friendica extends BaseModule
                        'about'     => DI::l10n()->t('This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.',
                                '<strong>' . FRIENDICA_VERSION . '</strong>',
                                DI::baseUrl()->get(),
-                               '<strong>' . DB_UPDATE_VERSION . '</strong>',
+                               '<strong>' . DB_UPDATE_VERSION . '/' . $config->get('system', 'build') .'</strong>',
                                '<strong>' . $config->get('system', 'post_update_version') . '</strong>'),
                        'friendica' => DI::l10n()->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
                        'bugs'      => DI::l10n()->t('Bug reports and issues: please visit') . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . DI::l10n()->t('the bugtracker at github') . '</a>',