/** * cronjob silent update * * @return void */ public function silentAction() { // logging $logger = Zend_Registry::get('logger'); $logger->log('start silent update', Zend_Log::DEBUG); // update feeds $updater = Zend_Controller_Action_HelperBroker::getStaticHelper('updater'); // get all feeds $feedModel = new application_models_feeds(); $feeds = $feedModel->fetchAll(); $logger->log('update ' . $feeds->count() . ' feeds', Zend_Log::DEBUG); $i = 1; foreach ($feeds as $feed) { $logger->log('#' . $i++ . ' feed update', Zend_Log::DEBUG); $updater->feed($feed); } // set last update $settingsModel = new application_models_settings(); $settingsModel->write('lastrefresh', Zend_Date::now()->get(Zend_Date::TIMESTAMP)); // delete orphaned thumbnails $updater->cleanupThumbnails(); $logger->log('delete orphaned thumbnails', Zend_Log::DEBUG); // optimize database application_models_base::optimizeDatabase(); $logger->log('database successfully optimized', Zend_Log::DEBUG); $logger->log('finished silent update', Zend_Log::DEBUG); }
/** * checks whether a feed exists or not * * @return boolean * @param int $value feed id */ public function isValid($value) { $feeds = new application_models_feeds(); if ($feeds->fetchAll($feeds->select()->where("id=?", $value))->count() == 0) { $this->_error(application_validate_feedid::NOT_EXISTS); return false; } return true; }
/** * checks whether a feed entry already exists or not * * @return boolean * @param string $value url */ public function isValid($value) { $feeds = new application_models_feeds(); $select = $feeds->select()->where("url=?", $value)->where("source=?", $this->source); if ($this->id) { $select->where("id!=?", $this->id); } if ($feeds->fetchAll($select)->count() > 0) { $this->_error(application_validate_duplicatefeed::ALREADY_EXISTS); return false; } return true; }
/** * test the fix position routine * setUp will insert feeds with position 0 and 2 * fixPosition corrects to 0 and 1 */ public function testFixPositions() { $this->model->fixPositions($this->model->find(1)->current()); $feedModel = new application_models_feeds(); $positions = $feedModel->fetchAll($feedModel->select()->order('position ASC')->from($feedModel, 'position'))->toArray(); $expected = array(array('position' => 0), array('position' => 1)); $this->assertEquals($expected, $positions); }
/** * return feed positions * * @return array of feed positions */ public function getFeedsIconPosition() { if ($this->iconPositions == false) { $feedsModel = new application_models_feeds(); $feeds = $feedsModel->fetchAll($feedsModel->select()->order('id ASC')); $feedPositions = array(); $count = 0; foreach ($feeds as $feed) { $feedPositions[$feed->id] = $count++; } $this->iconPositions = $feedPositions; } return $this->iconPositions; }
/** * insert given feeds * * @return void * @param int $category id * @param array $feeds as array */ protected function insertFeeds($category, $feeds) { $feedsModel = new application_models_feeds(); // insert unkown feeds foreach ($feeds as $feed) { // search existing feed $moreFeeds = $feedsModel->fetchAll($feedsModel->select()->where($feedsModel->getAdapter()->quoteInto('url=?', trim($feed['link'])))); // if feed doesn't exists if ($moreFeeds->count() == 0) { $feedsModel->add(array('name' => trim($feed['title']), 'url' => trim($feed['link']), 'category' => $category, 'priority' => 1, 'source' => 'plugins_rss_feed')); } } // fix positions $categoriesModel = new application_models_categories(); $categoriesModel->fixPositions($categoriesModel->find($category)->current()); }