* (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
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id));
 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.");
 }