From c331754b267fe596259799375384309777e37e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= Date: Wed, 8 May 2024 17:04:08 +0200 Subject: [PATCH 1/3] Fix: Disabling the module in a container (Space or User) --- Module.php | 10 +++++++--- docs/CHANGELOG.md | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Module.php b/Module.php index c02b5a1..60de075 100644 --- a/Module.php +++ b/Module.php @@ -113,9 +113,13 @@ public function getContentContainerDescription(ContentContainerActiveRecord $con public function disableContentContainer(ContentContainerActiveRecord $container) { parent::disableContentContainer($container); - /** @var ExternalCalendar $item */ - foreach (ExternalCalendar::find()->contentContainer($container)->each() as $item) { - $item->hardDelete(); + /** @var ExternalCalendar $calendar */ + foreach (ExternalCalendar::find()->contentContainer($container)->each() as $calendar) { + /** @var ExternalCalendarEntry $entry */ + foreach (ExternalCalendarEntry::find()->where(['calendar_id' => $calendar->id])->each() as $entry) { + $entry->hardDelete(); + } + $calendar->hardDelete(); } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fc03e84..2758003 100755 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,7 @@ Unreleased - Enh #68: Make URL locations clickable - Enh #69: Add `requirements.php` - Fix #71: After module disabling, Content for ExternalCalendarEntry are not deleted +- Fix: Disabling the module in a container (Space or User) 1.4.2 (January 19, 2023) ----------------------- From e3c3b4f139bf7504e0dc79d169706ea270e21ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= Date: Wed, 8 May 2024 17:05:07 +0200 Subject: [PATCH 2/3] Add PR ID to changelog --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2758003..4ddacdf 100755 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,7 +6,7 @@ Unreleased - Enh #68: Make URL locations clickable - Enh #69: Add `requirements.php` - Fix #71: After module disabling, Content for ExternalCalendarEntry are not deleted -- Fix: Disabling the module in a container (Space or User) +- Fix #76: Disabling the module in a container (Space or User) 1.4.2 (January 19, 2023) ----------------------- From df6d5128ad7d1ef567807fc9709e284ba3cbd32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= Date: Wed, 8 May 2024 17:50:35 +0200 Subject: [PATCH 3/3] https://github.com/humhub-contrib/external_calendar/pull/76#discussion_r1594223828 --- Module.php | 14 +---- models/ExternalCalendar.php | 109 ++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 72 deletions(-) diff --git a/Module.php b/Module.php index 60de075..00f7661 100644 --- a/Module.php +++ b/Module.php @@ -60,13 +60,9 @@ public function enable() */ public function disable() { - /** @var ExternalCalendarEntry $entry */ - foreach (ExternalCalendarEntry::find()->each() as $entry) { - $entry->hardDelete(); - } - /** @var ExternalCalendar $entry */ - foreach (ExternalCalendar::find()->all() as $entry) { - $entry->hardDelete(); + /** @var ExternalCalendar $calendar */ + foreach (ExternalCalendar::find()->all() as $calendar) { + $calendar->hardDelete(); } parent::disable(); } @@ -115,10 +111,6 @@ public function disableContentContainer(ContentContainerActiveRecord $container) parent::disableContentContainer($container); /** @var ExternalCalendar $calendar */ foreach (ExternalCalendar::find()->contentContainer($container)->each() as $calendar) { - /** @var ExternalCalendarEntry $entry */ - foreach (ExternalCalendarEntry::find()->where(['calendar_id' => $calendar->id])->each() as $entry) { - $entry->hardDelete(); - } $calendar->hardDelete(); } } diff --git a/models/ExternalCalendar.php b/models/ExternalCalendar.php index 1c0047c..e5bd2b7 100644 --- a/models/ExternalCalendar.php +++ b/models/ExternalCalendar.php @@ -5,16 +5,14 @@ use Colors\RandomColor; use humhub\libs\Html; use humhub\modules\content\components\ActiveQueryContent; +use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\content\components\ContentContainerActiveRecord; use humhub\modules\external_calendar\jobs\UpdateCalendarVisibility; use humhub\modules\external_calendar\models\forms\ConfigForm; -use Yii; -use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\external_calendar\permissions\ManageCalendar; use humhub\modules\search\interfaces\Searchable; -use humhub\modules\content\models\Content; use ICal\ICal; -use yii\base\InvalidCallException; +use Yii; use yii\base\InvalidValueException; @@ -39,72 +37,61 @@ class ExternalCalendar extends ContentActiveRecord implements Searchable { const ITEM_TYPE_KEY = 'external_calendar'; - + /** + * Sync Modes + */ + const SYNC_MODE_NONE = 0; + const SYNC_MODE_HOURLY = 1; + const SYNC_MODE_DAILY = 2; + /** + * Event Modes + */ + const EVENT_MODE_CURRENT_MONTH = 0; + const EVENT_MODE_ALL = 1; + /** + * @var array all given sync modes as array + */ + public static $syncModes = [ + self::SYNC_MODE_NONE, + self::SYNC_MODE_HOURLY, + self::SYNC_MODE_DAILY + ]; + /** + * @var array all given sync modes as array + */ + public static $eventModes = [ + self::EVENT_MODE_CURRENT_MONTH, + self::EVENT_MODE_ALL + ]; /** * @inheritdoc */ public $moduleId = 'external_calendar'; - /** * @inheritdoc */ public $wallEntryClass = 'humhub\modules\external_calendar\widgets\WallEntryCalendar'; - /** * @inheritdoc */ public $managePermission = ManageCalendar::class; - /** * @var bool */ public $allowFiles = false; - /** * @var int form field */ public $public; - /** * @inheritdoc */ public $streamChannel = null; - /** * @inheritdoc */ public $silentContentCreation = true; - /** - * Sync Modes - */ - const SYNC_MODE_NONE = 0; - const SYNC_MODE_HOURLY = 1; - const SYNC_MODE_DAILY = 2; - - /** - * Event Modes - */ - const EVENT_MODE_CURRENT_MONTH = 0; - const EVENT_MODE_ALL = 1; - - /** - * @var array all given sync modes as array - */ - public static $syncModes = [ - self::SYNC_MODE_NONE, - self::SYNC_MODE_HOURLY, - self::SYNC_MODE_DAILY - ]; - - /** - * @var array all given sync modes as array - */ - public static $eventModes = [ - self::EVENT_MODE_CURRENT_MONTH, - self::EVENT_MODE_ALL - ]; - /** * @inheritdoc */ @@ -121,11 +108,11 @@ public function init() parent::init(); - if(!$this->color) { + if (!$this->color) { $this->color = RandomColor::one(['luminosity' => 'light']); } - if($this->event_mode === null) { + if ($this->event_mode === null) { $this->event_mode = static::EVENT_MODE_ALL; } } @@ -133,7 +120,7 @@ public function init() public function afterFind() { parent::afterFind(); - if($this->public === null) { + if ($this->public === null) { $this->public = $this->content->visibility; } } @@ -155,8 +142,8 @@ public function rules() [['event_mode'], 'in', 'range' => self::$eventModes], ]; - if(!$this->allowFiles) { - $result[] = [['url'], 'url', 'defaultScheme' => 'https', 'message' => Yii::t('ExternalCalendarModule.sync_result', "No valid ical url! Try an url with http / https.")]; + if (!$this->allowFiles) { + $result[] = [['url'], 'url', 'defaultScheme' => 'https', 'message' => Yii::t('ExternalCalendarModule.sync_result', "No valid ical url! Try an url with http / https.")]; } return $result; @@ -194,7 +181,7 @@ public function getIcon() */ public function validateURL($attribute, $params) { - if(!filter_var($this->url, FILTER_VALIDATE_URL)) { + if (!filter_var($this->url, FILTER_VALIDATE_URL)) { $this->addError($attribute, Yii::t('ExternalCalendarModule.sync_result', "Bad URL")); return false; } @@ -246,7 +233,7 @@ public function getSearchAttributes() */ public function beforeDelete() { - foreach (ExternalCalendarEntry::findAll(['calendar_id' => $this->id]) as $item) { + foreach (ExternalCalendarEntry::find()->where(['calendar_id' => $this->id])->each() as $item) { $item->delete(); } @@ -286,7 +273,7 @@ public function afterSave($insert, $changedAttributes) parent::afterSave($insert, $changedAttributes); - if($visibilityChanged) { + if ($visibilityChanged) { Yii::$app->queue->push(new UpdateCalendarVisibility(['calendarId' => $this->id])); } } @@ -353,26 +340,26 @@ public function getEventMode() } } + /** + * @return ExternalCalendarEntry[] + */ + public function getRecurringEventRoots() + { + return $this->getEntries(false) + ->andWhere('external_calendar_entry.rrule IS NOT NULL')->all(); + } + public function getEntries(bool $includeRecurrences = true): ActiveQueryContent { $query = $this->hasMany(ExternalCalendarEntry::class, ['calendar_id' => 'id']); - if(!$includeRecurrences) { + if (!$includeRecurrences) { $query->andWhere('external_calendar_entry.parent_event_id IS NULL'); } return $query->readable(); } - /** - * @return ExternalCalendarEntry[] - */ - public function getRecurringEventRoots() - { - return $this->getEntries(false) - ->andWhere('external_calendar_entry.rrule IS NOT NULL')->all(); - } - public function addAttributes(ICal $ical) { // add info to CalendarModel @@ -404,9 +391,9 @@ public function getFullCalendarArray() /** * Syncronizes this external calendar * - * @throws InvalidValueException - * @throws \yii\base\Exception * @return static + * @throws \yii\base\Exception + * @throws InvalidValueException */ public function sync($rangeStart = null, $rangeEnd = null) {