Example #1
0
 /**
  * Gets a list of table to baked based on the Collection instance passed and the options passed to
  * the shell call.
  *
  * @param \Cake\Database\Schema\Collection $collection Instance of the collection of a specific database
  * connection.
  * @param array $options Array of options passed to a shell call.
  * @return array
  */
 protected function getTablesToBake(Collection $collection, $options = [])
 {
     $options = array_merge(['require-table' => false, 'plugin' => null], $options);
     $tables = $collection->listTables();
     if ($options['require-table'] === true || $options['plugin']) {
         $tableNamesInModel = $this->getTableNames($options['plugin']);
         if (empty($tableNamesInModel)) {
             return [];
         }
         foreach ($tableNamesInModel as $num => $table) {
             if (!in_array($table, $tables)) {
                 unset($tableNamesInModel[$num]);
             }
         }
         $tables = $tableNamesInModel;
     } else {
         foreach ($tables as $num => $table) {
             if (in_array($table, $this->skipTables) || strpos($table, $this->skipTablesRegex) !== false) {
                 unset($tables[$num]);
                 continue;
             }
         }
     }
     return $tables;
 }
Example #2
0
 /**
  * Test listing tables with Postgres
  *
  * @return void
  */
 public function testListTables()
 {
     $connection = ConnectionManager::get('test');
     $this->_createTables($connection);
     $schema = new SchemaCollection($connection);
     $result = $schema->listTables();
     $this->assertInternalType('array', $result);
     $this->assertContains('schema_articles', $result);
     $this->assertContains('schema_authors', $result);
 }
Example #3
0
 /**
  * Gets a list of table to baked based on the Collection instance passed and the options passed to
  * the shell call.
  *
  * @param \Cake\Database\Schema\Collection $collection Instance of the collection of a specific database
  * connection.
  * @param array $options Array of options passed to a shell call.
  * @return array
  */
 protected function getTablesToBake(Collection $collection, $options = [])
 {
     $options = array_merge(['require-table' => false, 'plugin' => null], $options);
     $tables = $collection->listTables();
     if (empty($tables)) {
         return $tables;
     }
     if ($options['require-table'] === true || $options['plugin']) {
         $tableNamesInModel = $this->getTableNames($options['plugin']);
         if (empty($tableNamesInModel)) {
             return [];
         }
         foreach ($tableNamesInModel as $num => $table) {
             if (strpos($table, '.') !== false) {
                 $splitted = array_reverse(explode('.', $table, 2));
                 $config = ConnectionManager::config($this->connection);
                 $key = isset($config['schema']) ? 'schema' : 'database';
                 if ($config[$key] === $splitted[1]) {
                     $table = $splitted[0];
                 }
             }
             if (!in_array($table, $tables)) {
                 unset($tableNamesInModel[$num]);
             }
         }
         $tables = $tableNamesInModel;
     } else {
         foreach ($tables as $num => $table) {
             if (in_array($table, $this->skipTables) || strpos($table, $this->skipTablesRegex) !== false) {
                 unset($tables[$num]);
                 continue;
             }
         }
     }
     return $tables;
 }