]> 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 b44400c01a0b710c6cb8dc8b36c6239b6c155731..88f12476f5f90feb4f3c5a1d20086b77b4feef58 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Console;
 
 
 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\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;
 
 /**
 use RuntimeException;
 
 /**
@@ -34,15 +40,21 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
 {
        protected $helpOptions = ['h', 'help', '?'];
 
 {
        protected $helpOptions = ['h', 'help', '?'];
 
-       /**
-        * @var Database
-        */
+       /** @var Database */
        private $dba;
        private $dba;
-       /**
-        * @var Cache
-        */
+
+       /** @var Cache */
        private $configCache;
 
        private $configCache;
 
+       /** @var DbaDefinition */
+       private $dbaDefinition;
+
+       /** @var ViewDefinition */
+       private $viewDefinition;
+
+       /** @var string */
+       private $basePath;
+
        protected function getHelp()
        {
                $help = <<<HELP
        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
 
 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)
 
     update   Update database schema
        -f|--force      Force the update command (Even if the database structure matches)
@@ -71,15 +83,18 @@ HELP;
                return $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;
        {
                parent::__construct($argv);
 
                $this->dba = $dba;
+               $this->dbaDefinition = $dbaDefinition;
+               $this->viewDefinition = $viewDefinition;
                $this->configCache = $configCache;
                $this->configCache = $configCache;
+               $this->basePath = $basePath->getPath();
        }
 
        }
 
-       protected function doExecute()
+       protected function doExecute(): int
        {
                if ($this->getOption('v')) {
                        $this->out('Class: ' . __CLASS__);
        {
                if ($this->getOption('v')) {
                        $this->out('Class: ' . __CLASS__);
@@ -120,10 +135,9 @@ HELP;
                                $output = ob_get_clean();
                                break;
                        case "dumpsql":
                                $output = ob_get_clean();
                                break;
                        case "dumpsql":
-                               DBStructure::writeStructure();
-                               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();
                                break;
                        case "toinnodb":
                                ob_start();