Skip to content

Commit

Permalink
EZP-24842: [PostgreSQL] Fixed identifier letters case inconsistencies (
Browse files Browse the repository at this point in the history
…ezsystems#66)

* EZP-24842: [PostgreSQL] Ensured Role name always starts w/ uppercase

* EZP-24842: [PostgreSQL] Aligned Content Type identifier char case

* fixup! EZP-24842: [PostgreSQL] Ensured Role name always starts w/ uppercase
  • Loading branch information
alongosz authored and andrerom committed Jul 28, 2017
1 parent 3825099 commit 99db7fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 9 additions & 1 deletion Context/EzContext.php
Expand Up @@ -254,7 +254,15 @@ protected function getCredentialsFor( $roleIdentifier )
$role = $this->getRepository()->sudo(
function() use ( $roleService, $roleIdentifier )
{
return $roleService->loadRoleByIdentifier( $roleIdentifier );
// make sure role name starts with uppercase as this is what default setup provides
if ($roleIdentifier !== ucfirst($roleIdentifier)) {
@trigger_error(
"'{$roleIdentifier}' role name should start with uppercase letter",
E_USER_DEPRECATED
);
}

return $roleService->loadRoleByIdentifier(ucfirst($roleIdentifier));
}
);

Expand Down
5 changes: 4 additions & 1 deletion Context/Object/ContentType.php
Expand Up @@ -124,7 +124,7 @@ public function assertContentTypeExistsByIdentifierOnGroup($identifier, $groupId
{
Assertion::assertTrue(
$this->checkContentTypeExistenceByIdentifier($identifier, $groupIdentifier),
"Couldn't find Content Type with identifier '$identifier' on '$groupIdentifier."
"Couldn't find Content Type with identifier '$identifier' on '$groupIdentifier'."
);
}

Expand Down Expand Up @@ -240,6 +240,9 @@ protected function assignContentGroupTypeToContentType($contentType, $contentTyp
*/
protected function checkContentTypeExistenceByIdentifier($identifier, $groupIdentifier = null)
{
// @see ensureContentTypeWithIdentifier
$identifier = strtolower($identifier);

$contentType = $this->loadContentTypeByIdentifier($identifier, false);
if ($contentType && $groupIdentifier) {
$contentTypeGroups = $contentType->getContentTypeGroups();
Expand Down
22 changes: 19 additions & 3 deletions ObjectManager/Role.php
Expand Up @@ -36,13 +36,22 @@ function() use( $repository, $name, $that )
{
$role = null;
$roleService = $repository->getRoleService();

// make sure role name starts with uppercase as this is what default setup provides
if ($name !== ucfirst($name)) {
@trigger_error(
"'{$name}' role name should start with uppercase letter",
E_USER_DEPRECATED
);
}

try
{
$role = $roleService->loadRoleByIdentifier( $name );
$role = $roleService->loadRoleByIdentifier(ucfirst($name));
}
catch ( ApiExceptions\NotFoundException $e )
{
$roleCreateStruct = $roleService->newRoleCreateStruct( $name );
$roleCreateStruct = $roleService->newRoleCreateStruct(ucfirst($name));
$roleDraft = $roleService->createRole( $roleCreateStruct );
$roleService->publishRoleDraft($roleDraft);
$role = $roleService->loadRole($roleDraft->id);
Expand Down Expand Up @@ -74,7 +83,14 @@ function() use( $repository, $identifier )
$roleService = $repository->getRoleService();
try
{
$role = $roleService->loadRoleByIdentifier( $identifier );
// make sure role name starts with uppercase as this is what default setup provides
if ($identifier !== ucfirst($identifier)) {
@trigger_error(
"'{$identifier}' role name should start with uppercase letter",
E_USER_DEPRECATED
);
}
$role = $roleService->loadRoleByIdentifier(ucfirst($identifier));
}
catch ( ApiExceptions\NotFoundException $e )
{
Expand Down

0 comments on commit 99db7fe

Please sign in to comment.