--- /dev/null
+<?php
+
+/**
+ * @var $time integer|null
+ */
+
+use GuzzleHttp\Client;
+use yii\helpers\Json;
+use yii_app\records\SchedulerTaskLog;
+use \yii_app\records\Meeting;
+use yii_app\services\TelegramService;
+
+ini_set('max_execution_time', (string)(60 * 60 * 1)); // 1 час
+ini_set('display_errors', 'on');
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+$time = $time ?? time(); // Использовать текущее время, если параметр не передан
+
+echo "time2_" . $time . "_time2 ";
+$taskNum = 35;
+$dateTask = date('Y-m-d H:i:s', $time);
+$dateTaskStart = null;
+$dateTaskStop = null;
+$log = '';
+$error = '';
+$infoError = '';
+$infoText = '';
+$description = '';
+$result = 0;
+
+$enable = true;
+$start = false;
+$force = true;
+
+$minuetTimeInTask = date('i', $time);
+$fullTimeInTask = date('Y-m-d H:i:s', $time);
+
+try {
+ if (
+ $force
+ && $enable
+ ) {
+
+ $dateTaskStart = date('Y-m-d H:i:s', $time);
+ $info = ' ================ test Task ' . $taskNum . ' start ================';
+ echo $info;
+ $log .= $info;
+ $log .= $time;
+
+ $schedulerTaskLog = new SchedulerTaskLog();
+ $schedulerTaskLog->setTaskNum($taskNum)
+ ->setName('Task ' . $taskNum)
+ ->setDate($dateTask)
+ ->setDateStart($dateTaskStart)
+ ;
+ $validate = $schedulerTaskLog->validate();
+ if ($validate) {
+ $schedulerTaskLog->save();
+ }
+ ////////////////////////////////////////////////////////////////////////
+ Meeting::updateAll(['location' => 2], ['location' => 1]);
+ $meeting = Meeting::find()->where(['location' => 1])->one();
+ if ($meeting) {
+ Meeting::updateAll(['location' => 3], ['location' => 2]);
+
+ $botToken = TelegramService::TELEGRAM_BOT_DEV;
+ $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
+ $chats = ['337084327', '5489795686']; //Алексей
+ $message = TelegramService::escapeMarkdown("Тестовое сообщение для https://tracker.yandex.ru/ERP-326 из шедулера");
+ $client = new Client();
+ foreach ($chats as $chatId) {
+ try {
+ $client->post($apiURL, [
+ 'json' => [
+ 'chat_id' => $chatId,
+ 'text' => $message,
+ 'parse_mode' => 'MarkdownV2',
+ ],
+ ]);
+ } catch (\Exception $e) {
+ Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+ }
+ }
+ }
+ ////////////////////////////////////////////////////////////////////////
+ $info = ' ================ test Task ' . $taskNum . ' stop ================';
+ echo $info;
+ $log .= $info;
+ $log .= ' date >= ' . strtotime("-1 week", $time);
+ $dateTaskStop = date('Y-m-d H:i:s', $time);
+ } else {
+ $info = ' Task ' . $taskNum . ' skip ';
+ echo $info;
+ $log .= $info;
+ }
+} catch (Exception $e) {
+ $error = 'Exception: ' . $e->getMessage() . ' ' . $e->getFile() . ' >>> ' . $e->getLine();
+}
+
+if (empty($schedulerTaskLog)) {
+ $schedulerTaskLog = new SchedulerTaskLog();
+ $schedulerTaskLog->setTaskNum($taskNum)
+ ->setName('Task ' . $taskNum)
+ ->setDate($dateTask)
+ ->setDateStart($dateTaskStart)
+ ->setDateStop($dateTaskStop)
+ ->setDescription($description)
+ ->setError($error)
+ ->setInfo($infoText)
+ ->setLog($log)
+ ;
+} else {
+ $schedulerTaskLog->setDateStop($dateTaskStop)
+ ->setDescription($description)
+ ->setError($error)
+ ->setInfo($infoText)
+ ->setLog($log)
+ ;
+}
+$validate = $schedulerTaskLog->validate();
+if ($validate) {
+ $schedulerTaskLog->save();
+}