Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '7.2'
  • Loading branch information
Andrew Longosz committed Sep 24, 2018
2 parents 03a7f8a + 0b4a187 commit 6efe17b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 47 deletions.
Expand Up @@ -33,6 +33,7 @@ class RegenerateUrlAliasesCommand extends Command
- Take installation offline, during the script execution the database should not be modified.
- Run this command without memory limit, i.e. processing of 300k Locations can take up to 1 GB of RAM.
- Run this command in production environment using <info>--env=prod</info>
- Manually clear HTTP cache after running this command.
EOT;

/**
Expand Down Expand Up @@ -148,6 +149,7 @@ function (Repository $repository) use ($offset, $iterationCount) {
$progressBar->finish();
$output->writeln('');
$output->writeln('<info>Done.</info>');
$output->writeln('<comment>Make sure to clear HTTP cache afterwards.</comment>');
}

/**
Expand Down
19 changes: 0 additions & 19 deletions eZ/Publish/Core/Base/Tests/PHPUnit5CompatTrait.php
Expand Up @@ -34,23 +34,4 @@ public function getMock($originalClassName, $methods = array(), array $arguments
$proxyTarget
);
}

/**
* Returns a test double for the specified class.
*
* @internal Forward compatibility with PHPUnit 5/6, so unit tests written on 6.7 & backported to 5.4 can use this.
*
* @param string $originalClassName
*
* @return \PHPUnit\Framework\MockObject\MockObject
*/
protected function createMock($originalClassName)
{
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
//->disallowMockingUnknownTypes() Not defined in PHPunit 4.8
->getMock();
}
}
Expand Up @@ -936,25 +936,30 @@ private function internalLoadContent(array $contentIds, int $version = null, arr
}

/**
* @see loadContentInfo(), loadContentInfoByRemoteId(), loadContentInfoList(), loadContentInfoByLocationId()
* Get query builder to load Content Info data.
*
* @param \Doctrine\DBAL\Query\QueryBuilder $query
* @see loadContentInfo(), loadContentInfoByRemoteId(), loadContentInfoList(), loadContentInfoByLocationId()
*
* @return array
* @return \Doctrine\DBAL\Query\QueryBuilder
*/
private function internalLoadContentInfo(DoctrineQueryBuilder $query): array
private function createLoadContentInfoQueryBuilder(): DoctrineQueryBuilder
{
$query
$queryBuilder = $this->connection->createQueryBuilder();
$expr = $queryBuilder->expr();
$queryBuilder
->select('c.*', 't.main_node_id AS ezcontentobject_tree_main_node_id')
->from('ezcontentobject', 'c')
->leftJoin(
'c',
'ezcontentobject_tree',
't',
'c.id = t.contentobject_id AND t.node_id = t.main_node_id'
$expr->andX(
$expr->eq('c.id', 't.contentobject_id'),
$expr->eq('t.node_id', 't.main_node_id')
)
);

return $query->execute()->fetchAll();
return $queryBuilder;
}

