Skip to content

Commit

Permalink
Merge branch '6.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Oct 30, 2017
2 parents 9bb89a9 + 606f7b4 commit 0c27115
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 194 deletions.
69 changes: 69 additions & 0 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Expand Up @@ -960,4 +960,73 @@ public function testLookUpThrowsInvalidArgumentException()
$loadedAlias = $urlAliasService->lookUp(str_repeat('/1', 99), 'ger-DE');
/* END: Use Case */
}

/**
* Test for the lookUp() method after renaming parent which is a part of the lookup path.
*
* @see https://jira.ez.no/browse/EZP-28046
* @covers \eZ\Publish\API\Repository\URLAliasService::lookUp
* @covers \eZ\Publish\API\Repository\URLAliasService::listLocationAliases
*/
public function testLookupOnRenamedParent()
{
$urlAliasService = $this->getRepository()->getURLAliasService();
$locationService = $this->getRepository()->getLocationService();
$contentTypeService = $this->getRepository()->getContentTypeService();
$contentService = $this->getRepository()->getContentService();

// 1. Create new container object (e.g. Folder "My Folder").
$folderContentType = $contentTypeService->loadContentTypeByIdentifier('folder');
$folderCreateStruct = $contentService->newContentCreateStruct($folderContentType, 'eng-GB');
$folderCreateStruct->setField('name', 'My-Folder');

$folderDraft = $contentService->createContent($folderCreateStruct, [
$locationService->newLocationCreateStruct(2),
]);

$folder = $contentService->publishVersion($folderDraft->versionInfo);

// 2. Create new object inside this container (e.g. article "My Article").
$folderLocation = $locationService->loadLocation($folder->contentInfo->mainLocationId);

$articleContentType = $contentTypeService->loadContentTypeByIdentifier('article');
$articleCreateStruct = $contentService->newContentCreateStruct($articleContentType, 'eng-GB');
$articleCreateStruct->setField('title', 'My Article');
$articleCreateStruct->setField(
'intro',
<<< DOCBOOK
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0-variant ezpublish-1.0">
<para>Cache invalidation in eZ</para>
</section>
DOCBOOK
);
$article = $contentService->publishVersion(
$contentService->createContent($articleCreateStruct, [
$locationService->newLocationCreateStruct($folderLocation->id),
])->versionInfo
);
$articleLocation = $locationService->loadLocation($article->contentInfo->mainLocationId);

// 3. Navigate to both of them
$urlAliasService->lookup('/My-Folder');
$urlAliasService->listLocationAliases($folderLocation, false);
$urlAliasService->lookup('/My-Folder/My-Article');
$urlAliasService->listLocationAliases($articleLocation, false);

// 4. Rename "My Folder" to "My Folder Modified".
$folderDraft = $contentService->createContentDraft($folder->contentInfo);
$folderUpdateStruct = $contentService->newContentUpdateStruct();
$folderUpdateStruct->setField('name', 'My Folder Modified');

$contentService->publishVersion(
$contentService->updateContent($folderDraft->versionInfo, $folderUpdateStruct)->versionInfo
);

// 5. Navigate to "Article"
$urlAliasService->lookup('/My-Folder/My-Article');
$aliases = $urlAliasService->listLocationAliases($articleLocation, false);

$this->assertEquals('/My-Folder-Modified/My-Article', $aliases[0]->path);
}
}
7 changes: 5 additions & 2 deletions eZ/Publish/Core/Limitation/ObjectStateLimitationType.php
Expand Up @@ -158,8 +158,11 @@ public function evaluate(APILimitationValue $value, APIUserReference $currentUse
);
}

