From fe9e5f72563a76c5f9649883bf0f5195ab90d1a9 Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Wed, 7 Jan 2026 17:17:51 +0500 Subject: [PATCH] fixed crontab every 5 seconds AND skipping empty messages --- examples/crontab/records.sh | 2 +- examples/crontab/week.sh | 11 +++++++++++ garden/campanula/system/public/telegram_week.php | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 examples/crontab/week.sh diff --git a/examples/crontab/records.sh b/examples/crontab/records.sh index 9c69f30..d6c3549 100644 --- a/examples/crontab/records.sh +++ b/examples/crontab/records.sh @@ -1 +1 @@ -*/10 * * * * php /var/www/campanula/garden/campanula/system/public/telegram_week.php +* * * * * /var/www/campanula/examples/crontab/week.sh diff --git a/examples/crontab/week.sh b/examples/crontab/week.sh new file mode 100755 index 0000000..ba49be4 --- /dev/null +++ b/examples/crontab/week.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Loop 6 times (60 seconds / 10 seconds = 6 iterations) +for i in {1..6}; do + php /var/www/campanula/garden/campanula/system/public/telegram_week.php + + # Wait 10 seconds before next iteration (skip sleep after the last run) + if [ $i -lt 6 ]; then + sleep 5 + fi +done diff --git a/garden/campanula/system/public/telegram_week.php b/garden/campanula/system/public/telegram_week.php index c00f67f..014856f 100644 --- a/garden/campanula/system/public/telegram_week.php +++ b/garden/campanula/system/public/telegram_week.php @@ -104,6 +104,9 @@ $response = (array) $request->fetchAll(pdo::FETCH_ASSOC); foreach ($response as $message) { // Iterating over messages from last week + // Skipping empty messages + if (empty($message['TextDecoded'])) continue; + // Searching for the message $model = new message()->read(filter: fn(record $record) => $record->sended === 1 && $record->identifier_gammu === (int) $message['ID']);