/** * Configures a Propel datasource. * * @param array $parameters The datasource parameters * @param string $name The datasource name */ public function initialize($parameters = null, $name = 'propel') { parent::initialize($parameters); if (!$this->hasParameter('datasource') && $this->hasParameter('name')) { $this->setParameter('datasource', $this->getParameter('name')); } elseif (!$this->hasParameter('datasource') && !empty($name)) { $this->setParameter('datasource', $name); } $this->addConfig(); // mark the first connection as the default if (!Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter('datasources.default')) { $this->setDefaultConfig(); } // for BC if ($this->getParameter('pooling', false)) { Propel::enableInstancePooling(); } else { Propel::disableInstancePooling(); } }
/** * Initializes sfPropelDatabase by loading configuration and initializing Propel * * @param array $parameters The datasource parameters * @param string $name The datasource name * * @return void */ public function initialize($parameters = null, $name = 'propel') { parent::initialize($parameters); if (!$this->hasParameter('datasource') && $this->hasParameter('name')) { $this->setParameter('datasource', $this->getParameter('name')); } elseif (!$this->hasParameter('datasource') && !empty($name)) { $this->setParameter('datasource', $name); } $this->addConfig(); $is_default = $this->getParameter('is_default', false); // first defined if none listed as default if ($is_default || 1 == count(self::$config['propel']['datasources'])) { $this->setDefaultConfig(); } Propel::setConfiguration(self::$config[$name]); if ($this->getParameter('pooling', false)) { Propel::enableInstancePooling(); } else { Propel::disableInstancePooling(); } if (!Propel::isInit()) { Propel::initialize(); } }
* This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; ob_start(); $plan = 14; $t = new lime_test($plan); if (!extension_loaded('SQLite') && !extension_loaded('pdo_SQLite')) { $t->skip('SQLite needed to run these tests', $plan); return; } // initialize the storage $database = new sfPDODatabase(array('dsn' => 'sqlite::memory:')); $connection = $database->getConnection(); $connection->exec('CREATE TABLE session (sess_id, sess_data, sess_time)'); ini_set('session.use_cookies', 0); $session_id = "1"; $storage = new sfPDOSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database)); $t->ok($storage instanceof sfStorage, 'sfPDOSessionStorage is an instance of sfStorage'); $t->ok($storage instanceof sfDatabaseSessionStorage, 'sfPDOSessionStorage is an instance of sfDatabaseSessionStorage'); // regenerate() $oldSessionData = 'foo:bar'; $storage->sessionWrite($session_id, $oldSessionData); $storage->regenerate(false); $newSessionData = 'foo:bar:baz'; $storage->sessionWrite(session_id(), $newSessionData); $t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id'); // checking if the old session record still exists
protected function execute($arguments = array(), $options = array()) { // initialize the database connection for RdvZ 1.x database $opt = array('dsn' => $arguments['dsn'], 'username' => $arguments['username'], 'password' => $arguments['password']); $d2 = new sfPDODatabase($opt); $rdvz1 = $d2->getConnection(); $this->logSection('rdvz', sprintf('Retrieving datas from RdvZ 1.x database "%s"', $opt['dsn'])); /** * This part is about fetching the datas from the old database * and formatting them before inserting into the new one. */ // initialize the database connection for RdvZ 2.0 database $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $res = $rdvz1->query('select * from meeting')->fetchAll(); foreach ($res as $meet) { // If the user doesn't exists in the new database, we have to retrieve his information // from the ldap server. if (sfConfig::get('app_authentication_type') == 'ldap') { $user = $this->getUserFromDatabase($meet['uid']); $user_id = $user->getId(); $user->free(); unset($user); } $meeting = new meeting(); $meeting->setHash($meet['mid']); $meeting->setTitle($meet['title']); $meeting->setDescription($meet['description']); $meeting->setUid($user_id); $meeting->setClosed($meet['closed']); $meeting->setDateDel($meet['date_del']); $meeting->setDateEnd($meet['date_end']); $meeting->setNotif($meet['notif'] == 'Y' ? 1 : 0); $meeting->save(null, false); $meeting_id = $meeting->getId(); $meeting->free(); unset($meeting); $res2 = $rdvz1->query("select * from meeting_date where mid = '" . $meet['mid'] . "'")->fetchAll(); foreach ($res2 as $date) { $meeting_date = new meeting_date(); $meeting_date->setMid($meeting_id); $meeting_date->setDate($date['date']); $meeting_date->setComment($date['comment']); $meeting_date->save(); $meeting_date_id = $meeting_date->getId(); $meeting_date->free(); unset($meeting_date); $res3 = $rdvz1->query("select * from meeting_poll where pollid = " . $date['pollid'])->fetchAll(); foreach ($res3 as $poll) { $meeting_poll = new meeting_poll(); $meeting_poll->setDateId($meeting_date_id); $meeting_poll->setPoll($poll['poll']); if ($poll['user_comment']) { $meeting_poll->setComment($poll['user_comment']); } if ($poll['uid'] != '') { $poll_user = $this->getUserFromDatabase($poll['uid']); $meeting_poll->setUid($poll_user->getId()); $poll_user->free(); unset($poll_user); } if ($poll['participant_name'] != '') { $meeting_poll->setParticipantName($poll['participant_name']); } $meeting_poll->save(); $meeting_poll->free(); unset($meeting_poll); } } } $this->logSection('rdvz', "The RdvZ 2.0 database is now filled with your former datas. You can now delete the old database."); }