示例#1
0
  /**
    * Function called when a meeting owner edits his meeting.
    * Due to the dynamic content generation, we have to compare
    * which dates and comments where here before and after the edit,
    * and the save or delete the records accordingly.
    *
    */
  public function processDatesAndCommentsForUpdate($dates_to_add,$dates_to_remove,$comments_to_add)
  {
    foreach($dates_to_add as $did => $val)
    {
      // For each new date, we have to know if it already exists in
      // the database.
      $d = Doctrine::getTable('meeting_date')->findWithMid($did,$this->getId()) ;
      if(is_null($d))
      {
        // If not, let's create it !
        $d = new meeting_date() ;
        $d->setDate(date_format(date_create($val),'Y-m-d')) ;

        if($comments_to_add[$did] != '')
          $d->setComment($comments_to_add[$did]) ;

        $d->setMid($this->getId()) ;
      }
      else
      {
        // It it does, we just change the date and the comment
        // if we need to.
        $d->setDate(date_format(date_create($val),'Y-m-d')) ;
        if(array_key_exists($did,$comments_to_add)) $d->setComment($comments_to_add[$did]) ;
      }

      $d->save() ;

      // Cancel the future operations !
      unset($dates_to_remove[$did]) ;
      unset($comments_to_add[$did]) ;
    }

    foreach($dates_to_remove as $did => $val)
    {
      // Removing the votes associated to the date before deleting
      // the date itself, otherwise a SQL error occurs.
      $polls = Doctrine::getTable('meeting_poll')->retrieveByDateId($did) ;
      foreach($polls as $p) 
        $p->delete() ;

      $d = Doctrine::getTable('meeting_date')->findWithMid($did, $this->getId()) ;
      $d->delete() ;
    }

    foreach($comments_to_add as $did => $comm)
    {
      // Update of a comment.
      $d = Doctrine::getTable('meeting_date')->find($did) ;
      $d->setComment($comments_to_add[$did]) ;
      $d->save() ;
    }
  }
 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.");
 }