Exemple #1
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_crud_check_table_name', array($this->console->colorize($this->params->paramTableName, Color::GREEN)));
     /** @var Adapter $dbAdapter */
     $dbAdapter = $this->params->dbAdapter;
     // get Metadata for database adapter
     $metaData = new Metadata($dbAdapter);
     // fetch database
     $database = $dbAdapter->getCurrentSchema();
     // fetch table object
     try {
         $table = $metaData->getTable($this->params->paramTableName);
     } catch (Exception $e) {
         $this->console->writeFailLine('task_crud_check_table_not_exists', array($this->console->colorize($this->params->paramTableName, Color::GREEN), $this->console->colorize($database, Color::GREEN)));
         return 1;
     }
     $tableObjects = array();
     /** @var TableObject $tableObject */
     foreach ($metaData->getTables() as $tableObject) {
         $tableObjects[$tableObject->getName()] = $tableObject;
     }
     $this->params->currentTableObjects = $tableObjects;
     return 0;
 }
Exemple #2
0
 /**
  * @param Adapter $adapter
  * @param null $options
  * @param bool $autoLoad
  */
 public function __construct(Adapter $adapter, $options = null, $autoLoad = true)
 {
     /** @var $db Adapter */
     $this->db = $adapter;
     self::$defaultDb = $adapter;
     $this->options = $options;
     if (isset($options['blacklist']) && !isset($options['whitelist'])) {
         if (is_array($options['blacklist'])) {
             $this->blackList = $options['blacklist'];
         } else {
             $this->blackList[] = (string) $options['blacklist'];
         }
     } elseif (isset($options['whitelist']) && !empty($options['whitelist'])) {
         if (is_array($options['whitelist'])) {
             $this->whiteList = $options['whitelist'];
         } else {
             $this->whiteList[] = (string) $options['whitelist'];
         }
     }
     if ($autoLoad) {
         $metadata = new Metadata($adapter);
         $tables = $metadata->getTables();
         foreach ($tables as $table) {
             $this->addTable($table->getName());
         }
     }
 }
Exemple #3
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     /** @var Adapter $dbAdapter */
     $dbAdapter = $this->params->dbAdapter;
     // get Metadata for database adapter
     $metaData = new Metadata($dbAdapter);
     // fetch database
     $database = $dbAdapter->getCurrentSchema();
     // fetch tables
     $tables = $metaData->getTables();
     // output found modules
     $this->console->writeTaskLine('task_crud_show_tables_found', array($this->console->colorize($database, Color::GREEN)));
     $this->console->writeLine();
     // loop through modules
     foreach ($tables as $tableObject) {
         $this->console->writeListItemLine('task_crud_show_tables_table_name', array($this->console->colorize($tableObject->getName(), Color::GREEN)));
     }
     return 0;
 }
Exemple #4
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_crud_load_entity_class', [$this->console->colorize($this->params->paramEntityClass, Color::GREEN), $this->console->colorize($this->params->paramEntityModule, Color::GREEN)]);
     if (!file_exists($this->params->entityModuleDir)) {
         $this->console->writeFailLine('task_crud_load_entity_module_not_found', [$this->console->colorize($this->params->paramEntityModule, Color::GREEN)]);
         return 1;
     }
     if (!file_exists($this->params->entityFile)) {
         $this->console->writeFailLine('task_crud_load_entity_entity_not_found', [$this->console->colorize($this->params->paramEntityClass, Color::GREEN), $this->console->colorize($this->params->paramEntityModule, Color::GREEN)]);
         return 1;
     }
     require_once $this->params->entityFile;
     $entityClass = new FileReflection($this->params->entityFile);
     $this->params->loadedEntity = $entityClass->getClass();
     /** @var Adapter $dbAdapter */
     $dbAdapter = $this->params->dbAdapter;
     // get Metadata for database adapter
     $metaData = new Metadata($dbAdapter);
     // init loaded tables
     $loadedTables = [];
     /** @var TableObject $tableObject */
     foreach ($metaData->getTables() as $tableObject) {
         $columns = [];
         $primaryKey = [];
         $foreignKeys = [];
         /** @var ColumnObject $columnObject */
         foreach ($tableObject->getColumns() as $columnObject) {
             $columns[$columnObject->getName()] = $columnObject;
         }
         /** @var ConstraintObject $constraintObject */
         foreach ($tableObject->getConstraints() as $constraintObject) {
             if ($constraintObject->isPrimaryKey()) {
                 $primaryKey = $constraintObject;
             } elseif ($constraintObject->isForeignKey()) {
                 $foreignKeys[$constraintObject->getName()] = $constraintObject;
             }
         }
         $loadedTables[$tableObject->getName()] = ['columns' => $columns, 'primaryKey' => $primaryKey, 'foreignKeys' => $foreignKeys];
     }
     $this->params->loadedTables = $loadedTables;
     return 0;
 }
