public function preUp()
 {
     parent::preUp();
     // get a mapping of current ids for later use
     $conn = Doctrine_Manager::getInstance()->connection();
     $episodes = $conn->execute('SELECT * FROM project_episodes')->fetchAll();
     $mapping = array();
     $afterDelete = array();
     foreach ($episodes as $episode) {
         if (empty($mapping[$episode['project_id'] . '-' . $episode['number'] . '-' . $episode['version']])) {
             $mapping[$episode['project_id'] . '-' . $episode['number'] . '-' . $episode['version']] = $episode['id'];
         } else {
             $afterDelete[] = $episode['id'];
         }
     }
     foreach ($episodes as $episode) {
         $rel = new Projects_Model_EpisodeRelease();
         $rel->vcodec = $episode['vcodec'];
         $rel->acodec = $episode['acodec'];
         $rel->container = $episode['container'];
         $rel->crc = $episode['crc'];
         $rel->released_at = $episode['released_at'];
         $rel->updated_by = $episode['updated_by'];
         $rel->created_at = $episode['created_at'];
         $rel->updated_at = $episode['updated_at'];
         $rel->episode_id = $mapping[$episode['project_id'] . '-' . $episode['number'] . '-' . $episode['version']];
         $rel->save();
         $rel->free();
     }
     Doctrine_Query::create()->delete('Projects_Model_Episode')->whereIn('id', $afterDelete)->execute();
 }
Example #2
0
 public function addEpisodeReleaseAction()
 {
     $this->view->pageTitle = $this->translate('project_add-episode-release_headline');
     $this->view->form = new Projects_Form_EditProjectEpisodeRelease(array(), true);
     $id = $this->getRequest()->getParam('id');
     $table = Doctrine_Core::getTable('Projects_Model_Episode');
     $p = $table->findOneBy('id', $id ? $id : 0);
     if (!$p) {
         $this->session->message = $this->translate('project_episode_not_existent');
         $this->_helper->redirector->gotoSimple('episodes', 'admin', 'projects');
     }
     $req = $this->getRequest();
     if ($req->isPost()) {
         // there are profile updates
         if ($this->view->form->isValid($_POST)) {
             $values = $this->view->form->getValues();
             $er = new Projects_Model_EpisodeRelease();
             $er->updateRelease($values);
             $p->link('Projects_Model_EpisodeRelease', array($er->id), true);
             $this->session->message = $this->translate('project_admin_add-episode-release_success');
             $this->_helper->redirector->gotoSimple('editepisode', 'admin', 'projects', array('id' => $id));
         } else {
             $this->view->message = $this->translate('project_admin_add-episode-release_failed');
         }
     }
 }