Skip to content

Commit

Permalink
Fix various Display Group and Display related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMis committed Apr 28, 2021
1 parent 363c1cc commit c2e65f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/Controller/DisplayGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 14 additions & 6 deletions lib/Entity/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand All @@ -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();
}

Expand All @@ -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]);
}
}
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions tests/LocalWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
});

Expand Down
3 changes: 1 addition & 2 deletions tests/Middleware/TestXmr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
});
}
Expand Down

0 comments on commit c2e65f3

Please sign in to comment.