示例#1
0
 /**
  * Prepares data in Config/Data/ required for install plugin
  *
  * Usage: ./Console/cake extensions.data_migration data table_name_here
  */
 public function data()
 {
     if (isset($this->params['plugin'])) {
         $plugin = $this->params['plugin'];
     }
     $connection = 'default';
     if (isset($this->params['connection'])) {
         $connection = $this->params['connection'];
     }
     $table = trim($this->args['0']);
     $name = Inflector::camelize(Inflector::singularize($table));
     $root = isset($plugin) ? CakePlugin::path($plugin) : APP;
     $output = $root . 'Config' . DS . 'Data' . DS . $name . 'Data.php';
     $records = array();
     $options = array('model' => array('name' => $name, 'table' => $table, 'connection' => $connection), 'output' => $output);
     $DataMigration = new DataMigration();
     $success = $DataMigration->generate('all', array('recursive' => -1), $options);
     if ($success) {
         $this->out('<success>New file generated</success>: ' . str_replace(APP, '', $output));
     } else {
         $this->err('<error>Failed generating file for table</error>: ' . $table);
     }
 }