diff --git a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclHelper.php b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclHelper.php index 21d845c665..d5a70d67bd 100644 --- a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclHelper.php +++ b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclHelper.php @@ -147,9 +147,9 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi private function getPermittedAclIdsSQLForUser(Query $query) { $aclConnection = $this->em->getConnection(); - $databasePrefix = is_file($aclConnection->getDatabase()) ? '' : $aclConnection->getDatabase().'.'; + $stringQuoteChar = $aclConnection->getDatabasePlatform()->getStringLiteralQuoteCharacter(); $mask = $query->getHint('acl.mask'); - $rootEntity = '"' . str_replace('\\', '\\\\', $query->getHint('acl.root.entity')) . '"'; + $rootEntity = $stringQuoteChar . $query->getHint('acl.root.entity') . $stringQuoteChar; /* @var $token TokenInterface */ $token = $this->tokenStorage->getToken(); @@ -166,18 +166,18 @@ private function getPermittedAclIdsSQLForUser(Query $query) } // Security context does not provide anonymous role automatically. - $uR = array('"IS_AUTHENTICATED_ANONYMOUSLY"'); + $uR = array($stringQuoteChar . 'IS_AUTHENTICATED_ANONYMOUSLY' . $stringQuoteChar); foreach ($userRoles as $role) { // The reason we ignore this is because by default FOSUserBundle adds ROLE_USER for every user if (is_string($role)) { if ($role !== 'ROLE_USER') { - $uR[] = '"' . $role . '"'; + $uR[] = $stringQuoteChar . $role . $stringQuoteChar; } } else { // Symfony 3.4 compatibility if ($role->getRole() !== 'ROLE_USER') { - $uR[] = '"' . $role->getRole() . '"'; + $uR[] = $stringQuoteChar . $role->getRole() . $stringQuoteChar; } } } @@ -185,21 +185,22 @@ private function getPermittedAclIdsSQLForUser(Query $query) $inString = implode(' OR s.identifier = ', $uR); if (\is_object($user)) { - $inString .= ' OR s.identifier = "' . str_replace( - '\\', - '\\\\', - \get_class($user) - ) . '-' . $user->getUserName() . '"'; + $inString .= ' OR s.identifier = ' . $stringQuoteChar . get_class($user) . '-' . $user->getUserName() . $stringQuoteChar; + } + + $objectIdentifierColumn = 'o.object_identifier'; + if ($aclConnection->getDatabasePlatform()->getName() === 'postgresql') { + $objectIdentifierColumn = 'o.object_identifier::BIGINT'; } $selectQuery = <<getDatabasePlatform()->getIsNullExpression('e.object_identity_id')}) ) -LEFT JOIN {$databasePrefix}acl_security_identities s ON ( +LEFT JOIN acl_security_identities s ON ( s.id = e.security_identity_id ) WHERE c.class_type = {$rootEntity} diff --git a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclNativeHelper.php b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclNativeHelper.php index 9490044225..0cad501ff6 100644 --- a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclNativeHelper.php +++ b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclNativeHelper.php @@ -67,14 +67,14 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi } $aclConnection = $this->em->getConnection(); + $stringQuoteChar = $aclConnection->getDatabasePlatform()->getStringLiteralQuoteCharacter(); - $databasePrefix = is_file($aclConnection->getDatabase()) ? '' : $aclConnection->getDatabase().'.'; $rootEntity = $permissionDef->getEntity(); $linkAlias = $permissionDef->getAlias(); // Only tables with a single ID PK are currently supported $linkField = $this->em->getClassMetadata($rootEntity)->getSingleIdentifierColumnName(); - $rootEntity = '"' . str_replace('\\', '\\\\', $rootEntity) . '"'; + $rootEntity = $stringQuoteChar . $rootEntity . $stringQuoteChar; $query = $queryBuilder; $builder = new MaskBuilder(); @@ -99,18 +99,18 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi } // Security context does not provide anonymous role automatically. - $uR = array('"IS_AUTHENTICATED_ANONYMOUSLY"'); + $uR = array($stringQuoteChar . 'IS_AUTHENTICATED_ANONYMOUSLY' . $stringQuoteChar); foreach ($userRoles as $role) { // The reason we ignore this is because by default FOSUserBundle adds ROLE_USER for every user if (is_string($role)) { if ($role !== 'ROLE_USER') { - $uR[] = '"' . $role . '"'; + $uR[] = $stringQuoteChar . $role . $stringQuoteChar; } } else { // Symfony 3.4 compatibility if ($role->getRole() !== 'ROLE_USER') { - $uR[] = '"' . $role->getRole() . '"'; + $uR[] = $stringQuoteChar . $role->getRole() . $stringQuoteChar; } } } @@ -118,21 +118,22 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi $inString = implode(' OR s.identifier = ', $uR); if (\is_object($user)) { - $inString .= ' OR s.identifier = "' . str_replace( - '\\', - '\\\\', - \get_class($user) - ) . '-' . $user->getUserName() . '"'; + $inString .= ' OR s.identifier = ' . $stringQuoteChar . \get_class($user) . '-' . $user->getUserName() . $stringQuoteChar; + } + + $objectIdentifierColumn = 'o.object_identifier'; + if ($aclConnection->getDatabasePlatform()->getName() === 'postgresql') { + $objectIdentifierColumn = 'o.object_identifier::BIGINT'; } $joinTableQuery = <<getDatabasePlatform()->getIsNullExpression('e.object_identity_id')}) ) -LEFT JOIN {$databasePrefix}acl_security_identities s ON ( +LEFT JOIN acl_security_identities s ON ( s.id = e.security_identity_id ) WHERE c.class_type = {$rootEntity} diff --git a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclWalker.php b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclWalker.php index 911e763b56..21ef8fe091 100644 --- a/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclWalker.php +++ b/src/Kunstmaan/AdminBundle/Helper/Security/Acl/AclWalker.php @@ -24,9 +24,18 @@ public function walkFromClause($fromClause) $tableAlias = $this->getSQLTableAlias($name, $alias); $extraQuery = $this->getQuery()->getHint('acl.extra.query'); - $tempAclView = <<getConnection()->getDatabasePlatform()->getName()) { + case 'postgresql': + $tempAclView = <<createQueryBuilder('e') ->update() - ->set('e.isResolved', 1) - ->where('e.isResolved = 0') + ->set('e.isResolved', ':resolved') + ->where('e.isResolved = :unresolved') + ->setParameter('resolved', true) + ->setParameter('unresolved', false) ->getQuery() ->getSingleScalarResult(); } @@ -36,7 +38,8 @@ public function findExceptionStatistics() { return $this->createQueryBuilder('e') ->select('COUNT(e.id) as cp_all, SUM(e.events) as cp_sum') - ->where('e.isResolved = 0') + ->where('e.isResolved = :isResolved') + ->setParameter('isResolved', false) ->getQuery() ->getOneOrNullResult(); } diff --git a/src/Kunstmaan/AdminBundle/Repository/UserRepository.php b/src/Kunstmaan/AdminBundle/Repository/UserRepository.php index b5149a0082..cee5ed7fd6 100644 --- a/src/Kunstmaan/AdminBundle/Repository/UserRepository.php +++ b/src/Kunstmaan/AdminBundle/Repository/UserRepository.php @@ -29,8 +29,9 @@ public function getUsersByRole($role) ->from('KunstmaanAdminBundle:User', 'u') ->innerJoin('u.groups', 'g') ->innerJoin('g.roles', 'r') - ->where('u.enabled=1') + ->where('u.enabled=:enabled') ->andWhere('r.role IN (:roles)') + ->setParameter('enabled', true) ->setParameter('roles', $roles); return $qb->getQuery()->getResult(); diff --git a/src/Kunstmaan/AdminBundle/Resources/doc/Permissions.md b/src/Kunstmaan/AdminBundle/Resources/doc/Permissions.md index 6842ba1275..c57e0d49e1 100644 --- a/src/Kunstmaan/AdminBundle/Resources/doc/Permissions.md +++ b/src/Kunstmaan/AdminBundle/Resources/doc/Permissions.md @@ -128,7 +128,8 @@ public function findAllWithPermission(AclHelper $aclHelper, PermissionDefinition { $qb = $this->createQueryBuilder('b') ->select('b') - ->where('b.deleted = 0'); + ->where('b.deleted = :deleted') + ->setParameter('deleted', false); $query = $aclHelper->apply($qb, $permissionDef); return $query->getResult(); diff --git a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclHelperTest.php b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclHelperTest.php index 910798a144..0db07db89f 100644 --- a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclHelperTest.php +++ b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclHelperTest.php @@ -76,7 +76,10 @@ protected function setUp(): void ->will($this->returnValue('myDatabase')); /* @var $platform AbstractPlatform */ - $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); + $platform = $this->createMock(AbstractPlatform::class); + $platform->expects($this->any()) + ->method('getStringLiteralQuoteCharacter') + ->willReturn($this->returnValue('#')); $conn->expects($this->any()) ->method('getDatabasePlatform') @@ -202,9 +205,9 @@ public function testApply() $this->assertEquals('n', $query->getHint('acl.entityRootTableDqlAlias')); $aclQuery = $query->getHint('acl.extra.query'); - $this->assertStringContainsString('"ROLE_SUBJECT"', $aclQuery); - $this->assertStringContainsString('"ROLE_KING"', $aclQuery); - $this->assertStringContainsString('"IS_AUTHENTICATED_ANONYMOUSLY"', $aclQuery); + $this->assertStringContainsString('#ROLE_SUBJECT#', $aclQuery); + $this->assertStringContainsString('#ROLE_KING#', $aclQuery); + $this->assertStringContainsString('#IS_AUTHENTICATED_ANONYMOUSLY#', $aclQuery); $this->assertStringContainsString('MyUser', $aclQuery); } @@ -255,7 +258,7 @@ public function testApplyAnonymous() $this->assertEquals('n', $query->getHint('acl.entityRootTableDqlAlias')); $aclQuery = $query->getHint('acl.extra.query'); - $this->assertStringContainsString('"IS_AUTHENTICATED_ANONYMOUSLY"', $aclQuery); + $this->assertStringContainsString('#IS_AUTHENTICATED_ANONYMOUSLY#', $aclQuery); } public function testGetAllowedEntityIds() diff --git a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclNativeHelperTest.php b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclNativeHelperTest.php index 47f64db3ff..244c7a44d0 100644 --- a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclNativeHelperTest.php +++ b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclNativeHelperTest.php @@ -74,7 +74,10 @@ protected function setUp(): void ->will($this->returnValue('myDatabase')); /* @var $platform AbstractPlatform */ - $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); + $platform = $this->createMock(AbstractPlatform::class); + $platform->expects($this->any()) + ->method('getStringLiteralQuoteCharacter') + ->willReturn($this->returnValue('#')); $this->conn->expects($this->any()) ->method('getDatabasePlatform') @@ -151,9 +154,9 @@ public function testApply() $qb = $this->object->apply($queryBuilder, $permissionDef); $query = $qb->getSQL(); - $this->assertStringContainsString('"ROLE_SUBJECT"', $query); - $this->assertStringContainsString('"ROLE_KING"', $query); - $this->assertStringContainsString('"IS_AUTHENTICATED_ANONYMOUSLY"', $query); + $this->assertStringContainsString('#ROLE_SUBJECT#', $query); + $this->assertStringContainsString('#ROLE_KING#', $query); + $this->assertStringContainsString('#IS_AUTHENTICATED_ANONYMOUSLY#', $query); $this->assertStringContainsString('MyUser', $query); } @@ -191,7 +194,7 @@ public function testApplyAnonymous() $qb = $this->object->apply($queryBuilder, $permissionDef); $query = $qb->getSQL(); - $this->assertStringContainsString('"IS_AUTHENTICATED_ANONYMOUSLY"', $query); + $this->assertStringContainsString('#IS_AUTHENTICATED_ANONYMOUSLY#', $query); } public function testGetTokenStorage() diff --git a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclWalkerTest.php b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclWalkerTest.php index 1c077fa492..7b3b05bed4 100644 --- a/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclWalkerTest.php +++ b/src/Kunstmaan/AdminBundle/Tests/unit/Helper/Security/Acl/AclWalkerTest.php @@ -36,7 +36,7 @@ public function testWalker() $platform->expects($this->once())->method('appendLockHint')->willReturn($from); $conn = $this->createMock(Connection::class); - $conn->expects($this->once())->method('getDatabasePlatform')->willReturn($platform); + $conn->expects($this->any())->method('getDatabasePlatform')->willReturn($platform); $em = $this->createMock(EntityManager::class); $query = $this->createMock(AbstractQuery::class); diff --git a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractPageAdminListConfigurator.php b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractPageAdminListConfigurator.php index 170ce7c92e..3e829cfddb 100644 --- a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractPageAdminListConfigurator.php +++ b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractPageAdminListConfigurator.php @@ -118,7 +118,8 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = [] ->select('b.id, b.node_id') ->from('kuma_node_translations', 'b') ->innerJoin('b', 'kuma_nodes', 'n', 'b.node_id = n.id') - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('n.ref_entity_name = :class') ->setParameter('class', $this->getPageClass()) ->addOrderBy('b.updated', 'DESC'); diff --git a/src/Kunstmaan/AdminListBundle/Helper/DoctrineDBALAdapter.php b/src/Kunstmaan/AdminListBundle/Helper/DoctrineDBALAdapter.php index 34eb6a6c9c..0a35af98b9 100644 --- a/src/Kunstmaan/AdminListBundle/Helper/DoctrineDBALAdapter.php +++ b/src/Kunstmaan/AdminListBundle/Helper/DoctrineDBALAdapter.php @@ -69,7 +69,6 @@ public function getNbResults() $distinctString = 'DISTINCT '; } $statement = $query->select('COUNT('. $distinctString . $this->countField.') AS total_results') - ->orderBy($this->countField) ->setMaxResults(1) ->execute(); diff --git a/src/Kunstmaan/AdminListBundle/Tests/unit/AdminList/Helper/DoctrineDBALAdapterTest.php b/src/Kunstmaan/AdminListBundle/Tests/unit/AdminList/Helper/DoctrineDBALAdapterTest.php index e0624dac3b..e3a469ceae 100644 --- a/src/Kunstmaan/AdminListBundle/Tests/unit/AdminList/Helper/DoctrineDBALAdapterTest.php +++ b/src/Kunstmaan/AdminListBundle/Tests/unit/AdminList/Helper/DoctrineDBALAdapterTest.php @@ -60,7 +60,7 @@ public function testNbResults() $qb = $this->createMock(QueryBuilder::class); $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT); $qb->expects($this->once())->method('select')->willReturn($qb); - $qb->expects($this->once())->method('orderBy')->willReturn($qb); + $qb->expects($this->never())->method('orderBy'); $qb->expects($this->once())->method('setMaxResults')->with(1)->willReturn($qb); $qb->expects($this->once())->method('execute')->willReturn($statement); @@ -76,7 +76,7 @@ public function testNbResultsWithZeroResults() $qb = $this->createMock(QueryBuilder::class); $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT); $qb->expects($this->once())->method('select')->willReturn($qb); - $qb->expects($this->once())->method('orderBy')->willReturn($qb); + $qb->expects($this->never())->method('orderBy'); $qb->expects($this->once())->method('setMaxResults')->with(1)->willReturn($qb); $qb->expects($this->once())->method('execute')->willReturn($statement); diff --git a/src/Kunstmaan/ArticleBundle/AdminList/AbstractArticlePageAdminListConfigurator.php b/src/Kunstmaan/ArticleBundle/AdminList/AbstractArticlePageAdminListConfigurator.php index 7cfc36571e..fcc788c0c5 100644 --- a/src/Kunstmaan/ArticleBundle/AdminList/AbstractArticlePageAdminListConfigurator.php +++ b/src/Kunstmaan/ArticleBundle/AdminList/AbstractArticlePageAdminListConfigurator.php @@ -108,7 +108,8 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id'); $queryBuilder->innerJoin('b.nodeVersions', 'nv', 'WITH', 'b.publicNodeVersion = nv.id'); $queryBuilder->andWhere('b.lang = :lang'); - $queryBuilder->andWhere('n.deleted = 0'); + $queryBuilder->andWhere('n.deleted = :deleted'); + $queryBuilder->setParameter('deleted', false); $queryBuilder->andWhere('n.refEntityName = :class'); $queryBuilder->addOrderBy('b.updated', 'DESC'); $queryBuilder->setParameter('lang', $this->locale); diff --git a/src/Kunstmaan/ArticleBundle/Repository/AbstractArticleOverviewPageRepository.php b/src/Kunstmaan/ArticleBundle/Repository/AbstractArticleOverviewPageRepository.php index 30b4939119..b91853949b 100644 --- a/src/Kunstmaan/ArticleBundle/Repository/AbstractArticleOverviewPageRepository.php +++ b/src/Kunstmaan/ArticleBundle/Repository/AbstractArticleOverviewPageRepository.php @@ -18,7 +18,8 @@ public function findActiveOverviewPages() ->innerJoin('KunstmaanNodeBundle:NodeVersion', 'v', 'WITH', 'a.id = v.refId') ->innerJoin('KunstmaanNodeBundle:NodeTranslation', 't', 'WITH', 't.publicNodeVersion = v.id') ->innerJoin('KunstmaanNodeBundle:Node', 'n', 'WITH', 't.node = n.id') - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('v.refEntityName = :refname') ->setParameter('refname', $this->getEntityName()); diff --git a/src/Kunstmaan/ArticleBundle/Tests/unit/Repository/AbstractArticleOverviewPageRepositoryTest.php b/src/Kunstmaan/ArticleBundle/Tests/unit/Repository/AbstractArticleOverviewPageRepositoryTest.php index e09eb29629..39dc4aa543 100644 --- a/src/Kunstmaan/ArticleBundle/Tests/unit/Repository/AbstractArticleOverviewPageRepositoryTest.php +++ b/src/Kunstmaan/ArticleBundle/Tests/unit/Repository/AbstractArticleOverviewPageRepositoryTest.php @@ -30,7 +30,7 @@ public function testFindActiveOverviewPages() $qb->expects($this->once())->method('from')->willReturn($qb); $qb->expects($this->once())->method('where')->willReturn($qb); $qb->expects($this->once())->method('andWhere')->willReturn($qb); - $qb->expects($this->once())->method('setParameter')->willReturn($qb); + $qb->expects($this->exactly(2))->method('setParameter')->willReturn($qb); $qb->expects($this->once())->method('getQuery')->willReturn($query); $em = $this->createMock(EntityManager::class); diff --git a/src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle/skeleton/article/Repository/PageRepositoryPartial.php.twig b/src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle/skeleton/article/Repository/PageRepositoryPartial.php.twig index 22f6c39ac7..97d9affeb5 100755 --- a/src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle/skeleton/article/Repository/PageRepositoryPartial.php.twig +++ b/src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle/skeleton/article/Repository/PageRepositoryPartial.php.twig @@ -41,8 +41,10 @@ class {{ entity_class }}PageRepository extends AbstractArticlePageRepository ->innerJoin('KunstmaanNodeBundle:NodeVersion', 'v', 'WITH', 'a.id = v.refId') ->innerJoin('KunstmaanNodeBundle:NodeTranslation', 't', 'WITH', 't.publicNodeVersion = v.id') ->innerJoin('KunstmaanNodeBundle:Node', 'n', 'WITH', 't.node = n.id') - ->where('t.online = 1') - ->andWhere('n.deleted = 0') + ->where('t.online = :online') + ->setParameter('online', true) + ->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('v.refEntityName = :refname') ->orderBy('a.date', 'DESC') ->setParameter('refname', "{{ namespace | replace({'\\': '\\\\'}) }}\\Entity\\Pages\\{{ entity_class }}Page"); diff --git a/src/Kunstmaan/MediaBundle/AdminList/MediaAdminListConfigurator.php b/src/Kunstmaan/MediaBundle/AdminList/MediaAdminListConfigurator.php index 12fad7b4b2..4609653344 100644 --- a/src/Kunstmaan/MediaBundle/AdminList/MediaAdminListConfigurator.php +++ b/src/Kunstmaan/MediaBundle/AdminList/MediaAdminListConfigurator.php @@ -153,7 +153,8 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) { $queryBuilder->andWhere('b.folder = :folder') ->setParameter('folder', $this->folder->getId()) - ->andWhere('b.deleted = 0') + ->andWhere('b.deleted = :deleted') + ->setParameter('deleted', false) ->orderBy('b.updatedAt', 'DESC'); if ($this->request->get('_route') == 'KunstmaanMediaBundle_chooser_show_folder') { diff --git a/src/Kunstmaan/MenuBundle/Form/MenuItemAdminType.php b/src/Kunstmaan/MenuBundle/Form/MenuItemAdminType.php index da9b7b195e..c2b142e5fa 100644 --- a/src/Kunstmaan/MenuBundle/Form/MenuItemAdminType.php +++ b/src/Kunstmaan/MenuBundle/Form/MenuItemAdminType.php @@ -91,10 +91,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) $qb = $er->createQueryBuilder('nt') ->innerJoin('nt.publicNodeVersion', 'nv') ->innerJoin('nt.node', 'n') - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('nt.lang = :lang') ->setParameter('lang', $locale) - ->andWhere('nt.online = 1') + ->andWhere('nt.online = :online') + ->setParameter('online', true) ->orderBy('nt.title', 'ASC'); if ($rootNode) { $qb->andWhere('n.lft >= :left') diff --git a/src/Kunstmaan/MenuBundle/Repository/MenuItemRepository.php b/src/Kunstmaan/MenuBundle/Repository/MenuItemRepository.php index 4feedcd62c..a38f8040a8 100644 --- a/src/Kunstmaan/MenuBundle/Repository/MenuItemRepository.php +++ b/src/Kunstmaan/MenuBundle/Repository/MenuItemRepository.php @@ -26,7 +26,8 @@ public function getMenuItemsForLanguage($menuName, $locale) ->setParameter('locale', $locale) ->andWhere('m.name = :name') ->setParameter('name', $menuName) - ->andWhere('nt.online = 1 OR mi.type = :url_type') + ->andWhere('nt.online = :online OR mi.type = :url_type') + ->setParameter('online', true) ->setParameter('url_type', BaseMenuItem::TYPE_URL_LINK); $query = $query->getQuery(); diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index b5d3c35c07..7a5214b4c3 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -243,7 +243,8 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->select('b,n') ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id') ->andWhere('b.lang = :lang') - ->andWhere('n.deleted = 0') + ->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false) ->addOrderBy('b.updated', 'DESC') ->setParameter('lang', $this->locale); diff --git a/src/Kunstmaan/NodeBundle/Form/NodeChoiceType.php b/src/Kunstmaan/NodeBundle/Form/NodeChoiceType.php index 281ab5bb61..4435e0b0f4 100644 --- a/src/Kunstmaan/NodeBundle/Form/NodeChoiceType.php +++ b/src/Kunstmaan/NodeBundle/Form/NodeChoiceType.php @@ -49,7 +49,8 @@ public function configureOptions(OptionsResolver $resolver) ->innerJoin('nt.publicNodeVersion', 'nv') ->andWhere('nt.online = :online') ->andWhere('nt.lang = :lang') - ->andWhere('n.deleted != 1') + ->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('n.refEntityName IN(:refEntityName)') ->setParameter('lang', $options['locale'] ? $options['locale'] : $this->getCurrentLocale()) ->setParameter('refEntityName', $options['page_class']) diff --git a/src/Kunstmaan/NodeBundle/Repository/NodeRepository.php b/src/Kunstmaan/NodeBundle/Repository/NodeRepository.php index bacbf3b730..b92729f7af 100644 --- a/src/Kunstmaan/NodeBundle/Repository/NodeRepository.php +++ b/src/Kunstmaan/NodeBundle/Repository/NodeRepository.php @@ -74,7 +74,8 @@ public function getChildNodes( 'WITH', 't.publicNodeVersion = v.id' ) - ->where('b.deleted = 0') + ->where('b.deleted = :deleted') + ->setParameter('deleted', false) ->setParameter('lang', $lang) ->addOrderBy('t.weight', 'ASC') ->addOrderBy('t.title', 'ASC'); @@ -275,6 +276,7 @@ public function getAllMenuNodes( ) use ($databasePlatformName) { switch ($databasePlatformName) { case 'sqlite': + case 'postgresql': $statement = 'CASE WHEN %s THEN %s ELSE %s END'; break; @@ -309,13 +311,14 @@ public function getAllMenuNodes( 'v', '(v.node_id = n.id AND v.lang <> :lang)' ) - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') ->addGroupBy('n.id') ->addOrderBy('t.weight', 'ASC') ->addOrderBy('t.title', 'ASC'); if (!$includeHiddenFromNav) { - $qb->andWhere('n.hidden_from_nav <> 0'); + $qb->andWhere('n.hidden_from_nav = :hidden_from_nav') + ->setParameter('hidden_from_nav', true); } if (!\is_null($rootNode)) { @@ -329,6 +332,7 @@ public function getAllMenuNodes( $qb = $aclNativeHelper->apply($qb, $permissionDef); $stmt = $this->_em->getConnection()->prepare($qb->getSQL()); + $stmt->bindValue(':deleted', false); $stmt->bindValue(':lang', $lang); if (!\is_null($rootNode)) { $stmt->bindValue(':left', $rootNode->getLeft()); @@ -364,7 +368,8 @@ public function getAllParents(Node $node = null, $lang = null) 'WITH', 't.publicNodeVersion = v.id' ) - ->where('node.deleted = 0'); + ->where('node.deleted = :deleted') + ->setParameter('deleted', false); if ($lang) { $qb->andWhere('t.lang = :lang') @@ -408,7 +413,8 @@ public function getRootNodeFor(Node $node = null, $lang = null) 'WITH', 't.publicNodeVersion = v.id' ) - ->where('node.deleted = 0') + ->where('node.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('node.parent IS NULL'); if ($lang) { @@ -440,7 +446,8 @@ public function getAllTopNodes() 'WITH', 't.publicNodeVersion = v.id' ) - ->where('b.deleted = 0') + ->where('b.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('b.parent IS NULL'); return $qb->getQuery()->getResult(); @@ -471,7 +478,8 @@ public function getNodesByInternalName( 'WITH', 't.publicNodeVersion = v.id' ) - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('n.internalName = :internalName') ->setParameter('internalName', $internalName) ->andWhere('t.lang = :lang') @@ -508,7 +516,8 @@ public function getNodeByInternalName($internalName) { $qb = $this->createQueryBuilder('n') ->select('n') - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('n.internalName = :internalName') ->setParameter('internalName', $internalName); @@ -524,7 +533,8 @@ public function findAllDistinctPageClasses() { $qb = $this->createQueryBuilder('n') ->select('n.refEntityName') - ->where('n.deleted = 0') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->distinct(true); return $qb->getQuery()->getArrayResult(); @@ -541,7 +551,8 @@ public function getChildCount(Node $node, bool $direct = false, bool $includeDel $qb->select('COUNT('.$alias.')'); if (false === $includeDeleted) { - $qb->andWhere($alias.'.deleted = 0'); + $qb->andWhere($alias.'.deleted = :deleted') + ->setParameter('deleted', false); } return (int) $qb->getQuery()->getSingleScalarResult(); diff --git a/src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php b/src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php index a2f35d3312..f27764e385 100644 --- a/src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php +++ b/src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php @@ -50,8 +50,10 @@ public function getNodeTranslationByNodeId($nodeId, string $lang) $qb = $this->createQueryBuilder('nt') ->select('nt') ->innerJoin('nt.node', 'n', 'WITH', 'nt.node = n.id') - ->where('n.deleted != 1') - ->andWhere('nt.online = 1') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) + ->andWhere('nt.online = :online') + ->setParameter('online', true) ->andWhere('nt.lang = :lang') ->setParameter('lang', $lang) ->andWhere('n.id = :node_id') @@ -103,7 +105,8 @@ public function getNodeTranslationsQueryBuilder($lang = null) 'WITH', 'nt.publicNodeVersion = v.id' ) - ->where('n.deleted = false') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->orderBy('nt.weight') ; @@ -128,7 +131,8 @@ public function getNodeTranslationsQueryBuilder($lang = null) public function getOnlineNodeTranslationsQueryBuilder($lang = null) { return $this->getNodeTranslationsQueryBuilder($lang) - ->andWhere('nt.online = true'); + ->andWhere('nt.online = :online') + ->setParameter('online', true); } /** @@ -153,7 +157,8 @@ public function getChildrenQueryBuilder(Node $parent, $lang = null) public function getOnlineChildrenQueryBuilder(Node $parent, $lang = null) { return $this->getChildrenQueryBuilder($parent, $lang) - ->andWhere('nt.online = true'); + ->andWhere('nt.online = :online') + ->setParameter('online', true); } /** @@ -258,7 +263,8 @@ private function getNodeTranslationForSlugPart( 'WITH', 't.publicNodeVersion = v.id' ) - ->where('n.deleted != 1') + ->where('n.deleted = :deleted') + ->setParameter('deleted', false) ->setFirstResult(0) ->setMaxResults(1); @@ -315,7 +321,8 @@ public function getAllNodeTranslationsForUrl( ->setMaxResults(1); if (!$includeDeleted) { - $qb->andWhere('n.deleted = 0'); + $qb->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false); } if (!empty($locale)) { @@ -391,7 +398,8 @@ public function getTopNodeTranslations() 'b.publicNodeVersion = v.id' ) ->where('n.parent IS NULL') - ->andWhere('n.deleted != 1'); + ->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false); return $qb->getQuery()->getResult(); } @@ -511,10 +519,11 @@ public function getBestMatchForUrl($urlSlug, $locale) 'select nt.* from kuma_node_translations nt join kuma_nodes n on n.id = nt.node_id - where n.deleted = 0 and nt.lang = :lang and locate(nt.url, :url) = 1 + where n.deleted = :deleted and nt.lang = :lang and locate(nt.url, :url) = 1 order by length(nt.url) desc limit 1', $rsm ); + $query->setParameter('deleted', false); $query->setParameter('lang', $locale); $query->setParameter('url', $urlSlug); @@ -577,8 +586,10 @@ public function getNodeTranslationByLanguageAndInternalName( 'WITH', 'nt.publicNodeVersion = v.id' ) - ->where('n.deleted != 1') - ->andWhere('nt.online = 1') + ->where('n.deleted = :deleted') + ->andWhere('nt.online = :online') + ->setParameter('deleted', false) + ->setParameter('online', true) ->setFirstResult(0) ->setMaxResults(1); @@ -615,7 +626,8 @@ public function getParentNodeTranslation(NodeTranslation $nodeTranslation) ->innerJoin('nt.publicNodeVersion', 'nv') ->innerJoin('nt.node', 'n') ->where('nt.node = :parent') - ->andWhere('n.deleted = 0') + ->andWhere('n.deleted = :deleted') + ->setParameter('deleted', false) ->andWhere('nt.lang = :lang') ->setParameter('parent', $parent) ->setParameter('lang', $nodeTranslation->getLang()); diff --git a/src/Kunstmaan/TaggingBundle/Entity/TagManager.php b/src/Kunstmaan/TaggingBundle/Entity/TagManager.php index 0493691a3a..fd052c0714 100644 --- a/src/Kunstmaan/TaggingBundle/Entity/TagManager.php +++ b/src/Kunstmaan/TaggingBundle/Entity/TagManager.php @@ -159,8 +159,8 @@ public function findRelatedItems(Taggable $item, $class, $locale, $nbOfItems = 1 INNER JOIN kuma_node_versions as nodeversion ON nodetranslation.publicNodeVersion = nodeversion.id AND nodeversion.refEntityname = '{$escapedClass}' - AND node.deleted = 0 - AND nodetranslation.online = 1 + AND node.deleted = :deleted + AND nodetranslation.online = :online ) EOD; } @@ -174,7 +174,13 @@ public function findRelatedItems(Taggable $item, $class, $locale, $nbOfItems = 1 number DESC LIMIT {$nbOfItems}; EOD; + $query = $em->createNativeQuery($query, $rsm); - return $em->createNativeQuery($query, $rsm)->getResult(); + if ($item instanceof AbstractPage) { + $query->setParameter('deleted', false); + $query->setParameter('online', true); + } + + return $query->getResult(); } } diff --git a/src/Kunstmaan/TranslatorBundle/AdminList/TranslationAdminListConfigurator.php b/src/Kunstmaan/TranslatorBundle/AdminList/TranslationAdminListConfigurator.php index e0f3b7dc54..aef434aff6 100644 --- a/src/Kunstmaan/TranslatorBundle/AdminList/TranslationAdminListConfigurator.php +++ b/src/Kunstmaan/TranslatorBundle/AdminList/TranslationAdminListConfigurator.php @@ -228,9 +228,12 @@ public function getQueryBuilder() $this->locales )); + $identifierQuoteCharacter = $this->connection->getDatabasePlatform()->getIdentifierQuoteCharacter(); + $quotedTextColumnName = $identifierQuoteCharacter . 'text' . $identifierQuoteCharacter; + // Add join for every locale foreach ($this->locales as $locale) { - $this->queryBuilder->addSelect('t_'.$locale.'.`text` AS '.$locale); + $this->queryBuilder->addSelect('t_'.$locale.'.'.$quotedTextColumnName.' AS '.$locale); $this->queryBuilder->addSelect('t_'.$locale.'.id AS '.$locale.'_id'); $this->queryBuilder->leftJoin( 'b', @@ -250,40 +253,40 @@ public function getQueryBuilder() $expr = null; switch ($textComparator) { case 'equals': - $expr = $this->queryBuilder->expr()->eq('t_'.$locale.'.`text`', ':var_'.$uniqueId); + $expr = $this->queryBuilder->expr()->eq('t_'.$locale.'.'.$quotedTextColumnName, ':var_'.$uniqueId); $this->queryBuilder->setParameter('var_'.$uniqueId, $textValue); break; case 'notequals': - $expr = $this->queryBuilder->expr()->neq('t_'.$locale.'.`text`', ':var_'.$uniqueId); + $expr = $this->queryBuilder->expr()->neq('t_'.$locale.'.'.$quotedTextColumnName, ':var_'.$uniqueId); $this->queryBuilder->setParameter('var_'.$uniqueId, $textValue); break; case 'contains': - $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.`text`', ':var_'.$uniqueId); + $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.'.$quotedTextColumnName, ':var_'.$uniqueId); $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$textValue.'%'); break; case 'doesnotcontain': - $expr = 't_'.$locale.'.`text`'.' NOT LIKE :var_'.$uniqueId; + $expr = 't_'.$locale.'.'.$quotedTextColumnName.' NOT LIKE :var_'.$uniqueId; $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$textValue.'%'); break; case 'startswith': - $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.`text`', ':var_'.$uniqueId); + $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.'.$quotedTextColumnName, ':var_'.$uniqueId); $this->queryBuilder->setParameter('var_'.$uniqueId, $textValue.'%'); break; case 'endswith': - $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.`text`', ':var_'.$uniqueId); + $expr = $this->queryBuilder->expr()->like('t_'.$locale.'.'.$quotedTextColumnName, ':var_'.$uniqueId); $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$textValue); break; case 'empty': $expr = $this->queryBuilder->expr()->orX( - $this->queryBuilder->expr()->isNull('t_'.$locale.'.`text`'), - $this->queryBuilder->expr()->eq('t_'.$locale.'.`text`', '\'-\''), - $this->queryBuilder->expr()->eq('t_'.$locale.'.`text`', '\'\'') + $this->queryBuilder->expr()->isNull('t_'.$locale.'.'.$quotedTextColumnName), + $this->queryBuilder->expr()->eq('t_'.$locale.'.'.$quotedTextColumnName, '\'-\''), + $this->queryBuilder->expr()->eq('t_'.$locale.'.'.$quotedTextColumnName, '\'\'') ); break;