/** * Restore backupped videos * This is not a trigger of plugin API. It's called by Backupper plugin */ function restoreItems($items) { //return parent::restoreItems($items); $models = Application_Model_VideosMapper::i()->fetchAll(); // cleaning up all shares foreach ($models as $model) { Application_Model_VideosMapper::i()->delete($model); } foreach (@$items['videos'] as $modelInfo) { $model = new Application_Model_Video(); $model->setIdVideo(@$modelInfo['idVideo'])->setDescription(@$modelInfo['description'])->setCategory(@$modelInfo['category'])->setTitle(@$modelInfo['title'])->setHoster(@$modelInfo['hoster'])->setThumbnail(@$modelInfo['thumbnail']); // i don't set id, or db adapter will try to update old data that i cleaned Application_Model_VideosMapper::i()->save($model); } return X_Env::_('p_onlinelibrary_backupper_restoreditems', count($items['videos'])); }
public function delete(Application_Model_Video $model) { $this->getDbTable()->delete(array('id = ?' => $model->getId())); }
public function addAction() { $csrf = new Zend_Form_Element_Hash('csrf', array('salt' => __CLASS__)); $validCheck = $csrf->isValid($this->getRequest()->getParam('csrf', false)); $csrf->initCsrfToken(); $hash = $csrf->getHash(); $return = array('success' => true, 'api' => array('resolver' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'resolver', 'csrf' => $hash)), 'adder' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'add', 'csrf' => $hash)), 'bookmark' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'bookmark', 'csrf' => $hash))), 'links' => array()); if ($validCheck) { $links = $this->getRequest()->getParam("links", array()); $category = $this->getRequest()->getParam("category", false); $added = 0; $ignored = 0; $total = count($links); if ($category) { $hosterHelper = X_VlcShares_Plugins::helpers()->hoster(); foreach ($links as $link) { $href = isset($link['href']) ? $link['href'] : false; $title = isset($link['title']) ? $link['title'] : false; $description = isset($link['description']) ? $link['description'] : false; $thumbnail = isset($link['thumbnail']) ? $link['thumbnail'] : false; if (!$href || !$title) { $ignored++; continue; } try { $hoster = $hosterHelper->findHoster($href); $id = $hoster->getResourceId($href); $video = new Application_Model_Video(); $video->setHoster($hoster->getId())->setIdVideo($id)->setTitle($title)->setCategory($category); if ($thumbnail) { $video->setThumbnail($thumbnail); } if ($description) { $video->setDescription($description); } try { Application_Model_VideosMapper::i()->save($video); $added++; } catch (Exception $e) { $ignored++; } } catch (Exception $e) { X_Debug::w("No hoster found: {{$e->getMessage()}}"); $ignored++; } } $return['links'] = array('total' => $total, 'ignored' => $ignored, 'added' => $added); } else { X_Debug::e("No category selected"); $return['success'] = false; } } else { X_Debug::e("Invalid CSRF"); $return['success'] = false; } $this->_helper->json($return, true, false); }