/** * Imports and adds the items for the requested feed uri and adds them * to the account specified in $accountId if they do not already exist. * The account's lastUpdated property will also be set, and the item lists * cache will be cleaned, if feed items have been actually added. * * * @param integer $accountId * @param integer $userId * @param boolean $useReaderCache * @param boolean $useConditionalGet * * @return array Returns an array with the recently added * Conjoon_Modules_Groupware_Feeds_Item_Dto * * @throws Exception */ public function importAndAddFeedItems($accountId, $userId, $useReaderCache = false, $useConditionalGet = false) { $accountId = (int) $accountId; $userId = (int) $userId; if ($accountId <= 0 || $userId <= 0) { throw new InvalidArgumentException("Invalid argument supplied, accountId was \"{$accountId}\", " . "userId was \"{$userId}\""); } $accountDto = $this->_getAccountFacade()->getAccount($accountId, $userId); $uri = $accountDto->uri; $requestTimeout = $accountDto->requestTimeout; /** * @see Conjoon_Modules_Groupware_Feeds_ImportHelper */ require_once 'Conjoon/Modules/Groupware/Feeds/ImportHelper.php'; // get the feeds metadata try { $import = Conjoon_Modules_Groupware_Feeds_ImportHelper::importFeedItems($uri, $requestTimeout, $useReaderCache, $useConditionalGet); } catch (Exception $e) { Conjoon_Log::log(get_class($this) . "::importAndAddFeedItems could not import " . "feed items from {$uri}: \"" . get_class($e) . "\" - \"" . $e->getMessage() . "\"", Zend_Log::INFO); // return an empty array, do not delete cache for the account and do not // update last_updated timestamp! return array(); } /** * @see Conjoon_Modules_Groupware_Feeds_Item_Filter_Item */ require_once 'Conjoon/Modules/Groupware/Feeds/Item/Filter/Item.php'; $filter = new Conjoon_Modules_Groupware_Feeds_Item_Filter_Item(array(), Conjoon_Filter_Input::CONTEXT_CREATE); $itemResponseFilter = new Conjoon_Modules_Groupware_Feeds_Item_Filter_Item(array(), Conjoon_Filter_Input::CONTEXT_RESPONSE); /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; /** * @see Conjoon_BeanContext_Inspector */ require_once 'Conjoon/BeanContext/Inspector.php'; $added = array(); $cCache = false; foreach ($import as $item) { $normalized = Conjoon_Modules_Groupware_Feeds_ImportHelper::normalizeFeedItem($item); $normalized['groupwareFeedsAccountsId'] = $accountId; $filter->setData($normalized); try { $fillIn = $filter->getProcessedData(); } catch (Zend_Filter_Exception $e) { /** * @see Conjoon_Error */ require_once 'Conjoon/Error.php'; Conjoon_Log::log(Conjoon_Error::fromFilter($filter, $e), Zend_Log::ERR); continue; } $dtoData = $fillIn; Conjoon_Util_Array::underscoreKeys($fillIn); $isAdded = $this->_addItemIfNotExists($fillIn, $accountId, false); if ($isAdded > 0) { $cCache = true; $dtoData['id'] = $isAdded; $dtoData['name'] = $accountDto->name; $itemResponseFilter->setData($dtoData); $dtoData = $itemResponseFilter->getProcessedData(); $added[] = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Feeds_Item', $dtoData)->getDto(); } } if ($cCache) { $this->_removeListCacheForAccountIds(array($accountId)); } $this->_getAccountFacade()->setLastUpdated(array($accountId), time()); return $added; }
/** * Checks wether the given uri points to a valid feed container. * */ public function isFeedAddressValidAction() { /*@REMOVE@*/ if (!$this->_helper->connectionCheck()) { /** * @see Conjoon_Error_Factory */ require_once 'Conjoon/Error/Factory.php'; $this->view->success = false; $this->view->error = null; return; } /*@REMOVE@*/ /** * @see Conjoon_Modules_Groupware_Feeds_ImportHelper */ require_once 'Conjoon/Modules/Groupware/Feeds/ImportHelper.php'; $success = Conjoon_Modules_Groupware_Feeds_ImportHelper::isFeedAddressValid($this->_request->getParam('uri')); $this->view->success = $success; $this->view->error = null; }
private static function _processResources(array $config) { if (self::$_lock) { /** * @see Conjoon_Log */ require_once 'Conjoon/Log.php'; Conjoon_Log::log("Conjoon_Modules_Groupware_Feeds_ImportHelper::_processResources " . "- possible race condition", Zend_Log::INFO); } self::$_lock = true; $uri = $config['uri']; $requestTimeout = $config['requestTimeout']; $useCache = $config['useCache']; $useConditionalGet = $config['useConditionalGet']; $callback = $config['callback']; /** * @see Zend_Feed_Reader */ require_once 'Zend/Feed/Reader.php'; if ($useCache !== false) { // set the reader's cache here /** * @see Conjoon_Cache_Factory */ require_once 'Conjoon/Cache/Factory.php'; /** * @see Conjoon_Keys */ require_once 'Conjoon/Keys.php'; $frCache = Conjoon_Cache_Factory::getCache(Conjoon_Keys::CACHE_FEED_READER, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray()); if ($frCache) { Zend_Feed_Reader::setCache($frCache); if ($useConditionalGet !== false) { Zend_Feed_Reader::useHttpConditionalGet(); } } } Zend_Feed_Reader::getHttpClient()->setConfig(array('timeout' => $requestTimeout)); $result = self::$callback($uri); Zend_Feed_Reader::reset(); self::$_lock = false; return $result; }
/** * Adds a feed account to the data storage for the specified * user in $userId. * * Fields required in $data: * - deleteInterval * - name * - requestTimeout * - updateInterval * - uri * * @param Array $data * @param intteger $userId * * @throws Exception */ public function addAccountAndImport(array $data, $userId) { $userId = (int) $userId; if ($userId <= 0) { throw new InvalidArgumentException("Invalid argument supplied, userId was \"{$userId}\""); } /** * @see Conjoon_Modules_Groupware_Feeds_ImportHelper */ require_once 'Conjoon/Modules/Groupware/Feeds/ImportHelper.php'; $data['lastUpdated'] = time(); // get the feeds metadata $metaData = Conjoon_Modules_Groupware_Feeds_ImportHelper::getFeedMetaData($data['uri'], $data['requestTimeout'], true, true); /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; Conjoon_Util_Array::applyIf($data, $metaData); $addedAcount = $this->addAccount($data, $userId, true); // something failed. Return. if ($addedAcount == null) { return array(); } // get the feed items now and insert them! $items = $this->_getItemFacade()->importAndAddFeedItems($addedAcount->id, $userId, true, false); return array('account' => $addedAcount, 'items' => $items); }