-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
konradoboza
committed
Dec 17, 2020
1 parent
5b4b34a
commit 68a1b7d
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzSupportTools\Storage; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\FetchMode; | ||
use Doctrine\DBAL\ParameterType; | ||
use eZ\Publish\SPI\Persistence\Content\ContentInfo; | ||
use eZ\Publish\SPI\Persistence\Content\Type; | ||
|
||
class DoctrineGateway implements Gateway | ||
{ | ||
private const CONTENTOBJECT_TABLE = 'ezcontentobject'; | ||
private const USER_TABLE = 'ezuser'; | ||
private const CONTENT_TYPE_TABLE = 'ezcontentclass'; | ||
private const CONTENTOBJECT_VERSION_TABLE = 'ezcontentobject_version'; | ||
|
||
/** @var \Doctrine\DBAL\Connection */ | ||
private $connection; | ||
|
||
/** @var \Doctrine\DBAL\Platforms\AbstractPlatform */ | ||
private $databasePlatform; | ||
|
||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
$this->databasePlatform = $connection->getDatabasePlatform(); | ||
} | ||
|
||
public function getContentObjectsCount(bool $includeDrafts = false): int | ||
{ | ||
$queryBuilder = $this->connection->createQueryBuilder(); | ||
$queryBuilder | ||
->select($this->databasePlatform->getCountExpression('id')) | ||
->from(self::CONTENTOBJECT_TABLE); | ||
|
||
if (!$includeDrafts) { | ||
$queryBuilder->andWhere( | ||
$queryBuilder->expr()->neq('status', ContentInfo::STATUS_DRAFT) | ||
); | ||
} | ||
|
||
return (int) $queryBuilder->execute()->fetchColumn(); | ||
} | ||
|
||
public function getUsersCount(): int | ||
{ | ||
$queryBuilder = $this->connection->createQueryBuilder(); | ||
$queryBuilder | ||
->select($this->databasePlatform->getCountExpression('contentobject_id')) | ||
->from(self::USER_TABLE); | ||
|
||
return (int) $queryBuilder->execute()->fetchColumn(); | ||
} | ||
|
||
public function getDraftsCount(): int | ||
{ | ||
$queryBuilder = $this->connection->createQueryBuilder(); | ||
$expr = $queryBuilder->expr(); | ||
|
||
$queryBuilder | ||
->select($this->databasePlatform->getCountExpression('v.id')) | ||
->from(self::CONTENTOBJECT_VERSION_TABLE, 'v') | ||
->innerJoin( | ||
'v', | ||
self::CONTENTOBJECT_TABLE, | ||
'c', | ||
$expr->andX( | ||
$expr->eq('c.id', 'v.contentobject_id'), | ||
$expr->neq('c.status', ContentInfo::STATUS_TRASHED) | ||
) | ||
) | ||
->where( | ||
$queryBuilder->expr()->eq('v.status', ':status') | ||
) | ||
->setParameter(':status', ContentInfo::STATUS_DRAFT, ParameterType::INTEGER); | ||
|
||
return (int) $queryBuilder->execute()->fetchColumn(); | ||
} | ||
|
||
public function getContentTypesCount(bool $includeDrafts = false): int | ||
{ | ||
$queryBuilder = $this->connection->createQueryBuilder(); | ||
$queryBuilder | ||
->select($this->databasePlatform->getCountExpression('id')) | ||
->from(self::CONTENT_TYPE_TABLE); | ||
|
||
if (!$includeDrafts) { | ||
$queryBuilder->andWhere( | ||
$queryBuilder->expr()->eq('version', Type::STATUS_DEFINED) | ||
); | ||
} | ||
|
||
return (int) $queryBuilder->execute()->fetchColumn(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzSupportTools\Storage; | ||
|
||
interface Gateway | ||
{ | ||
} |