/** * {@inheritdoc} */ public function templateData() { $className = $this->BakeTemplate->viewVars['name']; $namespace = Configure::read('App.namespace'); $pluginPath = ''; if ($this->plugin) { $namespace = $this->_pluginNamespace($this->plugin); $pluginPath = $this->plugin . '.'; } $action = $this->detectAction($className); if (empty($action)) { return ['plugin' => $this->plugin, 'pluginPath' => $pluginPath, 'namespace' => $namespace, 'tables' => [], 'action' => null, 'name' => $className]; } $arguments = $this->args; unset($arguments[0]); $columnParser = new ColumnParser(); $fields = $columnParser->parseFields($arguments); $indexes = $columnParser->parseIndexes($arguments); $primaryKey = $columnParser->parsePrimaryKey($arguments); if (in_array($action[0], ['alter_table', 'add_field']) && !empty($primaryKey)) { $this->error('Adding a primary key to an already existing table is not supported.'); } list($action, $table) = $action; return ['plugin' => $this->plugin, 'pluginPath' => $pluginPath, 'namespace' => $namespace, 'tables' => [$table], 'action' => $action, 'columns' => ['fields' => $fields, 'indexes' => $indexes, 'primaryKey' => $primaryKey], 'name' => $className]; }
/** * {@inheritdoc} */ public function templateData() { $className = $this->BakeTemplate->viewVars['name']; $namespace = Configure::read('App.namespace'); $pluginPath = ''; if ($this->plugin) { $namespace = $this->plugin; $pluginPath = $this->plugin . '.'; } $action = $this->detectAction($className); if ($action === null) { return ['plugin' => $this->plugin, 'pluginPath' => $pluginPath, 'namespace' => $namespace, 'tables' => [], 'action' => null, 'name' => $className]; } $arguments = $this->args; unset($arguments[0]); $columnParser = new ColumnParser(); $fields = $columnParser->parseFields($arguments); $indexes = $columnParser->parseIndexes($arguments); list($action, $table) = $action; return ['plugin' => $this->plugin, 'pluginPath' => $pluginPath, 'namespace' => $namespace, 'tables' => [$table], 'action' => $action, 'columns' => ['fields' => $fields, 'indexes' => $indexes], 'name' => $className]; }