Skip to content

Commit

Permalink
allow to load tags and set refs to their attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Sep 30, 2017
1 parent 48ad34f commit 4999f9a
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 4 deletions.
46 changes: 45 additions & 1 deletion Core/Executor/TagManager.php
Expand Up @@ -11,7 +11,7 @@
class TagManager extends RepositoryExecutor
{
protected $supportedStepTypes = array('tag');
protected $supportedActions = array('create', 'delete');
protected $supportedActions = array('create', 'load', 'delete');

protected $tagService;
/**
Expand Down Expand Up @@ -73,6 +73,22 @@ protected function create($step)
return $tag;
}

protected function load($step)
{
$this->checkTagsBundleInstall();

$tagsCollection = $this->matchTags('load', $step);

// This check is already done in setReferences
/*if (count($contentTypeCollection) > 1 && isset($step->dsl['references'])) {
throw new \Exception("Can not execute Content Type load because multiple contents match, and a references section is specified in the dsl. References can be set when only 1 content matches");
}*/

$this->setReferences($tagsCollection, $step);

return $tagsCollection;
}

protected function update($step)
{
$this->checkTagsBundleInstall();
Expand Down Expand Up @@ -114,6 +130,8 @@ protected function matchTags($action, $step)
/**
* @param $object
* @return bool
*
* @todo add support for keyword (with language),
*/
protected function setReferences($object, $step)
{
Expand All @@ -122,13 +140,39 @@ protected function setReferences($object, $step)
}

$references = $this->setReferencesCommon($object, $step->dsl['references']);
/** @var \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $object */
$object = $this->insureSingleEntity($object, $references);

foreach ($references as $reference) {
switch ($reference['attribute']) {
case 'id':
case 'tag_id':
$value = $object->id;
break;
case 'always_available':
$value = $object->alwaysAvailable;
break;
case 'depth':
$value = $object->depth;
break;
case 'main_language_code':
$value = $object->mainLanguageCode;
break;
case 'main_tag_id':
$value = $object->mainTagId;
break;
case 'modification_date':
$value = $object->modificationDate->getTimestamp();
break;
case 'path':
$value = $object->pathString;
break;
case 'parent_tag_id':
$value = $object->parentTagId;
break;
case 'remote_id':
$value = $object->remoteId;
break;
default:
throw new \InvalidArgumentException('Tag Manager does not support setting references for attribute ' . $reference['attribute']);
}
Expand Down
17 changes: 16 additions & 1 deletion Resources/doc/DSL/Tags.yml
Expand Up @@ -11,7 +11,7 @@
-
type: tag
mode: delete
match: # The locations to update
match: # The tags to delete
# Possible values for matching. only one of them is allowed at a time. All of them can be single or array
id: # the id(s) of the tag(s) we want to delete
remote_id: # the remote id(s) of the tag(s) we want to delete
Expand All @@ -26,3 +26,18 @@
_condition_: value # where _condition_ can be any of ones specified above, including 'and' and 'or'
-
_condition_: value # where _condition_ can be any of ones specified above, including 'and' and 'or'
references: # Optional
identifier: referenceId # A string used to identify the reference
attribute: attributeId # The attribute to get the value of for the reference
# supports: always_available, depth, main_language_code, main_tag_id, modification_date,
# path, parent_tag_id, remote_id

-
type: tag
mode: load
match: # The tag(s) to load
references: # Optional
identifier: referenceId # A string used to identify the reference
attribute: attributeId # The attribute to get the value of for the reference
# supports: always_available, depth, main_language_code, main_tag_id, modification_date,
# path, parent_tag_id, remote_id
65 changes: 64 additions & 1 deletion Tests/dsl/eztags/v2/UnitTestOK019_eztagsv2.yml
Expand Up @@ -18,7 +18,7 @@
-
type: tag
mode: create
#parent_tag_id: 1
#parent_tag_id: 0
main_language_code: eng-GB
always_available: true
remote_id: article_tag_remote_id
Expand All @@ -28,6 +28,69 @@
-
identifier: article_tag_id
attribute: id
-
type: tag
mode: load
match:
id: reference:article_tag_id
references:
-
identifier: article_tag_id_2
attribute: id
-
identifier: article_tag_always_available
attribute: always_available
-
identifier: article_tag_depth
attribute: depth
-
identifier: article_tag_main_language_code
attribute: main_language_code
-
identifier: article_tag_main_tag_id
attribute: main_tag_id
-
identifier: article_tag_modification_date
attribute: modification_date
-
identifier: article_tag_path
attribute: path
-
identifier: article_tag_parent_tag_id
attribute: parent_tag_id
-
identifier: article_tag_remote_id
attribute: remote_id
-
type: assert
target: reference
identifier: reference:article_tag_always_available
test:
equals: true
-
type: assert
target: reference
identifier: reference:article_tag_depth
test:
equals: 1
-
type: assert
target: reference
identifier: reference:article_tag_main_language_code
test:
equals: eng-GB
-
type: assert
target: reference
identifier: reference:article_tag_parent_tag_id
test:
equals: 0
-
type: assert
target: reference
identifier: reference:article_tag_remote_id
test:
equals: article_tag_remote_id
-
type: content_type
mode: update
Expand Down
65 changes: 64 additions & 1 deletion Tests/dsl/eztags/v3/UnitTestOK019_eztagsv3.yml
Expand Up @@ -18,7 +18,7 @@
-
type: tag
mode: create
#parent_tag_id: 1
#parent_tag_id: 0
main_language_code: eng-GB
always_available: true
remote_id: article_tag_remote_id
Expand All @@ -28,6 +28,69 @@
-
identifier: article_tag_id
attribute: id
-
type: tag
mode: load
match:
id: reference:article_tag_id
references:
-
identifier: article_tag_id_2
attribute: id
-
identifier: article_tag_always_available
attribute: always_available
-
identifier: article_tag_depth
attribute: depth
-
identifier: article_tag_main_language_code
attribute: main_language_code
-
identifier: article_tag_main_tag_id
attribute: main_tag_id
-
identifier: article_tag_modification_date
attribute: modification_date
-
identifier: article_tag_path
attribute: path
-
identifier: article_tag_parent_tag_id
attribute: parent_tag_id
-
identifier: article_tag_remote_id
attribute: remote_id
-
type: assert
target: reference
identifier: reference:article_tag_always_available
test:
equals: true
-
type: assert
target: reference
identifier: reference:article_tag_depth
test:
equals: 1
-
type: assert
target: reference
identifier: reference:article_tag_main_language_code
test:
equals: eng-GB
-
type: assert
target: reference
identifier: reference:article_tag_parent_tag_id
test:
equals: 0
-
type: assert
target: reference
identifier: reference:article_tag_remote_id
test:
equals: article_tag_remote_id
-
type: content_type
mode: update
Expand Down
3 changes: 3 additions & 0 deletions WHATSNEW.md
Expand Up @@ -12,6 +12,9 @@ Version 4.1 (unreleased)

* New: allow to set references to the 'version_count' of a Content

* New: allow to set references to the properties of a Tag: always_available, depth, main_language_code, main_tag_id, modification_date, path, parent_tag_id, remote_id

* New: operation 'load' 'tag' can be used to set references to existing tags properties

Version 4.0
===========
Expand Down

0 comments on commit 4999f9a

Please sign in to comment.