/**
Expand All @@ -971,11 +976,12 @@ private function internalLoadContentInfo(DoctrineQueryBuilder $query): array
*/
public function loadContentInfo($contentId)
{
$query = $this->connection->createQueryBuilder();
$query->where('c.id = :id')
->setParameter('id', $contentId, ParameterType::INTEGER);
$queryBuilder = $this->createLoadContentInfoQueryBuilder();
$queryBuilder
->where('c.id = :id')
->setParameter('id', $contentId, ParameterType::INTEGER);

$results = $this->internalLoadContentInfo($query);
$results = $queryBuilder->execute()->fetchAll(FetchMode::ASSOCIATIVE);
if (empty($results)) {
throw new NotFound('content', "id: $contentId");
}
Expand All @@ -985,11 +991,12 @@ public function loadContentInfo($contentId)

public function loadContentInfoList(array $contentIds)
{
$query = $this->connection->createQueryBuilder();
$query->where('c.id IN (:ids)')
->setParameter('ids', $contentIds, Connection::PARAM_INT_ARRAY);
$queryBuilder = $this->createLoadContentInfoQueryBuilder();
$queryBuilder
->where('c.id IN (:ids)')
->setParameter('ids', $contentIds, Connection::PARAM_INT_ARRAY);

return $this->internalLoadContentInfo($query);
return $queryBuilder->execute()->fetchAll(FetchMode::ASSOCIATIVE);
}

/**
Expand All @@ -1005,11 +1012,12 @@ public function loadContentInfoList(array $contentIds)
*/
public function loadContentInfoByRemoteId($remoteId)
{
$query = $this->connection->createQueryBuilder();
$query->where('c.remote_id = :id')
->setParameter('id', $remoteId, ParameterType::STRING);
$queryBuilder = $this->createLoadContentInfoQueryBuilder();
$queryBuilder
->where('c.remote_id = :id')
->setParameter('id', $remoteId, ParameterType::STRING);

$results = $this->internalLoadContentInfo($query);
$results = $queryBuilder->execute()->fetchAll(FetchMode::ASSOCIATIVE);
if (empty($results)) {
throw new NotFound('content', "remote_id: $remoteId");
}
Expand All @@ -1030,11 +1038,12 @@ public function loadContentInfoByRemoteId($remoteId)
*/
public function loadContentInfoByLocationId($locationId)
{
$query = $this->connection->createQueryBuilder();
$query->where('t.main_node_id = :id')
->setParameter('id', $locationId, ParameterType::INTEGER);
$queryBuilder = $this->createLoadContentInfoQueryBuilder();
$queryBuilder
->where('t.main_node_id = :id')
->setParameter('id', $locationId, ParameterType::INTEGER);

$results = $this->internalLoadContentInfo($query);
$results = $queryBuilder->execute()->fetchAll(FetchMode::ASSOCIATIVE);
if (empty($results)) {
throw new NotFound('content', "main_node_id: $locationId");
}
Expand Down
10 changes: 7 additions & 3 deletions eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php
Expand Up @@ -307,6 +307,10 @@ private function internalPublishUrlAliasForLocation(
* If $languageCode is null the $alias is created in the system's default
* language. $alwaysAvailable makes the alias available in all languages.
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
*
* @param mixed $locationId
* @param string $path
* @param bool $forwarding
Expand Down Expand Up @@ -335,6 +339,8 @@ public function createCustomUrlAlias($locationId, $path, $forwarding = false, $l
* language. $alwaysAvailable makes the alias available in all languages.
*
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException if the path already exists for the given language
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the path is broken
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @param string $resource
* @param string $path
Expand Down Expand Up @@ -536,9 +542,7 @@ public function removeURLAliases(array $urlAliases)
* Looks up a url alias for the given url.
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \RuntimeException
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
*
* @param string $url
Expand Down
10 changes: 8 additions & 2 deletions eZ/Publish/SPI/Persistence/Content/UrlAlias/Handler.php
Expand Up @@ -69,6 +69,8 @@ public function createGlobalUrlAlias($resource, $path, $forwarding = false, $lan
/**
* List global aliases.
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if path for any of the global URL aliases is broken
*
* @param string|null $languageCode
* @param int $offset
* @param int $limit
Expand All @@ -80,6 +82,8 @@ public function listGlobalURLAliases($languageCode = null, $offset = 0, $limit =
/**
* List of url entries of $urlType, pointing to $locationId.
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if any path for the Location is broken
*
* @param mixed $locationId
* @param bool $custom if true the user generated aliases are listed otherwise the autogenerated
*
Expand All @@ -102,6 +106,8 @@ public function removeURLAliases(array $urlAliases);
* Looks up a url alias for the given url.
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the stored path for the given URL is broken
*
* @param string $url
*
Expand All @@ -112,9 +118,9 @@ public function lookup($url);
/**
* Loads URL alias by given $id.
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if path for the given URL alias is broken
*
* @param string $id
* @param string $id unique identifier in the form of "<parentId>-<text_md5>"
*
* @return \eZ\Publish\SPI\Persistence\Content\UrlAlias
*/
Expand Down

0 comments on commit 6efe17b

Please sign in to comment.