Skip to content

Commit

Permalink
EZP-31310: Fixed VersionDraftConflict for content having multiple loc…
Browse files Browse the repository at this point in the history
…ations (#1237)
  • Loading branch information
mikadamczyk authored Feb 18, 2020
1 parent d23c668 commit e983ad7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
19 changes: 16 additions & 3 deletions src/bundle/Controller/Content/VersionDraftConflictController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ public function __construct(
/**
* @param int $contentId
* @param string $languageCode
* @param int|null $locationId
*
* @return Response
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function draftHasNoConflictAction(int $contentId, string $languageCode): Response
{
public function draftHasNoConflictAction(
int $contentId,
string $languageCode,
?int $locationId = null
): Response {
$content = $this->contentService->loadContent($contentId);
$location = $this->locationService->loadLocation($content->contentInfo->mainLocationId);
$contentInfo = $content->contentInfo;

try {
Expand All @@ -89,6 +93,15 @@ public function draftHasNoConflictAction(int $contentId, string $languageCode):
$versionsDataset = $this->datasetFactory->versions();
$versionsDataset->load($contentInfo);
$conflictedDrafts = $versionsDataset->getConflictedDraftVersions($contentInfo->currentVersionNo, $languageCode);
$locationId = $locationId ?? $contentInfo->mainLocationId;
try {
$location = $this->locationService->loadLocation($locationId);
} catch (UnauthorizedException $e) {
// Will return list of locations user has *read* access to, or empty array if none
$availableLocations = $this->locationService->loadLocations($contentInfo);
// will return null if array of availableLocations is empty
$location = array_shift($availableLocations);
}

$modalContent = $this->renderView('@ezdesign/content/modal_draft_conflict.html.twig', [
'conflicted_drafts' => $conflictedDrafts,
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,12 @@ ezplatform.version.has_no_conflict:
languageCode: ~

ezplatform.version_draft.has_no_conflict:
path: /version-draft/has-no-conflict/{contentId}/{languageCode}
path: /version-draft/has-no-conflict/{contentId}/{languageCode}/{locationId}
options:
expose: true
defaults:
_controller: 'EzPlatformAdminUiBundle:Content\VersionDraftConflict:draftHasNoConflict'
locationId: ~

# LocationView / Locations tab

Expand Down
5 changes: 3 additions & 2 deletions src/bundle/Resources/public/js/scripts/admin.location.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
},
currentLanguage: mfuContainer.dataset.currentLanguage,
};
const handleEditItem = (content) => {
const handleEditItem = (content, location) => {
const contentId = content._id;
const locationId = location._id;
const languageCode = content.mainLanguageCode;
const checkVersionDraftLink = Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode });
const checkVersionDraftLink = Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode, locationId });
const submitVersionEditForm = () => {
doc.querySelector('#form_subitems_content_edit_content_info').value = contentId;
doc.querySelector(`#form_subitems_content_edit_language_${languageCode}`).checked = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
const form = editActions.querySelector('form');
const contentIdInput = form.querySelector('#content_edit_content_info') || form.querySelector('#user_edit_content_info');
const contentId = contentIdInput.value;
const locationInput = form.querySelector('#content_edit_location') || form.querySelector('#user_edit_location');
const locationId = locationInput.value;
const resetRadioButtons = () =>
btns.forEach((btn) => {
btn.checked = false;
Expand Down Expand Up @@ -48,7 +50,10 @@
const changeHandler = (event) => {
const checkedBtn = event.currentTarget;
const languageCode = checkedBtn.value;
const checkVersionDraftLink = global.Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode });
const checkVersionDraftLink = global.Routing.generate(
'ezplatform.version_draft.has_no_conflict',
{ contentId, languageCode, locationId }
);

fetch(checkVersionDraftLink, {
credentials: 'same-origin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'contentId': version.contentInfo.id,
'versionNo': version.versionNo,
'language': version.initialLanguageCode,
'locationId': location.id
'locationId': location.id ?? null
})
%}

Expand Down

0 comments on commit e983ad7

Please sign in to comment.