N98\Util\Console\Helper\DatabaseHelper::getTableDefinitions PHP Method

getTableDefinitions() public method

public getTableDefinitions ( array $commandConfig ) : array
$commandConfig array
return array
    public function getTableDefinitions(array $commandConfig)
    {
        $tableDefinitions = array();
        if (isset($commandConfig['table-groups'])) {
            $tableGroups = $commandConfig['table-groups'];
            foreach ($tableGroups as $index => $definition) {
                $description = isset($definition['description']) ? $definition['description'] : '';
                if (!isset($definition['id'])) {
                    throw new RuntimeException('Invalid definition of table-groups (id missing) Index: ' . $index);
                }
                if (!isset($definition['tables'])) {
                    throw new RuntimeException('Invalid definition of table-groups (tables missing) Id: ' . $definition['id']);
                }
                $tableDefinitions[$definition['id']] = array('tables' => $definition['tables'], 'description' => $description);
            }
        }
        return $tableDefinitions;
    }

Usage Example

Example #1
0
 /**
  * PHP alternative to dump database without exec
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  */
 private function createBackupWithoutExec(InputInterface $input, OutputInterface $output)
 {
     $magerun = $this->getMagerun();
     $filePath = $this->getFilePath($input);
     $stripOptions = $input->getOption('strip') ?: '@development';
     // Exec must be unavailable so use PHP alternative (match output)
     $dbHelper = new DatabaseHelper();
     $dbHelper->setHelperSet($magerun->getHelperSet());
     $dbHelper->detectDbSettings(new NullOutput());
     $magerunConfig = $magerun->getConfig();
     $stripTables = $dbHelper->resolveTables(explode(' ', $stripOptions), $dbHelper->getTableDefinitions($magerunConfig['commands']['N98\\Magento\\Command\\Database\\DumpCommand']));
     $output->writeln(array('', $magerun->getHelperSet()->get('formatter')->formatBlock('Dump MySQL Database (without exec)', 'bg=blue;fg=white', true), ''));
     $dbSettings = $dbHelper->getDbSettings();
     $username = (string) $dbSettings['username'];
     $password = (string) $dbSettings['password'];
     $dbName = (string) $dbSettings['dbname'];
     try {
         $output->writeln('<comment>No-data export for: <info>' . implode(' ', $stripTables) . '</info></comment>');
         $output->writeln('<comment>Start dumping database <info>' . $dbSettings['dbname'] . '</info> to file <info>' . $filePath . '</info>');
         // Dump Structure for tables that we are not to receive data from
         $dumpStructure = new Mysqldump(sprintf('%s;dbname=%s', $dbHelper->dsn(), $dbName), $username, $password, array('include-tables' => $stripTables, 'no-data' => true));
         $dumpStructure->start($filePath . '.structure');
         $dump = new Mysqldump(sprintf('%s;dbname=%s', $dbHelper->dsn(), $dbName), $username, $password, array('exclude-tables' => $stripTables));
         $dump->start($filePath . '.data');
         // Now merge two files
         $fhData = fopen($filePath . '.data', 'a+');
         $fhStructure = fopen($filePath . '.structure', 'r');
         if ($fhData && $fhStructure) {
             while (!feof($fhStructure)) {
                 fwrite($fhData, fgets($fhStructure, 4096));
             }
         }
         fclose($fhStructure);
         // Gzip
         rewind($fhData);
         $zfh = gzopen($filePath, 'wb');
         while (!feof($fhData)) {
             gzwrite($zfh, fgets($fhData, 4096));
         }
         gzclose($zfh);
         fclose($fhData);
     } catch (\Exception $e) {
         throw new \Exception("Unable to export database.");
     }
 }
All Usage Examples Of N98\Util\Console\Helper\DatabaseHelper::getTableDefinitions