diff --git a/core/config.php b/core/config.php index 15183a3..16a9729 100644 --- a/core/config.php +++ b/core/config.php @@ -111,5 +111,5 @@ /** * Флаг использования логирования */ - const USE_LOG = false; + const USE_LOG = true; diff --git a/core/cron.php b/core/cron.php index 1f9395b..4446ec8 100644 --- a/core/cron.php +++ b/core/cron.php @@ -34,19 +34,4 @@ exec('(php -f ' . __DIR__ . '/runtime/threadsWorker.php & ) >> /dev/null 2>&1'); - // Каждые 10 минут добавляем в очередь задание на проверку новостей слободы и отправку в телегу - $cacheId = md5('cron_myslo'); - $runMyslo = false; - if (Cache::check($cacheId) && $cronMyslo = Cache::get($cacheId)) { - if ((time() - (int)$cronMyslo) > 600) { - $runMyslo = true; - Cache::set($cacheId, time()); - } - } else { - $runMyslo = true; - Cache::set($cacheId, time()); - } - - if ($runMyslo === true) { - $result = (new MQ())->setAttempts(3)->setPriority(3)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); - } \ No newline at end of file + $result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index d1edaf1..6b817c7 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -253,12 +253,10 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' public static function getMySLO() { - $cacheId = md5('getMySLO_criminal'); - if (Cache::check($cacheId)) { - $oldLink = Cache::get($cacheId); - } else { - $oldLink = ''; - } + $result = 'Нет данных для обновления'; + /** @var DB $DB */ + $DB = DB::getInstance(); + $file = file_get_contents('https://myslo.ru/news/criminal'); $file = preg_match_all('/"item width-100-tiny">(.*?)
/us', $file, $file2); @@ -273,10 +271,10 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' preg_match_all('/" href="(.*?)">/us', $file2, $link); $link = 'https://myslo.ru' . trim($link[1][0]); + $hash = md5($link); + $res = $DB->query('SELECT * FROM myslo WHERE hash="' . $hash . '"'); + if (!$res) { - if ($oldLink !== $link) { - sendTelegram('OLD (' . strlen($oldLink) . '): ' . $oldLink . PHP_EOL . 'NEW (' . strlen($link) . '): ' . $link); - sendTelegram('Обнаружен новый пост'); $full = file_get_contents($link); preg_match_all('/

(.*?)<\/p><\/div>/us', $full, $lidArticle); @@ -303,16 +301,17 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' $post = '' . $title . '' . PHP_EOL . $lidArticle . PHP_EOL . $fullArticle; $post .= PHP_EOL . 'Подробнее'; + $telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); $telegram->setChat('-1001789206618'); $res = $telegram->sendPhoto($tmpFile, $post); + sendTelegram($post); @unlink($tmpFile); - Cache::set($cacheId, trim($link)); - return $res; + $itemId = $DB->addItem('myslo', ['hash' => $hash, 'title' => $title]); + + return print_r($res, true);//'Добавлен новый элемент с ID ' . $itemId; } else { return 'Обновление не требуется'; } - - return $res; } } \ No newline at end of file diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index 80252ef..3296d51 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -531,7 +531,7 @@ 'in_progress' => self::VALUE_N, 'attempts' => '0', 'attempts_limit' => $this->runNow ? '1' : $this->attempts, // Если запускаем немедленно, то попытка одна - 'class' => !empty($class) ? addslashes($class) : '', + 'class' => !empty($class) ? $class : '', 'method' => $method, 'priority' => $priority, 'params' => $params,