From 1d46455145095bb738091fcf9d99d216fefa6953 Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 20 Oct 2016 13:53:35 +0100 Subject: [PATCH] Allow setting version creator of content; allow setting publication_date on content creation --- Core/Executor/ContentManager.php | 34 ++++++++++++++++++++++-- Resources/doc/DSL/ManageContent.yml | 7 +++-- Tests/dsl/good/UnitTestOK004_content.yml | 5 ++++ WHATSNEW.md | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Core/Executor/ContentManager.php b/Core/Executor/ContentManager.php index ac702372..d7ae92cd 100644 --- a/Core/Executor/ContentManager.php +++ b/Core/Executor/ContentManager.php @@ -76,6 +76,17 @@ protected function create() $contentCreateStruct->ownerId = $owner->id; } + // This is a bit tricky, as the eZPublish API does not support having a different creator and owner with only 1 version. + // We allow it, hoping that nothing gets broken because of it + if (isset($this->dsl['version_creator'])) { + $realContentOwnerId = $contentCreateStruct->ownerId; + if ($realContentOwnerId == null) { + $realContentOwnerId = $this->repository->getCurrentUser()->id; + } + $versionCreator = $this->getUser($this->dsl['version_creator']); + $contentCreateStruct->ownerId = $versionCreator->id; + } + if (isset($this->dsl['modification_date'])) { $contentCreateStruct->modificationDate = new \DateTime($this->dsl['modification_date']); } @@ -127,6 +138,20 @@ protected function create() $this->setObjectStates($content, $this->dsl['object_states']); } + // 2nd part of the hack: re-set the content owner to its intended value + if (isset($this->dsl['version_creator']) || isset($this->dsl['publication_date'])) { + $contentMetaDataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); + + if (isset($this->dsl['version_creator'])) { + $contentMetaDataUpdateStruct->ownerId = $realContentOwnerId; + } + if (isset($this->dsl['publication_date'])) { + $contentMetaDataUpdateStruct->publishedDate = new \DateTime($this->dsl['publication_date']); + } + + $contentService->updateContentMetadata($content->contentInfo, $contentMetaDataUpdateStruct); + } + $this->setReferences($content); return $content; @@ -163,8 +188,13 @@ protected function update() $this->setFields($contentUpdateStruct, $this->dsl['attributes'], $contentType); } - $draft = $contentService->createContentDraft($contentInfo); - $contentService->updateContent($draft->versionInfo,$contentUpdateStruct); + $versionCreator = null; + if (isset($this->dsl['version_creator'])) { + $versionCreator = $this->getUser($this->dsl['version_creator']); + } + + $draft = $contentService->createContentDraft($contentInfo, null, $versionCreator); + $contentService->updateContent($draft->versionInfo, $contentUpdateStruct); $content = $contentService->publishVersion($draft->versionInfo); if (isset($this->dsl['new_remote_id']) || isset($this->dsl['new_remote_id']) || diff --git a/Resources/doc/DSL/ManageContent.yml b/Resources/doc/DSL/ManageContent.yml index 2dd37c1b..34a8f6a4 100644 --- a/Resources/doc/DSL/ManageContent.yml +++ b/Resources/doc/DSL/ManageContent.yml @@ -13,7 +13,9 @@ lang: xxx-YY # Optional, will fallback to default language if not provided (--default-language option or 'eng-GB' by default) section: x # string|int Optional section id or identifier owner: xxx # user id, login or email if unique; Optional, set the content owner + version_creator: yyy # user id, login or email if unique; Optional, set the creator of the 1st version modification_date: zzz # Optional, set content modification date (for formats, see: http://php.net/manual/en/datetime.formats.php) + publication_date: zzz # Optional, set content publication date (for formats, see: http://php.net/manual/en/datetime.formats.php) attributes: attribute1: value1 attribute2: value2 @@ -70,9 +72,10 @@ content_type: yyy # string|string[] a content type identifier lang: xxx-YY # Optional, will fallback to default language if not provided (--default-language option or 'eng-GB' by default) section: x # string|int Optional section id or identifier - owner: xxx # user id, login or email if unique; Optional, set the content owner + owner: xxx # user id, login or email if unique; Optional, set the content owner (original creator) + version_creator: yyy # user id, login or email if unique; Optional, set the creator of the new version modification_date: zzz # Optional, set content modification date (for formats, see: http://php.net/manual/en/datetime.formats.php) - publication_date: zzz # Optional, set content modification date (for formats, see: http://php.net/manual/en/datetime.formats.php) + publication_date: zzz # Optional, set content publication date (for formats, see: http://php.net/manual/en/datetime.formats.php) new_remote_id: xxx # string Optional set a new RemoteId attributes: # the list of attribute identifier value pairs. For the format to use, see above attribute1: value1 diff --git a/Tests/dsl/good/UnitTestOK004_content.yml b/Tests/dsl/good/UnitTestOK004_content.yml index 201e6560..1b87fc69 100644 --- a/Tests/dsl/good/UnitTestOK004_content.yml +++ b/Tests/dsl/good/UnitTestOK004_content.yml @@ -124,6 +124,7 @@ content_type: reference:kmb_test_2 main_location: 2 section: 3 + owner: admin attributes: - ezstring: hello world 1 object_states: @@ -162,6 +163,8 @@ sort_field: path sort_order: DESC modification_date: "2006:07:08 18:11:31" + publication_date: "2005:08:09 18:11:31" + version_creator: anonymous attributes: ezstring: hello world 3 references: @@ -213,6 +216,8 @@ - ezimage: blank.jpg - ezbinaryfile: emptyfile.txt section: users + version_creator: 14 + owner: 10 new_remote_id: is_this_a_very_unlikely_remoteid modification_date: "2008:07:06 18:11:31" publication_date: "2007:08:09 18:11:31" diff --git a/WHATSNEW.md b/WHATSNEW.md index b56ec6ba..ada54d46 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -16,7 +16,7 @@ Version 3.0.0-beta3 * New: it is now possible to assign a section when creating and updating Contents -* New: it is now possible to assign an owner when creating and updating Contents +* New: it is now possible to assign an owner and a version creator when creating and updating Contents * New: it is now possible to set publication and modification dates when creating and updating Contents