Ejemplo n.º 1
0
 public static function process()
 {
     $logger = new Logger();
     $rssFeed = Fetcher::get(RssConfig::$rssFeedUrl);
     $containsNewContent = NewContentChecker::checkForNewContent($rssFeed);
     if ($containsNewContent) {
         $logger->log('info', 'New items detected');
         OutputUpdater::updateOutput($rssFeed);
         GuidUpdater::update($rssFeed->channel->item);
     } else {
         $logger->log('info', 'No new items detected');
     }
 }
Ejemplo n.º 2
0
 public static function checkForNewContent($rssFeed)
 {
     $log = new Logger();
     $rssFileContents = FileReader::readFile(Config::$rssGuidFileLocation);
     if (!$rssFileContents) {
         $log->log('info', 'GUID file is empty');
         return true;
     }
     $aGuids = GuidFileHandler::getGuids();
     foreach ($rssFeed->channel->item as $item) {
         if (!in_array((string) $item->guid, $aGuids)) {
             $log->log('info', 'Rss file has new content');
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public static function update($rssItems)
 {
     $logger = new Logger();
     $logger->log('info', 'Updating GUIDs');
     GuidFileHandler::addGuidFileIfNotExists();
     $aGuids = [];
     foreach ($rssItems as $rssItem) {
         array_push($aGuids, (string) $rssItem->guid);
     }
     GuidFileHandler::updateGuids($aGuids);
 }
Ejemplo n.º 4
0
 public static function updateGuids($aGuids)
 {
     $logger = new Logger();
     $guidsJson = json_encode($aGuids);
     $updated = FileWriter::writeStringToFile($guidsJson, Config::$rssGuidFileLocation);
     $message = 'GUIDs updated';
     $logLevel = 'info';
     if (!$updated) {
         $message = 'GUIDs not updated';
         $logLevel = 'error';
     }
     $logger->log($logLevel, $message);
 }
Ejemplo n.º 5
0
 public static function updateOutput($rssFeed)
 {
     $logger = new Logger();
     $jsonString = json_encode($rssFeed);
     OutputFileHandler::addOutputFileIfNotExists();
     $updated = FileWriter::writeStringToFile($jsonString, Config::$rssOutputFileLocation);
     $message = 'Output updated';
     $logLevel = 'info';
     if (!$updated) {
         $message = 'Output not updated';
         $logLevel = 'error';
     }
     $logger->log($logLevel, $message);
 }
Ejemplo n.º 6
0
 public static function go()
 {
     $logger = new Logger();
     $logger->log('info', 'Trace to log in go');
     Foo::bar();
 }