Przeglądaj źródła

fixed bug in Notify when no users with active notify

Piotr Labudda 10 lat temu
rodzic
commit
a865731264
2 zmienionych plików z 24 dodań i 22 usunięć
  1. 23 22
      SE/se-lib/Route/Cron.php
  2. 1 0
      SE/se-lib/Route/Notify.php

+ 23 - 22
SE/se-lib/Route/Cron.php

@@ -98,32 +98,33 @@ class Route_Cron extends RouteBase {
 		$notify = Router::getRoute('Notify');
 		$todoReminders = array();
 
-		{// limit send time to 8 - 20
-			$timeNow = time();
-			$timeSendLimitFrom = mktime(8, 0, 0, date('n'), date('j'), date('Y'));
-			$timeSendLimitTo = mktime(20, 0, 0, date('n'), date('j'), date('Y'));
-			if ($timeNow > $timeSendLimitFrom && $timeNow < $timeSendLimitTo) {
-				$todoReminders = $notify->getTodoList(2);
+		echo '<div class="container">' . "\n";
+		echo '<h1>Cron</h1>' . "\n";
+		try {
+			{// limit send time to 8 - 20
+				$timeNow = time();
+				$timeSendLimitFrom = mktime(8, 0, 0, date('n'), date('j'), date('Y'));
+				$timeSendLimitTo = mktime(20, 0, 0, date('n'), date('j'), date('Y'));
+				if ($timeNow > $timeSendLimitFrom && $timeNow < $timeSendLimitTo) {
+					$todoReminders = $notify->getTodoList(2);
+				}
 			}
-		}
-
-		?>
-<div class="container">
-	<h1>Cron</h1>
-	<?php DBG::_('DBG_CRON', '>0', 'todoReminders', $todoReminders, __CLASS__, __FUNCTION__, __LINE__); ?>
-		<?php
-
-		foreach ($todoReminders as $who => $listWhen) {
-			foreach ($listWhen as $when => $listWhat) {
-				if (!empty($listWhat)) {
-					$reminders = array_keys($listWhat);
-					echo "<p>Sending to {$who} reminders [" . implode(",", $reminders) . "]</p>" . "\n";
-					$notify->send($who, $reminders, $forceMail = 'plabudda@biall-net.pl');
-					$notify->markAsSent($who, $reminders);
+			DBG::_('DBG_CRON', '>0', 'todoReminders', $todoReminders, __CLASS__, __FUNCTION__, __LINE__);
+
+			foreach ($todoReminders as $who => $listWhen) {
+				foreach ($listWhen as $when => $listWhat) {
+					if (!empty($listWhat)) {
+						$reminders = array_keys($listWhat);
+						echo "<p>Sending to {$who} reminders [" . implode(",", $reminders) . "]</p>" . "\n";
+						$notify->send($who, $reminders, $forceMail = 'plabudda@biall-net.pl');
+						$notify->markAsSent($who, $reminders);
+					}
 				}
 			}
+		} catch (Exception $e) {
+			SE_Layout::alert('danger', "#" . $e->getLine() . ":" . $e->getMessage());
 		}
-echo "\n" . '</div>';// .container
+		echo "\n" . '</div>';// .container
 		echo "\n.EOF\n";
 	}
 

+ 1 - 0
SE/se-lib/Route/Notify.php

@@ -760,6 +760,7 @@ function refreshPreview() {
 		$sth->bindValue(':limit', $limit, PDO::PARAM_INT);
 		$sth->execute();
 		$rawUsers = $sth->fetchAll();
+		if (empty($rawUsers)) return array();
 		$sqlUsers = array(); foreach ($rawUsers as $row) { $sqlUsers[] = $pdo->quote($row['ADM_ACCOUNT'], PDO::PARAM_STR); }
 		$sqlUsers = implode(", ", $sqlUsers);
 		$sth = $pdo->prepare("