public function bake($name, $data = array()) { if ($name instanceof Model) { $object = new Model(array('name' => $name->name)); $fields = $object->schema(); $data['fields'] = $fields; } else { //Changed By Dkmadmin $object = new Model(array('name' => $name)); $fields = $object->schema(); $data['fields'] = $fields; } return parent::bake($name, $data); }
/** * Execution method always used for tasks * * @return void */ public function execute() { if (isset($this->params['plugin'])) { $plugin = $this->params['plugin']; $pluginPath = $plugin . '.'; App::uses($plugin . 'AppModel', $pluginPath . 'Model'); $pluginmodel = $plugin . 'AppModel'; $plugin_model = new $pluginmodel(); $db = ConnectionManager::getDataSource('default'); $db->cacheSources = false; $config = $db->config; $config['prefix'] = $plugin_model->tablePrefix; ConnectionManager::create('tmpDataSource', $config); $this->connection = 'tmpDataSource'; } parent::execute(); }
/** * Overrides ModelTask::bake() * * Calls ModelTask::bake() with no validation, which creates the baked model * file and then gets the contents, inserts the validation property, generated * by ModelFullValidateTask::bakeValidation() method after the name property * and writes the new contents back to the file. * * It's a filthy hack, but the alternative is copying the entire 170 line * ModelTask::bake() method into ModelFullValidateTask and replacing a small * portion of it with the new code. * * @param mixed $name Model name or object * @param mixed $associations if array and $name is not an object assume Model associations array otherwise boolean interactive * @param array $validate Validation rules * @param string $primaryKey Primary key to use * @param string $useTable Table to use * @param string $useDbConfig Database configuration setting to use * @access private */ function bake($name, $associations = array(), $validate = array(), $primaryKey = 'id', $useTable = null, $useDbConfig = 'default') { // Call bake method on ModelTask but with no validation $result = parent::bake($name, $associations, array(), $primaryKey, $useTable, $useDbConfig); if (!$result) { return $result; } // Get the contents of the baked file $filename = $this->path . Inflector::underscore($name) . '.php'; $contents = file_get_contents($filename); // The string after which we want to insert the validation property $addValidationAfterString = "var \$name = '{$name}';"; // The position of the above string in the file contents $addValidationAfterPos = strpos($contents, $addValidationAfterString); // If the string was found if ($addValidationAfterPos !== false) { // Bake the new validation in full format $validation = "\n\n" . $this->bakeValidation($validate); // Add it into the contents $contents = substr_replace($contents, $validation, $addValidationAfterPos + strlen($addValidationAfterString), 0); // Write the contents back to the file file_put_contents($filename, $contents); } // Return the result of the parent::bake() method return $result; }
/** * get the option parser. * * @return void */ public function getOptionParser() { $parser = parent::getOptionParser(); return $parser->addOption('plugin', array('short' => 'l', 'help' => __d('cake_console', 'Plugin.')))->addOption('appTestCase', array('short' => 'z', 'help' => __d('cake_console', 'App test case.')))->addOption('noAppTestCase', array('short' => 'n', 'help' => __d('cake_console', 'App test case.')))->addOption('slug', array('short' => 's', 'boolean' => true, 'help' => __d('cake_console', 'Use slug.')))->addOption('parentSlug', array('short' => 'f', 'boolean' => true, 'help' => __d('cake_console', 'Use slug.')))->addOption('user', array('short' => 'u', 'help' => __d('cake_console', 'Use user model.')))->addOption('parent', array('short' => 'r', 'help' => __d('cake_console', 'Use parent model.')))->addOption('theme', array('short' => 't', 'help' => __d('cake_console', 'theme.')))->addOption('subthemes', array('short' => 'b', 'help' => __d('cake_console', 'subthemes.')))->addOption('property', array('short' => 'y', 'boolean' => true, 'help' => __d('cake_console', 'generate IDE properties hints for model relations'))); }