Skip to content

Commit

Permalink
Merge branch '6.13' into 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-foremski committed May 18, 2018
2 parents 7c9dd98 + 239fbca commit b8aa70a
Show file tree
Hide file tree
Showing 25 changed files with 1,266 additions and 68 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -70,7 +70,7 @@
"extra": {
"_ci_branch-comment_": "Keep ci branch up-to-date with master or branch if on stable. ci is never on github but convention used for ci behat testing!",
"_ezplatform_branch_for_behat_tests_comment_": "ezplatform branch to use to run Behat tests",
"_ezplatform_branch_for_behat_tests": "master",
"_ezplatform_branch_for_behat_tests": "2.1",
"branch-alias": {
"dev-master": "7.1.x-dev",
"dev-tmp_ci_branch": "7.1.x-dev"
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Expand Up @@ -1277,7 +1277,7 @@ public function testSwapLocation()
);
$this->assertEquals(
$demoDesignLocation->id,
$repository->getURLAliasService()->lookup('/Plain-site')->destination
$repository->getURLAliasService()->lookup('/eZ-Publish-Demo-Design-without-demo-content')->destination
);
}

Expand Down
13 changes: 13 additions & 0 deletions eZ/Publish/Core/Persistence/Legacy/Content/Gateway.php
Expand Up @@ -162,6 +162,19 @@ abstract public function load($contentId, $version, array $translations = null);
*/
abstract public function loadContentInfoByRemoteId($remoteId);

/**
* Loads info for a content object identified by its location ID (node ID).
*
* Returns an array with the relevant data.
*
* @param int $locationId
*
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
*
* @return array
*/
abstract public function loadContentInfoByLocationId($locationId);

/**
* Loads info for content identified by $contentId.
* Will basically return a hash containing all field values for ezcontentobject table plus following keys:
Expand Down
Expand Up @@ -10,6 +10,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
use eZ\Publish\Core\Base\Exceptions\BadStateException;
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway;
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder;
Expand Down Expand Up @@ -852,29 +853,25 @@ public function load($contentId, $version, array $translations = null)
}

/**
* @see loadContentInfo(), loadContentInfoByRemoteId(), loadContentInfoList()
* @see loadContentInfo(), loadContentInfoByRemoteId(), loadContentInfoList(), loadContentInfoByLocationId()
*
* @param string $column
* @param array $ids Array of int, or if $bindype is set to Connection::PARAM_STR_ARRAY then array of string
* @param int $bindType One of Connection::PARAM_*_ARRAY constants.
* @param \Doctrine\DBAL\Query\QueryBuilder $query
*
* @return array
*/
private function internalLoadContentInfo(string $column, array $ids, int $bindType = Connection::PARAM_INT_ARRAY): array
private function internalLoadContentInfo(DoctrineQueryBuilder $query): array
{
$q = $this->connection->createQueryBuilder();
$q
$query
->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'
)->where("c.${column} IN (:ids)")
->setParameter('ids', $ids, $bindType);
);

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

/**
Expand All @@ -891,7 +888,11 @@ private function internalLoadContentInfo(string $column, array $ids, int $bindTy
*/
public function loadContentInfo($contentId)
{
$results = $this->internalLoadContentInfo('id', [$contentId]);
$query = $this->connection->createQueryBuilder();
$query->where('c.id = :id')
->setParameter('id', $contentId, \PDO::PARAM_INT);

$results = $this->internalLoadContentInfo($query);
if (empty($results)) {
throw new NotFound('content', "id: $contentId");
}
Expand All @@ -901,7 +902,11 @@ public function loadContentInfo($contentId)

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

return $this->internalLoadContentInfo($query);
}

/**
Expand All @@ -917,14 +922,43 @@ public function loadContentInfoList(array $contentIds)
*/
public function loadContentInfoByRemoteId($remoteId)
{
$results = $this->internalLoadContentInfo('remote_id', [$remoteId], Connection::PARAM_STR_ARRAY);
$query = $this->connection->createQueryBuilder();
$query->where('c.remote_id = :id')
->setParameter('id', $remoteId, \PDO::PARAM_STR);

$results = $this->internalLoadContentInfo($query);
if (empty($results)) {
throw new NotFound('content', "remote_id: $remoteId");
}

return $results[0];
}

/**
* Loads info for a content object identified by its location ID (node ID).
*
* Returns an array with the relevant data.
*
* @param int $locationId
*
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
*
* @return array
*/
public function loadContentInfoByLocationId($locationId)
{
$query = $this->connection->createQueryBuilder();
$query->where('t.main_node_id = :id')
->setParameter('id', $locationId, \PDO::PARAM_INT);

$results = $this->internalLoadContentInfo($query);
if (empty($results)) {
throw new NotFound('content', "main_node_id: $locationId");
}

return $results[0];
}

/**
* Loads version info for content identified by $contentId and $versionNo.
* Will basically return a hash containing all field values from ezcontentobject_version table plus following keys:
Expand Down
Expand Up @@ -296,6 +296,28 @@ public function loadContentInfoByRemoteId($remoteId)
}
}

/**
* Loads info for a content object identified by its location ID (node ID).
*
* Returns an array with the relevant data.
*
* @param int $locationId
*
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
*
* @return array
*/
public function loadContentInfoByLocationId($locationId)
{
try {
return $this->innerGateway->loadContentInfoByLocationId($locationId);
} catch (DBALException $e) {
throw new \RuntimeException('Database error', 0, $e);
} catch (\PDOException $e) {
throw new \RuntimeException('Database error', 0, $e);
}
}

/**
* Loads info for content identified by $contentId.
* Will basically return a hash containing all field values for ezcontentobject table plus following keys:
Expand Down
@@ -0,0 +1,56 @@
<?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.
*/
namespace eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\DTO;

/**
* @internal To be used internally by UrlAlias Persistence Handler.
*/
class SwappedLocationProperties
{
public function __construct($id, $parentId)
{
$this->id = $id;
$this->parentId = $parentId;
}

/**
* @var int
*/
public $id;

/**
* @var int
*/
public $parentId;

/**
* @var string
*/
public $name;

/**
* @var int
*/
public $mainLanguageId;

/**
* @var int
*/
public $autogeneratedId;

/**
* @var bool
*/
public $isAlwaysAvailable;

/**
* Raw database records (entries).
*
* @var array
*/
public $entries;
}
@@ -0,0 +1,59 @@
<?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.
*/
namespace eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\DTO;

/**
* @internal To be used internally by UrlAlias Persistence Handler.
*/
class UrlAliasForSwappedLocation
{
public function __construct(
$id,
$parentId,
$name,
$isAlwaysAvailable,
$isPathIdentificationStringModified,
$newId
) {
$this->id = $id;
$this->parentId = $parentId;
$this->name = $name;
$this->isAlwaysAvailable = $isAlwaysAvailable;
$this->isPathIdentificationStringModified = $isPathIdentificationStringModified;
$this->newId = $newId;
}

/**
* @var int
*/
public $id;

/**
* @var int
*/
public $parentId;

/**
* @var string
*/
public $name;

/**
* @var bool
*/
public $isAlwaysAvailable;

/**
* @var bool
*/
public $isPathIdentificationStringModified;

/**
* @var int
*/
public $newId;
}

0 comments on commit b8aa70a

Please sign in to comment.