/** * action reinit * * @param string $screenName * @param integer $storagePid * @param string $oauthAccessToken * @param string $oauthAccessTokenSecret * @param string $consumerKey * @param string $consumerKeySecret * @return void */ public function reinitAction($screenName, $storagePid, $oauthAccessToken, $oauthAccessTokenSecret, $consumerKey, $consumerKeySecret) { if ($screenName != "") { $this->twitterRepository->removeByPageId($screenName, $storagePid); $rawFeed = self::twitter($oauthAccessToken, $oauthAccessTokenSecret, $consumerKey, $consumerKeySecret, $screenName, 'init'); $posts = array(); $postIds = array(); foreach ($rawFeed as $item) { if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['postId'] = $postId; $item['screen_name'] = $screenName; $item['pid'] = $storagePid; $post = self::twitterPost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { $insertCnt = 0; foreach ($posts as $post) { $twitterPost = new \TYPO3\MooxSocial\Domain\Model\Twitter(); $twitterPost->setPid($post['pid']); $twitterPost->setCreated($post['created']); $twitterPost->setUpdated($post['updated']); $twitterPost->setModel("twitter"); $twitterPost->setType($post['type']); $twitterPost->setStatusType($post['statusType']); $twitterPost->setPage($post['page']); $twitterPost->setAction($post['action']); $twitterPost->setTitle($post['title']); $twitterPost->setSummary($post['summary']); $twitterPost->setText($post['text']); $twitterPost->setAuthor($post['author']); $twitterPost->setAuthorId($post['authorId']); $twitterPost->setDescription($post['description']); $twitterPost->setCaption($post['caption']); $twitterPost->setUrl($post['url']); $twitterPost->setLinkName($post['linkName']); $twitterPost->setLinkUrl($post['linkUrl']); $twitterPost->setImageUrl($post['imageUrl']); $twitterPost->setImageEmbedcode($post['imageEmbedcode']); $twitterPost->setVideoUrl($post['videoUrl']); $twitterPost->setVideoEmbedcode($post['videoEmbedcode']); $twitterPost->setSharedUrl($post['sharedUrl']); $twitterPost->setSharedTitle($post['sharedTitle']); $twitterPost->setSharedDescription($post['sharedDescription']); $twitterPost->setSharedCaption($post['sharedCaption']); $twitterPost->setLikes($post['likes']); $twitterPost->setShares($post['shares']); $twitterPost->setComments($post['comments']); $twitterPost->setApiUid($post['apiUid']); $twitterPost->setApiHash($post['apiHash']); $this->twitterRepository->add($twitterPost); $insertCnt++; } $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll(); $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $insertCnt . " neue Tweets geladen", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); } } $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:moox_social/Resources/Private/Language/locallang.xlf:overview.twitter.listing.reinit.success', $this->extensionName), '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); $this->redirect('index'); }
/** * Works through the indexing queue and indexes the queued items into Solr. * * @return boolean Returns TRUE on success, FALSE if no items were indexed or none were found. * @see typo3/sysext/scheduler/tx_scheduler_Task#execute() */ public function execute() { // Get the extensions's configuration $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['moox_social']); if ($extConf['debugEmailSenderName'] == "") { $extConf['debugEmailSenderName'] = $extConf['debugEmailSenderAddress']; } if ($this->email == "") { $this->email = $extConf['debugEmailReceiverAddress']; } $executionSucceeded = FALSE; if (!$this->pid) { $this->pid = 0; } if ($this->oauthAccessToken != "" && $this->oauthAccessTokenSecret != "" && $this->consumerKey != "" && $this->consumerKeySecret != "" && $this->screenName != "") { $execution = $this->getExecution(); $interval = $execution->getInterval(); $time = time(); $to = $time; $from = $time - $interval - $this->intervalBuffer; try { $rawFeed = \TYPO3\MooxSocial\Controller\TwitterController::twitter($this->oauthAccessToken, $this->oauthAccessTokenSecret, $this->consumerKey, $this->consumerKeySecret, $this->screenName, ''); $executionSucceeded = TRUE; } catch (\Exception $e) { $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.api_execution_error') . " [" . $e->getMessage() . "]", '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); if ($this->email && $extConf['debugEmailSenderAddress']) { $lockfile = $_SERVER['DOCUMENT_ROOT'] . "/typo3temp/.lock-email-task-" . md5($this->oauthAccessToken . $this->oauthAccessTokenSecret . $this->consumerKey . $this->consumerKeySecret . $this->screenName); if (file_exists($lockfile)) { $lockfiletime = filemtime($lockfile); if ($lockfiletime < time() - 86400) { unlink($lockfile); } } if (!file_exists($lockfile)) { $message = (new \TYPO3\CMS\Core\Mail\MailMessage())->setFrom(array($extConf['debugEmailSenderAddress'] => $extConf['debugEmailSenderName']))->setTo(array($this->email => $this->email))->setSubject($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.api_error_mailsubject'))->setBody('ERROR: while requesting [oauth access token: ' . $this->oauthAccessToken . ' | oauth access token secret: ' . $this->oauthAccessTokenSecret . ' | consumer key: ' . $this->consumerKey . ' | consumer key secret: ' . $this->consumerKeySecret . ' | screen_name: ' . $this->screenName . "]"); $message->send(); touch($lockfile); } } } $posts = array(); $postIds = array(); foreach ($rawFeed as $item) { if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['postId'] = $postId; $item['screen_name'] = $item['user']['screen_name']; $item['pid'] = $this->pid; $post = \TYPO3\MooxSocial\Controller\TwitterController::twitterPost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $twitterRepository = $objectManager->get('\\TYPO3\\MooxSocial\\Domain\\Repository\\TwitterRepository'); $insertCnt = 0; $updateCnt = 0; foreach ($posts as $post) { $twitterPost = $twitterRepository->findOneByApiUid($post['apiUid'], $this->pid); if (!$twitterPost instanceof \TYPO3\MooxSocial\Domain\Model\Twitter) { $twitterPost = new \TYPO3\MooxSocial\Domain\Model\Twitter(); $action = "insert"; } if ($action == "insert") { $twitterPost->setPid($post['pid']); $twitterPost->setCreated($post['created']); } $twitterPost->setUpdated($post['updated']); $twitterPost->setType($post['type']); $twitterPost->setStatusType($post['statusType']); if ($action == "insert") { $twitterPost->setPage($post['page']); $twitterPost->setModel("twitter"); } $twitterPost->setAction($post['action']); $twitterPost->setTitle($post['title']); $twitterPost->setSummary($post['summary']); $twitterPost->setText($post['text']); $twitterPost->setAuthor($post['author']); $twitterPost->setAuthorId($post['authorId']); $twitterPost->setDescription($post['description']); $twitterPost->setCaption($post['caption']); $twitterPost->setUrl($post['url']); $twitterPost->setLinkName($post['linkName']); $twitterPost->setLinkUrl($post['linkUrl']); $twitterPost->setImageUrl($post['imageUrl']); $twitterPost->setImageEmbedcode($post['imageEmbedcode']); $twitterPost->setVideoUrl($post['videoUrl']); $twitterPost->setVideoEmbedcode($post['videoEmbedcode']); $twitterPost->setSharedUrl($post['sharedUrl']); $twitterPost->setSharedTitle($post['sharedTitle']); $twitterPost->setSharedDescription($post['sharedDescription']); $twitterPost->setSharedCaption($post['sharedCaption']); $twitterPost->setLikes($post['likes']); $twitterPost->setShares($post['shares']); $twitterPost->setComments($post['comments']); if ($action == "insert") { $twitterPost->setApiUid($post['apiUid']); } $twitterPost->setApiHash($post['apiHash']); if ($action == "insert") { $twitterRepository->add($twitterPost); $insertCnt++; } else { $twitterRepository->update($twitterPost); $updateCnt++; } } $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll(); $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $insertCnt . " neue Tweets geladen | " . $updateCnt . " bestehende Tweets aktualisiert", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); } else { $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', "Keine neuen oder aktualisierten Tweets gefunden", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); } } return $executionSucceeded; }
/** * Finds all posts by given request settings directly from Twitter api * * @param array $settings settings The settings * @return Tx_Extbase_Persistence_QueryResultInterface The posts */ public function requestAllBySettings($settings) { $result = array(); $postIds = array(); if (!$settings['offset']) { $settings['offset'] = 0; } $rawFeed = \TYPO3\MooxSocial\Controller\TwitterController::twitter($settings['api_oauth_access_token'], $settings['api_oauth_access_token_secret'], $settings['api_consumer_key'], $settings['api_consumer_key_secret'], $settings['api_screen_name']); $posts = array(); foreach ($rawFeed as $item) { if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['postId'] = $postId; $item['pageId'] = $screenName; $item['pid'] = $storagePid; $post = \TYPO3\MooxSocial\Controller\TwitterController::twitterPost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { foreach ($posts as $post) { $twitterPost = new \TYPO3\MooxSocial\Domain\Model\Twitter(); $twitterPost->setPid($post['pid']); $twitterPost->setCreated($post['created']); $twitterPost->setUpdated($post['updated']); $twitterPost->setType($post['type']); $twitterPost->setStatusType($post['statusType']); $twitterPost->setPage($post['page']); $twitterPost->setAction($post['action']); $twitterPost->setTitle($post['title']); $twitterPost->setSummary($post['summary']); $twitterPost->setText($post['text']); $twitterPost->setAuthor($post['author']); $twitterPost->setAuthorId($post['authorId']); $twitterPost->setDescription($post['description']); $twitterPost->setCaption($post['caption']); $twitterPost->setUrl($post['url']); $twitterPost->setLinkName($post['linkName']); $twitterPost->setLinkUrl($post['linkUrl']); $twitterPost->setImageUrl($post['imageUrl']); $twitterPost->setImageEmbedcode($post['imageEmbedcode']); $twitterPost->setVideoUrl($post['videoUrl']); $twitterPost->setVideoEmbedcode($post['videoEmbedcode']); $twitterPost->setSharedUrl($post['sharedUrl']); $twitterPost->setSharedTitle($post['sharedTitle']); $twitterPost->setSharedDescription($post['sharedDescription']); $twitterPost->setSharedCaption($post['sharedCaption']); $twitterPost->setLikes($post['likes']); $twitterPost->setShares($post['shares']); $twitterPost->setComments($post['comments']); $twitterPost->setApiUid($post['apiUid']); $twitterPost->setApiHash($post['apiHash']); $result[] = $twitterPost; } } return $result; }