/** * Fetches subscribed feeds and imports them */ public function _on_execute() { debug_add('_on_execute called'); if (!midcom::get('auth')->request_sudo('net.nemein.rss')) { $msg = "Could not get sudo, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); return; } midcom::get()->disable_limits(); $qb = net_nemein_rss_feed_dba::new_query_builder(); // Process lang0 subscriptions first $qb->add_order('itemlang', 'ASC'); $feeds = $qb->execute(); foreach ($feeds as $feed) { try { $node = new midcom_db_topic($feed->node); } catch (midcom_error $e) { debug_add("Node #{$feed->node} does not exist, skipping feed #{$feed->id}", MIDCOM_LOG_ERROR); continue; } debug_add("Fetching {$feed->url}...", MIDCOM_LOG_INFO); $fetcher = new net_nemein_rss_fetch($feed); $items = $fetcher->import(); debug_add("Imported " . count($items) . " items, set feed refresh time to " . strftime('%x %X', $feed->latestfetch), MIDCOM_LOG_INFO); } midcom::get('auth')->drop_sudo(); debug_add('Done'); return; }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_fetch($handler_id, array $args, array &$data) { $this->_topic->require_do('midgard:create'); midcom::get('cache')->content->enable_live_mode(); //Disable limits @ini_set('memory_limit', $GLOBALS['midcom_config']['midcom_max_memory']); @ini_set('max_execution_time', 0); if ($handler_id == 'feeds_fetch') { $data['feed'] = new net_nemein_rss_feed_dba($args[0]); $fetcher = new net_nemein_rss_fetch($data['feed']); $data['items'] = $fetcher->import(); midcom::get('metadata')->set_request_metadata($data['feed']->metadata->revised, $data['feed']->guid); $this->bind_view_to_object($data['feed']); } else { $data['items'] = array(); $qb = net_nemein_rss_feed_dba::new_query_builder(); $qb->add_order('title'); $qb->add_constraint('node', '=', $this->_topic->id); $data['feeds'] = $qb->execute(); foreach ($data['feeds'] as $feed) { $fetcher = new net_nemein_rss_fetch($feed); $items = $fetcher->import(); $data['items'] = array_merge($data['items'], $items); } } $this->_update_breadcrumb_line($handler_id); }