From 6b090675c6f7acbd3d0f2e6f7ae5a852eb27e8fd Mon Sep 17 00:00:00 2001 From: Sean Delaney Date: Fri, 7 Jun 2024 05:46:07 +0100 Subject: [PATCH] =?UTF-8?q?fix(SFT-1158):=20Replaced=20custom=20UpdateEven?= =?UTF-8?q?tsUriJob=20with=20Craft=E2=80=99s=20UpdateElementSlugsAndUris?= =?UTF-8?q?=20job=20to=20correctly=20parse=20URI=20parameters=20(#295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controllers/CalendarsController.php | 16 ++++--- .../plugin/src/Jobs/UpdateEventsUriJob.php | 46 ------------------- 2 files changed, 10 insertions(+), 52 deletions(-) delete mode 100644 packages/plugin/src/Jobs/UpdateEventsUriJob.php diff --git a/packages/plugin/src/Controllers/CalendarsController.php b/packages/plugin/src/Controllers/CalendarsController.php index bc3007c..6ece5b1 100644 --- a/packages/plugin/src/Controllers/CalendarsController.php +++ b/packages/plugin/src/Controllers/CalendarsController.php @@ -11,10 +11,10 @@ use craft\helpers\UrlHelper; use craft\models\FieldLayout; use craft\models\FieldLayoutTab; +use craft\queue\jobs\UpdateElementSlugsAndUris; use craft\records\Field; use Solspace\Calendar\Calendar; use Solspace\Calendar\Elements\Event; -use Solspace\Calendar\Jobs\UpdateEventsUriJob; use Solspace\Calendar\Library\Helpers\DateHelper; use Solspace\Calendar\Library\Helpers\PermissionHelper; use Solspace\Calendar\Library\Helpers\SitesHelper; @@ -293,11 +293,15 @@ public function actionSaveCalendar(): Response // Save it if ($this->getCalendarService()->saveCalendar($calendar)) { if ($hasUriFormatChanges) { - foreach ($calendar->siteSettings as $siteSetting) { - Queue::push(new UpdateEventsUriJob([ - 'calendarId' => $calendar->id, - 'siteId' => $siteSetting->siteId, - 'uriFormat' => $siteSetting->uriFormat, + $events = Calendar::getInstance()->events->getEventQuery([ + 'calendarId' => $calendar->id, + ])->all(); + + foreach ($events as $event) { + Queue::push(new UpdateElementSlugsAndUris([ + 'elementId' => $event->id, + 'elementType' => $event::class, + 'updateDescendants' => false, ])); } } diff --git a/packages/plugin/src/Jobs/UpdateEventsUriJob.php b/packages/plugin/src/Jobs/UpdateEventsUriJob.php deleted file mode 100644 index 342e6c9..0000000 --- a/packages/plugin/src/Jobs/UpdateEventsUriJob.php +++ /dev/null @@ -1,46 +0,0 @@ -updateEventsUri(); - $this->setProgress($queue, 1); - } - - protected function defaultDescription(): string - { - return 'Update Events URI'; - } - - private function updateEventsUri(): void - { - $elements = Calendar::getInstance()->events - ->getEventQuery([ - 'calendarId' => $this->calendarId, - ]) - ->all() - ; - - foreach ($elements as $element) { - \Craft::$app->db - ->createCommand('UPDATE elements_sites SET uri = :uri WHERE elementId = :elementId AND siteId = :siteId') - ->bindValue(':elementId', $element->id) - ->bindValue(':siteId', $this->siteId) - ->bindValue(':uri', $this->uriFormat) - ->execute() - ; - } - } -}