Skip to content

Commit

Permalink
doctrine storage
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Dec 17, 2020
1 parent 5b4b34a commit 8573678
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector;

use Doctrine\DBAL\Connection;
use eZ\Publish\API\Repository\Values\ValueObject;
use EzSystems\EzSupportTools\Storage\Gateway;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\RepositorySystemInfo;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\RepositoryStatistics;
Expand Down
102 changes: 102 additions & 0 deletions src/lib/Storage/DoctrineGateway.php
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();
}
}
13 changes: 13 additions & 0 deletions src/lib/Storage/Gateway.php
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
{
}

0 comments on commit 8573678

Please sign in to comment.