Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout import : Fix Playlist closure table. #2780

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions lib/Entity/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@
// Clone the regions
$this->regions = array_map(function ($object) { return clone $object; }, $this->regions);
// Clone drawers
$this->drawers = array_map(function ($object) { return clone $object; }, $this->drawers);

Check failure on line 474 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must be the last content on the line

Check failure on line 474 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Closing brace must be on a line by itself

Check failure on line 474 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Each PHP statement must be on a line by itself
// Clone actions
$this->actions = array_map(function ($object) { return clone $object; }, $this->actions);

Check failure on line 476 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must be the last content on the line

Check failure on line 476 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Closing brace must be on a line by itself
}

/**
Expand All @@ -488,7 +488,7 @@
$statusMessages = $this->getStatusMessage();
$countMessages = is_array($statusMessages) ? count($statusMessages) : 0;

return sprintf('Layout %s - %d x %d. Regions = %d, Drawers = %d, Tags = %d. layoutId = %d. Status = %d, messages %d', $this->layout, $this->width, $this->height, $countRegions, $countDrawers, $countTags, $this->layoutId, $this->status, $countMessages);

Check warning on line 491 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 260 characters
}

/**
Expand All @@ -496,7 +496,7 @@
*/
private function hash()
{
return md5($this->layoutId . $this->ownerId . $this->campaignId . $this->backgroundImageId . $this->backgroundColor . $this->width . $this->height . $this->status . $this->description . json_encode($this->statusMessage) . $this->publishedStatusId . json_encode($this->actions));

Check warning on line 499 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 286 characters
}

/**
Expand Down Expand Up @@ -1049,7 +1049,7 @@
$this->getStore()->update('DELETE FROM `lklayoutdisplaygroup` WHERE layoutId = :layoutId', ['layoutId' => $this->layoutId]);

// Remove any display group links
$this->getStore()->update('DELETE FROM `schedule_sync` WHERE layoutId = :layoutId', ['layoutId' => $this->layoutId]);

Check warning on line 1052 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 129 characters
} else {
// Remove the draft from any Campaign assignments
$this->getStore()->update('DELETE FROM `lkcampaignlayout` WHERE layoutId = :layoutId', ['layoutId' => $this->layoutId]);
Expand Down Expand Up @@ -1127,7 +1127,7 @@
if ($this->code != null) {

if (!v::alnum('_')->validate($this->code)) {
throw new InvalidArgumentException(__('Please use only alphanumeric characters in Layout Code identifier', 'code'));

Check warning on line 1130 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 132 characters
}

$duplicateCode = $this->layoutFactory->query(null, [
Expand Down Expand Up @@ -2644,11 +2644,11 @@
// getById would fail here and prevent adding new Layout in web ui
try {
$folder = $this->folderFactory->getById($campaign->folderId);
$campaign->permissionsFolderId = ($folder->getPermissionFolderId() == null) ? $folder->id : $folder->getPermissionFolderId();

Check warning on line 2647 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 141 characters
} catch (NotFoundException $exception) {
$campaign->permissionsFolderId = 1;
}
$campaign->save(['validate' => false, 'notify' => $options['notify'], 'collectNow' => $options['collectNow'], 'layoutCode' => $this->code]);

Check warning on line 2651 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 152 characters
}
}

Expand Down Expand Up @@ -2681,29 +2681,34 @@
$child = $assignedPlaylistIds;
}
}
}
}

if (isset($parentId) && isset($child)) {
foreach ($child as $childId) {
$this->getLog()->debug('Manage closure table for parent ' . $parentId . ' and child ' . $childId);

if ($this->getStore()->exists('SELECT parentId, childId, depth FROM lkplaylistplaylist WHERE childId = :childId AND parentId = :parentId ', [//phpcs:ignore
'parentId' => $parentId,
'childId' => $childId
])) {
throw new InvalidArgumentException(__('Cannot add the same SubPlaylist twice.'), 'playlistId');
}
if (isset($parentId) && isset($child)) {
foreach ($child as $childId) {
$this->getLog()->debug(
'Manage closure table for parent ' . $parentId . ' and child ' . $childId
);

if ($this->getStore()->exists('SELECT parentId, childId, depth FROM lkplaylistplaylist WHERE childId = :childId AND parentId = :parentId ', [//phpcs:ignore
'parentId' => $parentId,
'childId' => $childId
])) {
throw new InvalidArgumentException(
__('Cannot add the same SubPlaylist twice.'),
'playlistId'
);
}

$this->getStore()->insert('
$this->getStore()->insert('
INSERT INTO `lkplaylistplaylist` (parentId, childId, depth)
SELECT p.parentId, c.childId, p.depth + c.depth + 1
FROM lkplaylistplaylist p, lkplaylistplaylist c
WHERE p.childId = :parentId AND c.parentId = :childId
', [
'parentId' => $parentId,
'childId' => $childId
]);
'parentId' => $parentId,
'childId' => $childId
]);
}
}
}
}
}
Expand Down Expand Up @@ -2753,7 +2758,7 @@
if ($action->targetId != null) {
foreach ($combined as $old => $new) {
if ($old == $action->targetId) {
$this->getLog()->debug('Layout Import, switching Layout Action target ID from ' . $old . ' to ' . $new);

Check warning on line 2761 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 128 characters
$action->targetId = $new;
}
}
Expand All @@ -2764,7 +2769,7 @@

foreach ($combinedWidgets as $old => $new) {
if ($old == $action->widgetId && $action->actionType == 'navWidget') {
$this->getLog()->debug('Layout Import, switching Widget Action widget ID from ' . $old . ' to ' . $new);

Check warning on line 2772 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 128 characters
$action->widgetId = $new;
}
}
Expand All @@ -2783,12 +2788,12 @@

foreach ($combined as $old => $new) {
if ($old == $action->targetId) {
$this->getLog()->debug('Layout Import, switching Region Action target ID from ' . $old . ' to ' . $new);

Check warning on line 2791 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 124 characters
$action->targetId = $new;
}

if ($action->sourceId === $old) {
$this->getLog()->debug('Layout Import, switching Region Action source ID from ' . $old . ' to ' . $new);

Check warning on line 2796 in lib/Entity/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 124 characters
$action->sourceId = $new;
}
}
Expand Down
Loading