From c2e65f30643f64c9f1172623fd714e18a1402478 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 28 Apr 2021 14:59:22 +0100 Subject: [PATCH] Fix various Display Group and Display related issues --- lib/Controller/DisplayGroup.php | 1 + lib/Entity/Display.php | 20 ++++++++++++++------ tests/LocalWebTestCase.php | 3 +-- tests/Middleware/TestXmr.php | 3 +-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/Controller/DisplayGroup.php b/lib/Controller/DisplayGroup.php index c00b17afdf..67153a8fc3 100644 --- a/lib/Controller/DisplayGroup.php +++ b/lib/Controller/DisplayGroup.php @@ -1191,6 +1191,7 @@ public function unassignDisplayGroup(Request $request, Response $response, $id) } $displayGroup->load(); + $this->getDispatcher()->dispatch(DisplayGroupLoadEvent::$NAME, new DisplayGroupLoadEvent($displayGroup)); if ($displayGroup->isDynamic == 1) { throw new InvalidArgumentException(__('DisplayGroups cannot be manually unassigned to a Dynamic Group'), 'isDynamic'); diff --git a/lib/Entity/Display.php b/lib/Entity/Display.php index d8fc08607c..995ec1a8ff 100644 --- a/lib/Entity/Display.php +++ b/lib/Entity/Display.php @@ -684,17 +684,21 @@ public function save($options = []) ], $options); $allowNotify = true; + $checkDynamicGroups = true; - if ($options['validate']) + if ($options['validate']) { $this->validate(); + } if ($options['checkDisplaySlotAvailability']) { // Check if there are display slots available $maxDisplays = $this->config->GetSetting('MAX_LICENSED_DISPLAYS'); if (!$this->isDisplaySlotAvailable()) { - throw new InvalidArgumentException(sprintf(__('You have exceeded your maximum number of authorised displays. %d'), - $maxDisplays), 'maxDisplays'); + throw new InvalidArgumentException(sprintf( + __('You have exceeded your maximum number of authorised displays. %d'), + $maxDisplays + ), 'maxDisplays'); } } @@ -703,8 +707,8 @@ public function save($options = []) // Never notify on add (there is little point, we've only just added). $allowNotify = false; - } - else { + $checkDynamicGroups = false; + } else { $this->edit(); } @@ -713,10 +717,11 @@ public function save($options = []) } // Trigger an update of all dynamic DisplayGroups - if ($this->hasPropertyChanged('display') || $this->hasPropertyChanged('tags')) { + if (($this->hasPropertyChanged('display') || $this->hasPropertyChanged('tags')) && $checkDynamicGroups) { foreach ($this->displayGroupFactory->getByIsDynamic(1) as $group) { /* @var DisplayGroup $group */ $this->getDispatcher()->dispatch(DisplayGroupLoadEvent::$NAME, new DisplayGroupLoadEvent($group)); + $group->load(); $group->save(['validate' => false, 'saveGroup' => false, 'manageDisplayLinks' => true, 'allowNotify' => $allowNotify]); } } @@ -737,6 +742,7 @@ public function delete() foreach ($this->displayGroups as $displayGroup) { /* @var DisplayGroup $displayGroup */ $this->getDispatcher()->dispatch(DisplayGroupLoadEvent::$NAME, new DisplayGroupLoadEvent($displayGroup)); + $displayGroup->load(); $displayGroup->unassignDisplay($this); $displayGroup->save(['validate' => false, 'manageDynamicDisplayLinks' => false]); } @@ -908,6 +914,8 @@ private function edit() $this->getLog()->debug('Display specific DisplayGroup properties need updating'); $displayGroup = $this->displayGroupFactory->getById($this->displayGroupId); + $this->getDispatcher()->dispatch(DisplayGroupLoadEvent::$NAME, new DisplayGroupLoadEvent($displayGroup)); + $displayGroup->load(); $displayGroup->displayGroup = $this->display; $displayGroup->description = $this->description; $displayGroup->replaceTags($this->tags); diff --git a/tests/LocalWebTestCase.php b/tests/LocalWebTestCase.php index cfb706d632..11fc444ca1 100644 --- a/tests/LocalWebTestCase.php +++ b/tests/LocalWebTestCase.php @@ -279,8 +279,7 @@ public static function setUpBeforeClass() $c->get('store'), $c->get('pool'), $c->get('playerActionService'), - $c->get('scheduleFactory'), - $c->get('dayPartFactory') + $c->get('scheduleFactory') ); }); diff --git a/tests/Middleware/TestXmr.php b/tests/Middleware/TestXmr.php index 470706b7ca..0e7ecdc29b 100644 --- a/tests/Middleware/TestXmr.php +++ b/tests/Middleware/TestXmr.php @@ -89,8 +89,7 @@ public static function setXmr($app, $triggerPlayerActions = true) $app->getContainer()->get('store'), $app->getContainer()->get('pool'), $app->getContainer()->get('playerActionService'), - $app->getContainer()->get('scheduleFactory'), - $app->getContainer()->get('dayPartFactory') + $app->getContainer()->get('scheduleFactory') ); }); }