]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/DatabaseStructure.php
Merge pull request #12277 from nupplaphil/mod/fbrowser
[friendica.git] / src / Console / DatabaseStructure.php
index 3898774a5a8f123f00cde4361a27b0f31b5e1180..88f12476f5f90feb4f3c5a1d20086b77b4feef58 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Console;
 
-use Friendica\Core\Config\Cache;
+use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Core\Update;
 use Friendica\Database\Database;
 use Friendica\Database\DBStructure;
+use Friendica\Database\Definition\DbaDefinition;
+use Friendica\Database\Definition\ViewDefinition;
+use Friendica\Util\BasePath;
+use Friendica\Util\Writer\DbaDefinitionSqlWriter;
+use Friendica\Util\Writer\DocWriter;
+use Friendica\Util\Writer\ViewDefinitionSqlWriter;
 use RuntimeException;
 
 /**
@@ -34,15 +40,21 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
 {
        protected $helpOptions = ['h', 'help', '?'];
 
-       /**
-        * @var Database
-        */
+       /** @var Database */
        private $dba;
-       /**
-        * @var Cache
-        */
+
+       /** @var Cache */
        private $configCache;
 
+       /** @var DbaDefinition */
+       private $dbaDefinition;
+
+       /** @var ViewDefinition */
+       private $viewDefinition;
+
+       /** @var string */
+       private $basePath;
+
        protected function getHelp()
        {
                $help = <<<HELP
@@ -52,7 +64,7 @@ Usage
 
 Commands
     drop     Show tables that aren't in use by Friendica anymore and can be dropped
-       -e|--execute    Execute the dropping
+       -e|--execute    Execute the removal
 
     update   Update database schema
        -f|--force      Force the update command (Even if the database structure matches)
@@ -71,15 +83,18 @@ HELP;
                return $help;
        }
 
-       public function __construct(Database $dba, Cache $configCache, $argv = null)
+       public function __construct(Database $dba, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition, BasePath $basePath, Cache $configCache, $argv = null)
        {
                parent::__construct($argv);
 
                $this->dba = $dba;
+               $this->dbaDefinition = $dbaDefinition;
+               $this->viewDefinition = $viewDefinition;
                $this->configCache = $configCache;
+               $this->basePath = $basePath->getPath();
        }
 
-       protected function doExecute()
+       protected function doExecute(): int
        {
                if ($this->getOption('v')) {
                        $this->out('Class: ' . __CLASS__);
@@ -120,9 +135,9 @@ HELP;
                                $output = ob_get_clean();
                                break;
                        case "dumpsql":
-                               ob_start();
-                               DBStructure::printStructure($basePath);
-                               $output = ob_get_clean();
+                               DocWriter::writeDbDefinition($this->dbaDefinition, $this->basePath);
+                               $output = DbaDefinitionSqlWriter::create($this->dbaDefinition);
+                               $output .= ViewDefinitionSqlWriter::create($this->viewDefinition);
                                break;
                        case "toinnodb":
                                ob_start();