diff --git a/MatrixPostNewsCronjob.php b/MatrixPostNewsCronjob.php index d4ac57fff04f5e943d1362259a1d005693be51c9..e2d63d40b818c01219bdf587c14fabef91b945de 100644 --- a/MatrixPostNewsCronjob.php +++ b/MatrixPostNewsCronjob.php @@ -77,34 +77,41 @@ class MatrixPostNewsCronjob extends CronJob print_r($news); } foreach (StudipNews::findMany($news) as $one) { - foreach ($one->news_ranges as $range) { - $success = false; - if ($range->course && MatrixRoom::hasRoom($range->course->id)) { - $room = MatrixRoom::find($range->course->id); + if ($one->date + $one->expire >= time()) { + foreach ($one->news_ranges as $range) { + $success = false; + if ($range->course && MatrixRoom::hasRoom($range->course->id)) { + $room = MatrixRoom::find($range->course->id); - $success = MatrixClient::get()->postMessage( - MatrixAccount::requireSystemAccount(), - $room->getLinkedRoom(), - 'Ankündigung: ' . $one->topic . ' ' . strip_tags($one->body), - '<strong>Ankündigung: ' . $one->topic . '</strong><br>' . $one->body - ); + $success = MatrixClient::get()->postMessage( + MatrixAccount::requireSystemAccount(), + $room->getLinkedRoom(), + 'Ankündigung: ' . $one->topic . ' ' . strip_tags($one->body), + '<strong>Ankündigung: ' . $one->topic . '</strong><br>' . $one->body + ); + + // Mark entry as done after message has been posted to Matrix room successfully. + if ($success) { + // Verbose output + if ($parameters['verbose']) { + echo sprintf( + "Posted news entry $1%s to Matrix room $2%s in course $3%s.\n", + $one->id, $room->matrix_room_id, $room->range_id + ); + } - // Mark entry as done after message has been posted to Matrix room successfully. - if ($success) { - // Verbose output - if ($parameters['verbose']) { - echo sprintf( - "Posted news entry $1%s to Matrix room $2%s in course $3%s.\n", - $news->id, $room->matrix_room_id, $room->range_id + DBManager::get()->execute( + "UPDATE `matrix_upcoming_news` SET `posted` = 1 WHERE `news_id` = :id AND `range_id` = :range", + ['id' => $one->id, 'range' => $range->course->id] ); } - - DBManager::get()->execute( - "UPDATE `matrix_upcoming_news` SET `posted` = 1 WHERE `news_id` = :id AND `range_id` = :range", - ['id' => $one->id, 'range' => $range->course->id] - ); } } + } else { + DBManager::get()->execute( + "DELETE FROM `matrix_upcoming_news` WHERE `news_id` = :id", + ['id' => $one->id] + ); } } diff --git a/plugin.manifest b/plugin.manifest index c25c2a6303033a7bb5dfd65b1c046dbff63a10fb..630979ae07b43021db48f92e59a0dd14638d7243 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginname=Matrix-Chat pluginclassname=MatrixPlugin origin=data-quest -version=1.4.3 +version=1.4.4 screenshot=assets/images/matrix_logo.png description=Matrix chat for Stud.IP courses studipMinVersion=4.5