public function delete(Application_Model_YoutubeCategory $model)
 {
     if ($model->getId() !== null) {
         $where = $this->getDbTable()->getAdapter()->quoteInto("id = ?", $model->getId());
         $this->getDbTable()->delete($where);
     }
 }
Esempio n. 2
0
 /**
  * Restore backupped videos 
  * This is not a trigger of plugin API. It's called by Backupper plugin
  */
 function restoreItems($items)
 {
     //return parent::restoreItems($items);
     // cleaning up all videos
     $models = Application_Model_YoutubeVideosMapper::i()->fetchAll();
     foreach ($models as $model) {
         Application_Model_YoutubeVideosMapper::i()->delete($model);
     }
     // cleaning up all categories
     $models = Application_Model_YoutubeCategoriesMapper::i()->fetchAll();
     foreach ($models as $model) {
         Application_Model_YoutubeCategoriesMapper::i()->delete($model);
     }
     // cleaning up all accounts
     $models = Application_Model_YoutubeAccountsMapper::i()->fetchAll();
     foreach ($models as $model) {
         Application_Model_YoutubeAccountsMapper::i()->delete($model);
     }
     $mapOldNewCategoryId = array();
     foreach (@$items['categories'] as $modelInfo) {
         $model = new Application_Model_YoutubeCategory();
         $model->setLabel(@$modelInfo['label'])->setThumbnail(@$modelInfo['thumbnail'] != '' ? @$modelInfo['thumbnail'] : null);
         // i don't set id, or db adapter will try to update old data that i cleaned
         Application_Model_YoutubeCategoriesMapper::i()->save($model);
         $mapOldNewCategoryId[@$modelInfo['id']] = $model->getId();
     }
     foreach (@$items['videos'] as $modelInfo) {
         $model = new Application_Model_YoutubeVideo();
         $model->setIdYoutube(@$modelInfo['idYoutube'])->setDescription(@$modelInfo['description'])->setIdCategory(@$mapOldNewCategoryId[$modelInfo['idCategory']])->setLabel(@$modelInfo['label'])->setThumbnail(@$modelInfo['thumbnail'] != '' ? @$modelInfo['thumbnail'] : null);
         // i don't set id, or db adapter will try to update old data that i cleaned
         Application_Model_YoutubeVideosMapper::i()->save($model);
     }
     foreach (@$items['accounts'] as $modelInfo) {
         $model = new Application_Model_YoutubeAccount();
         $model->setLabel(@$modelInfo['label'])->setThumbnail(@$modelInfo['thumbnail'] != '' ? @$modelInfo['thumbnail'] : null);
         // i don't set id, or db adapter will try to update old data that i cleaned
         Application_Model_YoutubeAccountsMapper::i()->save($model);
     }
     return implode('<br/>', array(X_Env::_('p_youtube_backupper_restoredcategories') . ": " . count($items['categories']), X_Env::_('p_youtube_backupper_restoredvideos') . ": " . count($items['videos']), X_Env::_('p_youtube_backupper_restoredaccounts') . ": " . count($items['accounts'])));
 }