Skip to content

Commit

Permalink
Allow setting version creator of content; allow setting publication_d…
Browse files Browse the repository at this point in the history
…ate on content creation
  • Loading branch information
gggeek committed Oct 20, 2016
1 parent 612071c commit 1d46455
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
34 changes: 32 additions & 2 deletions Core/Executor/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']) ||
Expand Down
7 changes: 5 additions & 2 deletions Resources/doc/DSL/ManageContent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Tests/dsl/good/UnitTestOK004_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
content_type: reference:kmb_test_2
main_location: 2
section: 3
owner: admin
attributes:
- ezstring: hello world 1
object_states:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion WHATSNEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1d46455

Please sign in to comment.