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

resolveTables() public method

public resolveTables ( array $list, array $definitions = [], array $resolved = [] ) : array
$list array
$definitions array
$resolved array Which definitions where already resolved -> prevent endless loops
return array
    public function resolveTables(array $list, array $definitions = array(), array $resolved = array())
    {
        if ($this->_tables === null) {
            $this->_tables = $this->getTables(true);
        }
        $resolvedList = array();
        foreach ($list as $entry) {
            if (substr($entry, 0, 1) == '@') {
                $code = substr($entry, 1);
                if (!isset($definitions[$code])) {
                    throw new RuntimeException('Table-groups could not be resolved: ' . $entry);
                }
                if (!isset($resolved[$code])) {
                    $resolved[$code] = true;
                    $tables = $this->resolveTables(explode(' ', $definitions[$code]['tables']), $definitions, $resolved);
                    $resolvedList = array_merge($resolvedList, $tables);
                }
                continue;
            }
            // resolve wildcards
            if (strpos($entry, '*') !== false) {
                $connection = $this->getConnection();
                $sth = $connection->prepare('SHOW TABLES LIKE :like', array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
                $sth->execute(array(':like' => str_replace('*', '%', $this->dbSettings['prefix'] . $entry)));
                $rows = $sth->fetchAll();
                foreach ($rows as $row) {
                    $resolvedList[] = $row[0];
                }
                continue;
            }
            if (in_array($entry, $this->_tables)) {
                $resolvedList[] = $this->dbSettings['prefix'] . $entry;
            }
        }
        asort($resolvedList);
        $resolvedList = array_unique($resolvedList);
        return $resolvedList;
    }

Usage Example

 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @throws \InvalidArgumentException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $this->isTypeAllowed();
     $this->detectMagento($output);
     $this->dbHelper = $this->getHelper('database');
     $this->showProgress = $input->getOption('format') == null;
     if ($input->getOption('table')) {
         $resolvedTables = array($this->dbHelper->resolveTables(array('@check'), array('check' => array('tables' => $input->getOption('table')))));
         $tables = $resolvedTables[0];
     } else {
         $tables = $this->dbHelper->getTables();
     }
     $allTableStatus = $this->dbHelper->getTablesStatus();
     $tableOutput = array();
     /** @var \Symfony\Component\Console\Helper\ProgressHelper $progress */
     $progress = $this->getHelper('progress');
     if ($this->showProgress) {
         $progress->start($output, count($tables));
     }
     $methods = array('InnoDB' => 1, 'MEMORY' => 1, 'MyISAM' => 1);
     foreach ($tables as $tableName) {
         if (isset($allTableStatus[$tableName]) && isset($methods[$allTableStatus[$tableName]['Engine']])) {
             $m = '_check' . $allTableStatus[$tableName]['Engine'];
             $tableOutput = array_merge($tableOutput, $this->{$m}($tableName));
         } else {
             $tableOutput[] = array('table' => $tableName, 'operation' => 'not supported', 'type' => '', 'status' => '');
         }
         $this->progressAdvance();
     }
     if ($this->showProgress) {
         $progress->finish();
     }
     $this->getHelper('table')->setHeaders(array('Table', 'Operation', 'Type', 'Status'))->renderByFormat($this->output, $tableOutput, $this->input->getOption('format'));
 }
All Usage Examples Of N98\Util\Console\Helper\DatabaseHelper::resolveTables