Esempio n. 1
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $charset = 'utf8';
     $collation = 'utf8_general_ci';
     $stdout = false;
     $database = $input->getArgument('database');
     if ($input->getOption('charset')) {
         $charset = (string) $input->getOption('charset');
     }
     if ($input->getOption('collation')) {
         $collation = (string) $input->getOption('collation');
     }
     if ($input->getOption('stdout')) {
         $stdout = true;
     }
     // ##################
     // Alter database
     // ##################
     $query = 'ALTER DATABASE %s CHARACTER SET %s COLLATE %s';
     $query = sprintf($query, DatabaseConnection::sanitizeSqlDatabase($database), DatabaseConnection::quote($charset), DatabaseConnection::quote($collation));
     if (!$stdout) {
         // Execute
         $output->writeln('<h2>Converting database ' . $database . '</h2>');
         DatabaseConnection::exec($query);
     } else {
         // Show only
         $output->writeln($query . ';');
     }
     // ##################
     // Alter tables
     // ##################
     $tableList = DatabaseConnection::tableList($database);
     foreach ($tableList as $table) {
         // Build statement
         $query = 'ALTER TABLE %s.%s CONVERT TO CHARACTER SET %s COLLATE %s';
         $query = sprintf($query, DatabaseConnection::sanitizeSqlDatabase($database), DatabaseConnection::sanitizeSqlTable($table), DatabaseConnection::quote($charset), DatabaseConnection::quote($collation));
         if (!$stdout) {
             // Execute
             $output->writeln('<p>Converting table ' . $table . '</p>');
             DatabaseConnection::exec($query);
         } else {
             // Show only
             $output->writeln($query . ';');
         }
     }
     return 0;
 }
Esempio n. 2
0
 /**
  * Cleanup TYPO3 database
  *
  * @param string $database Database
  */
 protected function cleanupTypo3Database($database)
 {
     $cleanupTableList = array();
     // Check if database is TYPO3 instance
     $tableList = DatabaseConnection::tableList($database);
     foreach ($tableList as $table) {
         $clearTable = false;
         // Caching und indexing tables
         switch (true) {
             case strpos($table, 'cache_') === 0:
             case strpos($table, 'cachingframework_') === 0:
             case strpos($table, 'cf_') === 0:
                 // Caching framework
                 $clearTable = true;
                 break;
             case strpos($table, 'index_') === 0:
                 // EXT:indexed_search
                 $clearTable = true;
                 break;
         }
         switch ($table) {
             case 'sys_history':
             case 'sys_log':
                 // History/Log
                 $clearTable = true;
                 break;
             case 'sys_dmain':
                 // EXT:direct_mail
                 $clearTable = true;
                 break;
             case 'tx_devlog':
                 // EXT:devlog
                 $clearTable = true;
                 break;
             case 'tx_realurl_errorlog':
             case 'tx_realurl_pathcache':
             case 'tx_realurl_urldecodecache':
             case 'tx_realurl_urlencodecache':
                 // EXT: realurl
                 $clearTable = true;
                 break;
             case 'tx_solr_cache':
             case 'tx_solr_cache_tags':
                 // EXT:solr
                 $clearTable = true;
                 break;
         }
         if ($clearTable) {
             $cleanupTableList[] = $table;
         }
     }
     $this->output->writeln('<p>Starting cleanup of database "' . $database . '"</p>');
     DatabaseConnection::switchDatabase(DatabaseConnection::sanitizeSqlDatabase($database));
     foreach ($cleanupTableList as $table) {
         $query = 'TRUNCATE ' . DatabaseConnection::sanitizeSqlTable($table);
         DatabaseConnection::exec($query);
         if ($this->output->isVerbose()) {
             $this->output->writeln('<p>Truncating table ' . $table . '</p>');
         }
     }
     $this->output->writeln('<p>finished</p>');
 }