/** * insert * * @param Object $db * @return array */ public function insert($db) { $result = parent::insert($db); if ($result === true && $db instanceof Postgres) { $this->_fixSequence($db); } return $result; }
/** * Inserts records in the database * * @param DboSource $db * @return boolean */ public function insert($db) { if (isset($this->_insert)) { return true; } if (!empty($this->records)) { return parent::insert($db); } return (bool) $db->execute(file_get_contents($this->_getFilePath())); }
/** * Inserts records in the database * * This will only happen if the underlying table is modified in any way or * does not exist with a hash yet. * * @param DboSource $db * @return boolean */ public function insert($db) { if ($this->_tableUnmodified($db)) { return true; } if (!empty($this->records)) { if (empty($this->fields)) { $this->fields = $db->describe($this->table); } $result = parent::insert($db); static::$_tableHashes[$this->table] = $this->_hash($db); return $result; } $source = ConnectionManager::getDataSource($this->sourceConfig); $sourceTable = $source->fullTableName($this->table); $query = sprintf('TRUNCATE TABLE %s', $db->fullTableName($this->table)); $db->execute($query, ['log' => false]); $query = sprintf('INSERT INTO %s SELECT * FROM %s', $db->fullTableName($this->table), $sourceTable); $db->execute($query, ['log' => false]); static::$_tableHashes[$this->table] = $this->_hash($db); return true; }
/** * Recovers tree after insterting data. This way we only need to properly define * the parent_id's for each records * * @param object $db Instance of DB * @return boolean Success */ public function insert(&$db) { $success = parent::insert($db); ClassRegistry::init('Ministry')->recover(); return $success; }
/** * 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; } } } } }