/** * 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']))); }
function svideoAction() { /* @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); if (!$request->isPost()) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_invalidrequest'), 'type' => 'error')); $this->_helper->redirector('index', 'youtube'); } try { $form = new Application_Form_YoutubeVideo(); } catch (Exception $e) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_formerror') . ": {$e->getMessage()}", 'type' => 'error')); $this->_helper->redirector('index', 'youtube'); } $post = $request->getPost(); X_Debug::i("Post = '" . var_export($post, true) . "'"); $valid = $form->isValid($post); if ($valid != true) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_invaliddata'), 'type' => 'error')); //$this->_helper->flashMessenger(array('text' => '<pre>'.var_export($form, true).'</pre>', 'type' => 'error')); foreach ($form->getErrorMessages() as $error) { $this->_helper->flashMessenger(array('text' => $error, 'type' => 'error')); } $this->_helper->redirector('index', 'youtube'); } try { $idYoutube = $form->getValue('idYoutube'); if (X_Env::startWith($idYoutube, 'http')) { $start = strpos($idYoutube, 'v='); $end = strpos($idYoutube, '&', $start); if ($end !== false) { $idYoutube = substr($idYoutube, $start + 2, $end - $start - 2); } else { $idYoutube = substr($idYoutube, $start + 2); } X_Debug::i("Found ID: {$idYoutube}"); } $idCategory = $form->getValue('idCategory'); // check if $accountName is a valid account and if it has a thumbnail image /* @var $helper X_VlcShares_Plugins_Helper_Youtube */ $helper = X_VlcShares_Plugins::helpers('youtube'); $videoEntry = $helper->getVideo($idYoutube); $thumb = $videoEntry->getVideoThumbnails(); $thumb = @$thumb[0]['url']; $thumb = str_replace('default', '0', $thumb); $video = new Application_Model_YoutubeVideo(); $video->setLabel($videoEntry->getVideoTitle())->setDescription($videoEntry->getVideoDescription())->setIdYoutube($idYoutube)->setIdCategory($idCategory)->setThumbnail($thumb); Application_Model_YoutubeVideosMapper::i()->save($video); $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_completed_video'), 'type' => 'info')); $this->_helper->redirector('category', 'youtube', 'default', array('idCategory' => $idCategory)); } catch (Zend_Gdata_App_HttpException $e) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_err_invalidvideo'), 'type' => 'error')); $this->_helper->redirector('index', 'youtube'); } catch (Exception $e) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_err_dberror') . ": {$e->getMessage()}", 'type' => 'error')); $this->_helper->redirector('index', 'youtube'); } }
public function delete(Application_Model_YoutubeVideo $model) { if ($model->getId() !== null) { $where = $this->getDbTable()->getAdapter()->quoteInto("id = ?", $model->getId()); $this->getDbTable()->delete($where); } }