Exemple #5
0
 /**
  * Render
  * 
  * @param  \Zend\Db\Metadata\Metadata $metadata
  * @return string 
  */
 public function render(\Zend\Db\Metadata\Metadata $metadata)
 {
     $output = '';
     $output .= $this->renderTables($metadata->getTables());
     return $output;
 }
Exemple #6
0
 /**
  * Load table metadata.
  *
  * @param bool $reload Force a reload? (Default is false).
  *
  * @return array
  */
 protected function getTableInfo($reload = false)
 {
     if ($reload || !$this->tableInfo) {
         $metadata = new DbMetadata($this->getAdapter());
         $tables = $metadata->getTables();
         $this->tableInfo = array();
         foreach ($tables as $current) {
             $this->tableInfo[$current->getName()] = $current;
         }
     }
     return $this->tableInfo;
 }
Exemple #7
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_crud_load_tables_name', [$this->console->colorize($this->params->paramTableName, Color::GREEN)]);
     /** @var Adapter $dbAdapter */
     $dbAdapter = $this->params->dbAdapter;
     // get Metadata for database adapter
     $metaData = new Metadata($dbAdapter);
     // fetch database
     $database = $dbAdapter->getCurrentSchema();
     // init loaded tables
     $loadedTables = [];
     /** @var TableObject $tableObject */
     foreach ($metaData->getTables() as $tableObject) {
         $columns = [];
         $primaryKey = [];
         $foreignKeys = [];
         /** @var ColumnObject $columnObject */
         foreach ($tableObject->getColumns() as $columnObject) {
             $columns[$columnObject->getName()] = $columnObject;
         }
         /** @var ConstraintObject $constraintObject */
         foreach ($tableObject->getConstraints() as $constraintObject) {
             if ($constraintObject->isPrimaryKey()) {
                 $primaryKey = $constraintObject;
             } elseif ($constraintObject->isForeignKey()) {
                 $foreignKeys[$constraintObject->getName()] = $constraintObject;
             }
         }
         $loadedTables[$tableObject->getName()] = ['columns' => $columns, 'primaryKey' => $primaryKey, 'foreignKeys' => $foreignKeys];
     }
     // get missing tables
     $missingTables = array_values(array_diff($this->params->paramTableList, array_keys($loadedTables)));
     // check missing tables
     if (count($missingTables) == 1) {
         $this->console->writeFailLine('task_crud_load_tables_not_exists_one', [$this->console->colorize($missingTables[0], Color::GREEN), $this->console->colorize($database, Color::GREEN)]);
         return 1;
     } elseif (count($missingTables) > 1) {
         $this->console->writeFailLine('task_crud_load_tables_not_exists_more', [$this->console->colorize(implode(', ', $missingTables), Color::GREEN), $this->console->colorize($database, Color::GREEN)]);
         return 1;
     }
     // Ini needed tables
     $neededTables = [];
     // loop through table list
     foreach ($this->params->paramTableList as $tableName) {
         $neededTables[] = $tableName;
         /** @var ConstraintObject $foreignKey */
         foreach ($loadedTables[$tableName]['foreignKeys'] as $foreignKey) {
             $neededTables[] = $foreignKey->getReferencedTableName();
         }
     }
     // get missing tables
     $missingTables = array_values(array_diff($neededTables, $this->params->paramTableList));
     // check missing tables
     if (count($missingTables) == 1) {
         $this->console->writeFailLine('task_crud_load_tables_needed_one', [$this->console->colorize($missingTables[0], Color::GREEN), $this->console->colorize($database, Color::GREEN)]);
         return 1;
     } elseif (count($missingTables) > 1) {
         $this->console->writeFailLine('task_crud_load_tables_needed_more', [$this->console->colorize(implode(', ', $missingTables), Color::GREEN), $this->console->colorize($database, Color::GREEN)]);
         return 1;
     }
     // get unneeded tables
     $unneededTables = array_diff(array_keys($loadedTables), $this->params->paramTableList);
     // clear unneeded tables
     foreach ($unneededTables as $tableName) {
         unset($loadedTables[$tableName]);
     }
     $this->params->loadedTables = $loadedTables;
     return 0;
 }