if ($this->isStateGroupUsedForLimitation($stateGroup->id, $limitationValues)) {
$objectStateIdsToVerify[] = $defaultStateId;
foreach ($states as $state) {
// check using loose types as limitation values are strings and id's can be int
if (in_array($state->id, $limitationValues)) {
$objectStateIdsToVerify[] = $defaultStateId;
}
}
}
} else {
Expand Down
44 changes: 18 additions & 26 deletions eZ/Publish/Core/Persistence/Cache/ObjectStateHandler.php
Expand Up @@ -60,26 +60,22 @@ public function loadGroupByIdentifier($identifier)
*/
public function loadAllGroups($offset = 0, $limit = -1)
{
// Method caches all state groups in cache only uses offset / limit to slice the cached result
$cache = $this->cache->getItem('objectstategroup', 'all');
$groupIds = $cache->get();
$stateGroups = $cache->get();
if ($cache->isMiss()) {
$this->logger->logCall(__METHOD__, array('offset' => $offset, 'limit' => $limit));
$stateGroups = $this->persistenceHandler->objectStateHandler()->loadAllGroups(0, -1);

$groupIds = array();
foreach ($stateGroups as $objectStateGroup) {
$groupCache = $this->cache->getItem('objectstategroup', $objectStateGroup->id);
$groupCache->set($objectStateGroup)->save();
$groupIds[] = $objectStateGroup->id;
}

$cache->set($groupIds)->save();
$cache->set($stateGroups)->save();
$stateGroups = array_slice($stateGroups, $offset, $limit > -1 ?: null);
} else {
$groupIds = array_slice($groupIds, $offset, $limit > -1 ?: null);
$stateGroups = array();
foreach ($groupIds as $groupId) {
$stateGroups[] = $this->loadGroup($groupId);
$stateGroups = array_slice($stateGroups, $offset, $limit > -1 ?: null);
// BC for updates to 6.7LTS installs where cache contains ID's and not objects
// @todo Remove in later branches
foreach ($stateGroups as $key => $stateGroup) {
if (is_numeric($stateGroup)) {
$stateGroups[$key] = $this->loadGroup($stateGroup);
}
}
}

Expand All @@ -92,22 +88,18 @@ public function loadAllGroups($offset = 0, $limit = -1)
public function loadObjectStates($groupId)
{
$cache = $this->cache->getItem('objectstate', 'byGroup', $groupId);
$objectStateIds = $cache->get();
$objectStates = $cache->get();
if ($cache->isMiss()) {
$this->logger->logCall(__METHOD__, array('groupId' => $groupId));

$objectStates = $this->persistenceHandler->objectStateHandler()->loadObjectStates($groupId);

$objectStateIds = array();
foreach ($objectStates as $objectState) {
$objectStateIds[] = $objectState->id;
}

$cache->set($objectStateIds)->save();
$cache->set($objectStates)->save();
} else {
$objectStates = array();
foreach ($objectStateIds as $stateId) {
$objectStates[] = $this->load($stateId);
// BC for updates to 6.7LTS installs where cache contains ID's and not objects
// @todo Remove in later branches
foreach ($objectStates as $key => $state) {
if (is_numeric($state)) {
$objectStates[$key] = $this->load($state);
}
}
}

Expand Down
100 changes: 4 additions & 96 deletions eZ/Publish/Core/Persistence/Cache/Tests/ObjectStateHandlerTest.php
Expand Up @@ -217,12 +217,6 @@ public function generateObjectGroupsArray()
public function testLoadAllGroups($offset = 0, $limit = -1)
{
$testGroups = $this->generateObjectGroupsArray();
$testGroupIds = array_map(
function ($group) {
return $group->id;
},
$testGroups
);

$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$this->cacheMock
Expand Down Expand Up @@ -253,36 +247,10 @@ function ($group) {
->with(0, -1)
->will($this->returnValue($testGroups));

foreach ($testGroups as $group) {
$this->cacheMock
->expects($this->at($group->id))
->method('getItem')
->with('objectstategroup', $group->id)
->will(
$this->returnCallback(
function ($cachekey, $i) use ($group) {
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$cacheItemMock
->expects($this->once())
->method('set')
->with($group)
->will($this->returnValue($cacheItemMock));

$cacheItemMock
->expects($this->once())
->method('save')
->with();

return $cacheItemMock;
}
)
);
}

$cacheItemMock
->expects($this->once())
->method('set')
->with($testGroupIds)
->with($testGroups)
->will($this->returnValue($cacheItemMock));

$cacheItemMock
Expand All @@ -303,12 +271,6 @@ function ($cachekey, $i) use ($group) {
public function testLoadAllGroupsCached($offset = 0, $limit = -1)
{
$testGroups = $this->generateObjectGroupsArray($offset, $limit);
$testGroupIds = array_map(
function ($group) {
return $group->id;
},
$testGroups
);

$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$this->cacheMock
Expand All @@ -319,35 +281,14 @@ function ($group) {
$cacheItemMock
->expects($this->once())
->method('get')
->will($this->returnValue($testGroupIds));
->will($this->returnValue($testGroups));
$cacheItemMock
->expects($this->once())
->method('isMiss')
->will($this->returnValue(false));

$expectedGroups = array_slice($testGroups, $offset, $limit > -1 ?: null);

// loadGroup()
foreach ($expectedGroups as $i => $group) {
$this->cacheMock
->expects($this->at($i + 1))
->method('getItem')
->with('objectstategroup', $group->id)
->will(
$this->returnCallback(
function ($cachekey, $i) use ($group) {
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$cacheItemMock
->expects($this->once())
->method('get')
->will($this->returnValue($group));

return $cacheItemMock;
}
)
);
}

$handler = $this->persistenceCacheHandler->objectStateHandler();
$groups = $handler->loadAllGroups($offset, $limit);
$this->assertEquals($groups, $expectedGroups);
Expand Down Expand Up @@ -397,12 +338,6 @@ public function testLoadObjectStates()
)
),
);
$testStateIds = array_map(
function ($state) {
return $state->id;
},
$testStates
);

$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$this->cacheMock
Expand Down Expand Up @@ -436,7 +371,7 @@ function ($state) {
$cacheItemMock
->expects($this->once())
->method('set')
->with($testStateIds)
->with($testStates)
->will($this->returnValue($cacheItemMock));

$cacheItemMock
Expand Down Expand Up @@ -477,12 +412,6 @@ public function testLoadObjectStatesCached()
)
),
);
$testStateIds = array_map(
function ($state) {
return $state->id;
},
$testStates
);

$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$this->cacheMock
Expand All @@ -493,33 +422,12 @@ function ($state) {
$cacheItemMock
->expects($this->once())
->method('get')
->will($this->returnValue($testStateIds));
->will($this->returnValue($testStates));
$cacheItemMock
->expects($this->once())
->method('isMiss')
->will($this->returnValue(false));

// load()
foreach ($testStates as $i => $state) {
$this->cacheMock
->expects($this->at($i + 1))
->method('getItem')
->with('objectstate', $state->id)
->will(
$this->returnCallback(
function ($cachekey, $i) use ($state) {
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
$cacheItemMock
->expects($this->once())
->method('get')
->will($this->returnValue($state));

return $cacheItemMock;
}
)
);
}

$handler = $this->persistenceCacheHandler->objectStateHandler();
$states = $handler->loadObjectStates(1);
$this->assertEquals($states, $testStates);
Expand Down

0 comments on commit 0c27115

Please sign in to comment.