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."); }