/** * Initializes this fixture class * * @return boolean */ public function create($db) { if (!empty($this->fields)) { return parent::create($db); } return (bool) $db->execute(file_get_contents($this->_getFilePath())); }
function create(&$db) { $result = parent::create($db); if ($result) { $db->execute('ALTER TABLE `items` CHANGE `provider_key` `provider_key` BIGINT( 20 ) NULL DEFAULT NULL '); } return $result; }
/** * Maps enum fields in the database to strings with a length of 64 */ public function create($db) { foreach ($this->fields as $name => &$field) { if (strstr($field['type'], "enum") !== false) { $field['type'] = 'string'; $field['length'] = 64; } } parent::create($db); }
public function create($db) { parent::create($db); return ' CREATE TABLE `multilanguage_model` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `object_id` int(11) unsigned NOT NULL, `lang_code` varchar(5) NOT NULL, `name` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8'; }
/** * Initializes this fixture class * * @param DboSource $db * @return boolean */ public function create($db) { if (!empty($this->fields)) { return parent::create($db); } $source = ConnectionManager::getDataSource($this->sourceConfig); $sourceTable = $source->fullTableName($this->table); $query = sprintf('DROP TABLE IF EXISTS %s', $db->fullTableName($this->table)); $db->execute($query, ['log' => false]); $query = sprintf('CREATE TABLE %s LIKE %s', $db->fullTableName($this->table), $sourceTable); $db->execute($query, ['log' => false]); $this->created[] = $db->configKeyName; return true; }
public function create($db) { $ok = parent::create($db); // Workaround: CakeSchema cannot create FULLTEXT fixtures, so we change the table manually after creation if ($ok) { $query = "ALTER TABLE `{$this->table}` ADD FULLTEXT INDEX `data` (`data` ASC)"; try { $db->rawQuery($query); $this->created[] = $db->configKeyName; } catch (Exception $e) { $msg = __d('cake_dev', 'Fixture creation for "%s" failed "%s"', $this->table, $e->getMessage()); CakeLog::error($msg); trigger_error($msg, E_USER_WARNING); return false; } return true; } return false; }
/** * Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully. * * @param object $db An instance of the database object used to create the fixture table * @return boolean True on success, false on failure * @access public * @ override */ public function create(&$db) { if (isset($this->fields) && !empty($this->fields) && empty($this->fields['tableParameters']['engine'])) { $canUseMemory = true; foreach ($this->fields as $field => $args) { if (is_string($args)) { $type = $args; } elseif (!empty($args['type'])) { $type = $args['type']; } else { continue; } if (in_array($type, array('blob', 'text', 'binary'))) { $canUseMemory = false; break; } } if ($canUseMemory) { $this->fields['tableParameters']['engine'] = 'MEMORY'; } } return parent::create($db); }
/** * Runs the drop and create commands on the fixtures if necessary. * * @param CakeTestFixture $fixture the fixture object to create * @param DataSource $db the datasource instance to use * @param boolean $drop whether drop the fixture if it is already created or not * @return void */ protected function _setupTable($fixture, $db = null, $drop = true) { if (!$db) { if (!empty($fixture->useDbConfig)) { $db = ClassRegistry::getDataSource($fixture->useDbConfig); } else { $db = $this->_db; } } if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) { return; } $sources = $db->listSources(); $table = $db->config['prefix'] . $fixture->table; if ($drop && in_array($table, $sources)) { $fixture->drop($db); $fixture->create($db); } elseif (!in_array($table, $sources)) { $fixture->create($db); } }
/** * Runs the drop and create commands on the fixtures if necessary. * * @param CakeTestFixture $fixture the fixture object to create * @param DataSource $db the datasource instance to use * @param bool $drop whether drop the fixture if it is already created or not * @return void */ protected function _setupTable($fixture, $db = null, $drop = true) { if (!$db) { if (!empty($fixture->useDbConfig)) { $db = ConnectionManager::getDataSource($fixture->useDbConfig); } else { $db = $this->_db; } } if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) { return; } $sources = (array) $db->listSources(); $table = $db->config['prefix'] . $fixture->table; $exists = in_array($table, $sources); if ($drop && $exists) { $fixture->drop($db); $fixture->create($db); } elseif (!$exists) { $fixture->create($db); } else { $fixture->created[] = $db->configKeyName; } }
/** * Callback issued when a controller's action is about to be invoked through testAction(). * * @param Controller $controller Controller that's about to be invoked. * @param array $params Additional parameters as sent by testAction(). * @return void * @access public */ function startController(&$controller, $params = array()) { if (isset($params['fixturize']) && (is_array($params['fixturize']) && !empty($params['fixturize']) || $params['fixturize'] === true)) { if (!isset($this->db)) { $this->_initDb(); } if ($controller->uses === false) { $list = array($controller->modelClass); } else { $list = is_array($controller->uses) ? $controller->uses : array($controller->uses); } $models = array(); ClassRegistry::config(array('ds' => $params['connection'])); foreach ($list as $name) { if (is_array($params['fixturize']) && in_array($name, $params['fixturize']) || $params['fixturize'] === true) { if (class_exists($name) || App::import('Model', $name)) { $object = ClassRegistry::init($name); //switch back to specified datasource. $object->setDataSource($params['connection']); $db = ConnectionManager::getDataSource($object->useDbConfig); $db->cacheSources = false; $models[$object->alias] = array('table' => $object->table, 'model' => $object->alias, 'key' => strtolower($name)); } } } ClassRegistry::config(array('ds' => 'test_suite')); if (!empty($models) && isset($this->db)) { $this->_actionFixtures = array(); foreach ($models as $model) { $fixture = new CakeTestFixture($this->db); $fixture->name = $model['model'] . 'Test'; $fixture->table = $model['table']; $fixture->import = array('model' => $model['model'], 'records' => true); $fixture->init(); $fixture->create($this->db); $fixture->insert($this->db); $this->_actionFixtures[] = $fixture; } foreach ($models as $model) { $object = ClassRegistry::getObject($model['key']); if ($object !== false) { $object->setDataSource('test_suite'); $object->cacheSources = false; } } } } }
/** * Runs the drop and create commands on the fixtures if necessary * * @param CakeTestFixture $fixture the fixture object to create * @param DataSource $db the datasource instance to use * @param boolean $drop whether drop the fixture if it is already created or not * @return void */ protected function _setupTable($fixture, $db = null, $drop = true) { if (!$db) { $db = $this->_db; } if (!empty($fixture->created) && $fixture->created == $db->configKeyName) { return; } $cacheSources = $db->cacheSources; $db->cacheSources = false; $sources = $db->listSources(); $db->cacheSources = $cacheSources; $table = $db->config['prefix'] . $fixture->table; if ($drop && in_array($table, $sources)) { $fixture->drop($db); $fixture->create($db); $fixture->created = $db->configKeyName; } elseif (!in_array($table, $sources)) { $fixture->create($db); $fixture->created = $db->configKeyName; } }
public function create(&$db) { $db->columns['decimal'] = array('name' => 'decimal', 'formatter' => 'floatval'); return parent::create($db); }
public function creaete($db) { $ret = parent::create($db); var_dump($ret); exit; }