/** * Finds all posts by given request settings directly from Youtube 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\YoutubeController::youtube($settings['api_youtube_channel']); $posts = array(); foreach ($rawFeed as $item) { if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['id'] = $postId; $item['youtubeChannel'] = $youtubeChannel; $item['pid'] = $storagePid; $post = \TYPO3\MooxSocial\Controller\YoutubeController::youtubePost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { foreach ($posts as $post) { $youtubePost = new \TYPO3\MooxSocial\Domain\Model\Youtube(); $youtubePost->setPid($post['pid']); $youtubePost->setCreated($post['created']); $youtubePost->setUpdated($post['updated']); $youtubePost->setType($post['type']); $youtubePost->setStatusType($post['statusType']); $youtubePost->setPage($post['page']); $youtubePost->setAction($post['action']); $youtubePost->setTitle($post['title']); $youtubePost->setSummary($post['summary']); $youtubePost->setText($post['text']); $youtubePost->setAuthor($post['author']); $youtubePost->setAuthorId($post['authorId']); $youtubePost->setDescription($post['description']); $youtubePost->setCaption($post['caption']); $youtubePost->setUrl($post['url']); $youtubePost->setLinkName($post['linkName']); $youtubePost->setLinkUrl($post['linkUrl']); $youtubePost->setImageUrl($post['imageUrl']); $youtubePost->setImageEmbedcode($post['imageEmbedcode']); $youtubePost->setVideoUrl($post['videoUrl']); $youtubePost->setVideoEmbedcode($post['videoEmbedcode']); $youtubePost->setSharedUrl($post['sharedUrl']); $youtubePost->setSharedTitle($post['sharedTitle']); $youtubePost->setSharedDescription($post['sharedDescription']); $youtubePost->setSharedCaption($post['sharedCaption']); $youtubePost->setLikes($post['likes']); $youtubePost->setShares($post['shares']); $youtubePost->setComments($post['comments']); $youtubePost->setApiUid($post['apiUid']); $youtubePost->setApiHash($post['apiHash']); $result[] = $youtubePost; } } return $result; }
/** * 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->youtubeChannel != "") { $execution = $this->getExecution(); $interval = $execution->getInterval(); $time = time(); $to = $time; $from = $time - $interval - $this->intervalBuffer; try { $rawFeed = \TYPO3\MooxSocial\Controller\YoutubeController::youtube($this->youtubeChannel); /*print "<pre>"; print_r($rawFeed); print "</pre>"; exit();*/ $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_youtubegettask.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->youtubeChannel); 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_youtubegettask.api_error_mailsubject'))->setBody('ERROR: while requesting [youtube channel: ' . $this->youtubeChannel . "]"); $message->send(); touch($lockfile); } } } $posts = array(); $postIds = array(); foreach ($rawFeed as $item) { //if(1 || !in_array($item['type'],array("status"))){ //if(!in_array($item['id'],$postIds) && $item['status_type']!=""){ if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['id'] = $postId; $item['youtubeChannel'] = $this->youtubeChannel; $item['pid'] = $this->pid; $post = \TYPO3\MooxSocial\Controller\YoutubeController::youtubePost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $youtubeRepository = $objectManager->get('\\TYPO3\\MooxSocial\\Domain\\Repository\\YoutubeRepository'); $insertCnt = 0; $updateCnt = 0; foreach ($posts as $post) { $youtubePost = $youtubeRepository->findOneByApiUid($post['apiUid'], $this->pid); if (!$youtubePost instanceof \TYPO3\MooxSocial\Domain\Model\Youtube) { $youtubePost = new \TYPO3\MooxSocial\Domain\Model\Youtube(); $action = "insert"; } if ($action == "insert") { $youtubePost->setPid($post['pid']); $youtubePost->setCreated($post['created']); } $youtubePost->setUpdated($post['updated']); $youtubePost->setType($post['type']); $youtubePost->setStatusType($post['statusType']); if ($action == "insert") { $youtubePost->setPage($post['page']); $youtubePost->setModel("youtube"); } $youtubePost->setAction($post['action']); $youtubePost->setTitle($post['title']); $youtubePost->setSummary($post['summary']); $youtubePost->setText($post['text']); $youtubePost->setAuthor($post['author']); $youtubePost->setAuthorId($post['authorId']); $youtubePost->setDescription($post['description']); $youtubePost->setCaption($post['caption']); $youtubePost->setUrl($post['url']); $youtubePost->setLinkName($post['linkName']); $youtubePost->setLinkUrl($post['linkUrl']); $youtubePost->setImageUrl($post['imageUrl']); $youtubePost->setImageEmbedcode($post['imageEmbedcode']); $youtubePost->setVideoUrl($post['videoUrl']); $youtubePost->setVideoEmbedcode($post['videoEmbedcode']); $youtubePost->setSharedUrl($post['sharedUrl']); $youtubePost->setSharedTitle($post['sharedTitle']); $youtubePost->setSharedDescription($post['sharedDescription']); $youtubePost->setSharedCaption($post['sharedCaption']); $youtubePost->setLikes($post['likes']); $youtubePost->setShares($post['shares']); $youtubePost->setComments($post['comments']); if ($action == "insert") { $youtubePost->setApiUid($post['apiUid']); } $youtubePost->setApiHash($post['apiHash']); if ($action == "insert") { $youtubeRepository->add($youtubePost); $insertCnt++; } else { $youtubeRepository->update($youtubePost); $updateCnt++; } } $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll(); $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $insertCnt . " neue Videos geladen | " . $updateCnt . " bestehende Videos 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 Videos gefunden", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); } } return $executionSucceeded; }
/** * action reinit * * @param string $youtubeChannel * @param integer $storagePid * @return void */ public function reinitAction($youtubeChannel, $storagePid) { if ($youtubeChannel != "") { $this->youtubeRepository->removeByPageId($youtubeChannel, $storagePid); $rawFeed = self::youtube($youtubeChannel, 'init'); $posts = array(); $postIds = array(); foreach ($rawFeed as $item) { if (!in_array($item['id'], $postIds)) { $postIds[] = $item['id']; $postId = $item['id']; $item['id'] = $postId; $item['youtubeChannel'] = $youtubeChannel; $item['pid'] = $storagePid; $post = self::youtubePost($item); if (is_array($post)) { $posts[] = $post; } } } if (count($posts)) { $insertCnt = 0; foreach ($posts as $post) { $youtubePost = new \TYPO3\MooxSocial\Domain\Model\Youtube(); $youtubePost->setPid($post['pid']); $youtubePost->setCreated($post['created']); $youtubePost->setUpdated($post['updated']); $youtubePost->setModel("youtube"); $youtubePost->setType($post['type']); $youtubePost->setStatusType($post['statusType']); $youtubePost->setPage($post['page']); $youtubePost->setAction($post['action']); $youtubePost->setTitle($post['title']); $youtubePost->setSummary($post['summary']); $youtubePost->setText($post['text']); $youtubePost->setAuthor($post['author']); $youtubePost->setAuthorId($post['authorId']); $youtubePost->setDescription($post['description']); $youtubePost->setCaption($post['caption']); $youtubePost->setUrl($post['url']); $youtubePost->setLinkName($post['linkName']); $youtubePost->setLinkUrl($post['linkUrl']); $youtubePost->setImageUrl($post['imageUrl']); $youtubePost->setImageEmbedcode($post['imageEmbedcode']); $youtubePost->setVideoUrl($post['videoUrl']); $youtubePost->setVideoEmbedcode($post['videoEmbedcode']); $youtubePost->setSharedUrl($post['sharedUrl']); $youtubePost->setSharedTitle($post['sharedTitle']); $youtubePost->setSharedDescription($post['sharedDescription']); $youtubePost->setSharedCaption($post['sharedCaption']); $youtubePost->setLikes($post['likes']); $youtubePost->setShares($post['shares']); $youtubePost->setComments($post['comments']); $youtubePost->setApiUid($post['apiUid']); $youtubePost->setApiHash($post['apiHash']); $this->youtubeRepository->add($youtubePost); $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 Videos 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.youtube.listing.reinit.success', $this->extensionName), '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE); \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message); $this->redirect('index'); }