diff --git a/config.php b/config.php index 3525d6f2..5ce1e7ac 100644 --- a/config.php +++ b/config.php @@ -1,5 +1,6 @@ [ ['class' => Menu::class, 'event' => Menu::EVENT_INIT, 'callback' => [Events::class, 'onSpaceMenuInit']], ['class' => Application::class, 'event' => Application::EVENT_BEFORE_REQUEST, 'callback' => [Events::class, 'onBeforeRequest']], + ['class' => ConsoleApplication::class, 'event' => ConsoleApplication::EVENT_BEFORE_REQUEST, 'callback' => [Events::class, 'onBeforeRequest']], ['class' => ProfileMenu::class, 'event' => ProfileMenu::EVENT_INIT, 'callback' => [Events::class, 'onProfileMenuInit']], ['class' => SpaceSidebar::class, 'event' => SpaceSidebar::EVENT_INIT, 'callback' => [Events::class, 'onSpaceSidebarInit']], ['class' => ProfileSidebar::class, 'event' => ProfileSidebar::EVENT_INIT, 'callback' => [Events::class, 'onProfileSidebarInit']], @@ -37,4 +39,4 @@ ['class' => User::class, 'event' => User::EVENT_BEFORE_DELETE, 'callback' => [Events::class, 'onUserDelete']], ['class' => 'humhub\modules\rest\Module', 'event' => 'restApiAddRules', 'callback' => [Events::class, 'onRestApiAddRules']], ], -]; \ No newline at end of file +]; diff --git a/controllers/IcalController.php b/controllers/IcalController.php index d2a1670f..2027a4a3 100644 --- a/controllers/IcalController.php +++ b/controllers/IcalController.php @@ -1,21 +1,16 @@ getEvent($id); - - if(RecurrenceHelper::isRecurrent($event) && !RecurrenceHelper::isRecurrentRoot($event)) { - /* @var $event RecurrentEventIF */ - $event = $event->getRecurrenceQuery()->getRecurrenceRoot(); - } + $model = $this->getModel($id); - $uid = $event->getUid() ?: $this->uniqueId; + $ics = $model->generateIcs(); - return Yii::$app->response->sendContentAsFile(VCalendar::withEvents($event, CalendarUtils::getSystemTimeZone(true))->serialize(), $uid.'.ics', ['mimeType' => static::EXPORT_MIME]); + if (empty($ics)) { + throw new HttpException(400, 'Selected content does not implement calendar interface'); + } - } + $uid = $model->getUid() ?: $this->uniqueId; - public function actionGenerateics() - { - $calendarEntry = $this->getCalendarEntry(Yii::$app->request->get('id')); - $ics = $calendarEntry->generateIcs(); - return Yii::$app->response->sendContentAsFile($ics, uniqid() . '.ics', ['mimeType' => static::EXPORT_MIME]); + return Yii::$app->response->sendContentAsFile($ics, $uid.'.ics', ['mimeType' => static::EXPORT_MIME]); } /** * @param $id - * @return CalendarEventIF + * @return CalendarEntry * @throws HttpException * @throws \Throwable * @throws Exception */ - public function getEvent($id) + public function getModel($id) { $content = Content::findOne(['id' => $id]); - if(!$content) { + if (!$content) { throw new NotFoundHttpException(); } - if(!$content->canView()) { + if (!$content->canView()) { throw new HttpException(403); } $model = $content->getModel(); - if(!$model) { + if (!$model) { throw new NotFoundHttpException(); } - $event = CalendarUtils::getCalendarEvent($model); - - if(!$event) { - throw new HttpException(400, 'Selected content does not implement calendar interface'); - } - - return $event; + return $model; } -} \ No newline at end of file +} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 53f788a9..16932aad 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog 1.5.7 (Unreleased) -------------------------- - Fix #433: Fix memory usage on integrity check +- Enh #435: Attach ICS file to invitation email 1.5.6 (October 26, 2023) -------------------------- diff --git a/interfaces/VCalendar.php b/interfaces/VCalendar.php index 541c2ec9..bcaba582 100644 --- a/interfaces/VCalendar.php +++ b/interfaces/VCalendar.php @@ -42,7 +42,7 @@ class VCalendar extends Model /** - * @param CalendarEventIF[] $items + * @param CalendarEventIF|CalendarEventIF[] $items * @return VCalendar */ public static function withEvents($items, $tz = null) @@ -364,4 +364,4 @@ public function add($items, bool $initRecurrenceChildren = true) return $this; } -} \ No newline at end of file +} diff --git a/models/CalendarEntry.php b/models/CalendarEntry.php index 18211097..0cdccdb4 100644 --- a/models/CalendarEntry.php +++ b/models/CalendarEntry.php @@ -13,6 +13,7 @@ use humhub\modules\calendar\interfaces\recurrence\AbstractRecurrenceQuery; use humhub\modules\calendar\interfaces\recurrence\RecurrentEventIF; use humhub\modules\calendar\interfaces\reminder\CalendarEventReminderIF; +use humhub\modules\calendar\interfaces\VCalendar; use humhub\modules\calendar\models\participation\CalendarEntryParticipation; use humhub\modules\calendar\models\recurrence\CalendarEntryRecurrenceQuery; use humhub\modules\calendar\models\reminder\CalendarReminder; @@ -634,11 +635,20 @@ public function getBadge() return null; } - public function generateIcs() + public function generateIcs(): ?string { - $timezone = Yii::$app->settings->get('defaultTimeZone'); - $ics = new ICS($this->title, $this->description, $this->start_datetime, $this->end_datetime, null, null, $timezone, $this->all_day); - return $ics; + $event = CalendarUtils::getCalendarEvent($this); + + if (!$event) { + return null; + } + + if (RecurrenceHelper::isRecurrent($event) && !RecurrenceHelper::isRecurrentRoot($event)) { + /* @var $event RecurrentEventIF */ + $event = $event->getRecurrenceQuery()->getRecurrenceRoot(); + } + + return VCalendar::withEvents($event, CalendarUtils::getSystemTimeZone(true))->serialize(); } public function afterMove(ContentContainerActiveRecord $container = null) diff --git a/notifications/Invited.php b/notifications/Invited.php index ad6e4714..7a524639 100644 --- a/notifications/Invited.php +++ b/notifications/Invited.php @@ -11,6 +11,7 @@ use humhub\modules\calendar\models\CalendarEntry; use humhub\modules\notification\components\BaseNotification; use Yii; +use yii\mail\MessageInterface; /** * Notification for an invited participant @@ -64,4 +65,21 @@ public function getMailSubject() 'contentTitle' => $this->getContentInfo($this->source, false) ]); } -} \ No newline at end of file + + /** + * @inheritdoc + */ + public function beforeMailSend(MessageInterface $message) + { + $ics = $this->source->generateIcs(); + + if (!empty($ics)) { + $message->attachContent($ics, [ + 'fileName' => $this->source->getUid() . '.ics', + 'contentType' => 'text/calendar' + ]); + } + + return true; + } +}