public function delete(Application_Model_YoutubeAccount $model) { if ($model->getId() !== null) { $where = $this->getDbTable()->getAdapter()->quoteInto("id = ?", $model->getId()); $this->getDbTable()->delete($where); } }
function saccountAction() { /* @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_YoutubeAccount(); } 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 { $accountName = $form->getValue('label'); // 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'); $accountProfile = $helper->getAccountInfo($accountName); $thumb = $accountProfile->getThumbnail()->getUrl(); $account = new Application_Model_YoutubeAccount(); $account->setLabel($accountName)->setThumbnail($thumb); Application_Model_YoutubeAccountsMapper::i()->save($account); $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_completed_account'), 'type' => 'info')); $this->_helper->redirector('index', 'youtube'); } catch (Zend_Gdata_App_HttpException $e) { $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_err_invalidaccount'), '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'); } }
/** * 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']))); }