Skip to content

Commit

Permalink
Merge branch '6.7' into 6.13
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-foremski committed May 17, 2018
2 parents 8c29797 + bec9345 commit 239fbca
Show file tree
Hide file tree
Showing 24 changed files with 1,282 additions and 75 deletions.
2 changes: 1 addition & 1 deletion eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Expand Up @@ -1205,7 +1205,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 @@ -852,19 +852,14 @@ public function load($contentId, $version, array $translations = null)
}

/**
* @see loadContentInfo(), loadContentInfoByRemoteId()
* @see loadContentInfo(), loadContentInfoByRemoteId(), loadContentInfoByLocationId()
*
* @param string $column
* @param mixed $id
*
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
* @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query
*
* @return array
*/
private function internalLoadContentInfo($column, $id)
private function internalLoadContentInfo(SelectQuery $query)
{
/** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */
$query = $this->dbHandler->createSelectQuery();
$query->select(
'ezcontentobject.*',
$this->dbHandler->aliasedColumn($query, 'main_node_id', 'ezcontentobject_tree')
Expand All @@ -882,21 +877,11 @@ private function internalLoadContentInfo($column, $id)
$this->dbHandler->quoteColumn('node_id', 'ezcontentobject_tree')
)
)
)->where(
$query->expr->eq(
$this->dbHandler->quoteColumn($column, 'ezcontentobject'),
$query->bindValue($id, null, $column === 'id' ? PDO::PARAM_INT : PDO::PARAM_STR)
)
);
$statement = $query->prepare();
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);

if (empty($row)) {
throw new NotFound('content', "$column: $id");
}

return $row;
return $statement->fetch(PDO::FETCH_ASSOC);
}

/**
Expand All @@ -913,7 +898,21 @@ private function internalLoadContentInfo($column, $id)
*/
public function loadContentInfo($contentId)
{
return $this->internalLoadContentInfo('id', $contentId);
$query = $this->dbHandler->createSelectQuery();
$query->where(
$query->expr->eq(
$this->dbHandler->quoteColumn('id', 'ezcontentobject'),
$query->bindValue($contentId, null, PDO::PARAM_INT)
)
);

$row = $this->internalLoadContentInfo($query);

if (empty($row)) {
throw new NotFound('content', "id: $contentId");
}

return $row;
}

/**
Expand All @@ -929,7 +928,51 @@ public function loadContentInfo($contentId)
*/
public function loadContentInfoByRemoteId($remoteId)
{
return $this->internalLoadContentInfo('remote_id', $remoteId);
$query = $this->dbHandler->createSelectQuery();
$query->where(
$query->expr->eq(
$this->dbHandler->quoteColumn('remote_id', 'ezcontentobject'),
$query->bindValue($remoteId)
)
);

$row = $this->internalLoadContentInfo($query);

if (empty($row)) {
throw new NotFound('content', "remote_id: $remoteId");
}

return $row;
}

/**
* 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->dbHandler->createSelectQuery();
$query->where(
$query->expr->eq(
$this->dbHandler->quoteColumn('main_node_id', 'ezcontentobject_tree'),
$query->bindValue($locationId, null, PDO::PARAM_INT)
)
);

$row = $this->internalLoadContentInfo($query);

if (empty($row)) {
throw new NotFound('content', "main_node_id: $locationId");
}

return $row;
}

/**
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 239fbca

Please sign in to comment.