Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new storage gateway API for 6.11 compatibility #22

Merged
merged 4 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ language: php

matrix:
include:
- php: 5.4
env: TEST_CONFIG="phpunit.xml"
- php: 5.5
env: TEST_CONFIG="phpunit.xml"
- php: 5.6
env: TEST_CONFIG="phpunit.xml"
- php: 7.0
env: TEST_CONFIG="phpunit.xml"
- php: 7.1
env: TEST_CONFIG="phpunit.xml"
- php: 5.5
env: TEST_CONFIG="phpunit-integration-legacy.xml"
- php: 5.6
env: TEST_CONFIG="phpunit-integration-legacy.xml"
- php: 7.1
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"minimum-stability": "alpha",
"require": {
"ezsystems/ezpublish-kernel": "^6.0@dev"
"ezsystems/ezpublish-kernel": "^6.11@dev"
},
"require-dev": {
"phpunit/phpunit": "~4.7",
Expand All @@ -31,7 +31,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "1.3.x-dev"
}
}
}
11 changes: 4 additions & 7 deletions lib/FieldType/XmlText/XmlTextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
namespace eZ\Publish\Core\FieldType\XmlText;

use eZ\Publish\Core\FieldType\GatewayBasedStorage;
use eZ\Publish\SPI\FieldType\GatewayBasedStorage;
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
use eZ\Publish\SPI\Persistence\Content\Field;

Expand All @@ -21,7 +21,7 @@ class XmlTextStorage extends GatewayBasedStorage
*/
public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context)
{
$update = $this->getGateway($context)->storeFieldData($versionInfo, $field);
$update = $this->gateway->storeFieldData($versionInfo, $field);

if ($update) {
return true;
Expand All @@ -37,16 +37,13 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co
*/
public function getFieldData(VersionInfo $versionInfo, Field $field, array $context)
{
$this->getGateway($context)->getFieldData($field);
$this->gateway->getFieldData($field);
}

public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context)
{
/** @var \eZ\Publish\Core\FieldType\XmlText\XmlTextStorage\Gateway $gateway */
$gateway = $this->getGateway($context);

foreach ($fieldIds as $fieldId) {
$gateway->unlinkUrl($fieldId, $versionInfo->versionNo);
$this->gateway->unlinkUrl($fieldId, $versionInfo->versionNo);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/FieldType/XmlText/XmlTextStorage/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
namespace eZ\Publish\Core\FieldType\XmlText\XmlTextStorage;

use eZ\Publish\Core\FieldType\StorageGateway;
use eZ\Publish\SPI\FieldType\StorageGateway;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway as UrlGateway;
Expand Down
42 changes: 7 additions & 35 deletions lib/FieldType/XmlText/XmlTextStorage/Gateway/LegacyStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,22 @@
use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway as UrlGateway;
use DOMDocument;
use PDO;
use RuntimeException;

class LegacyStorage extends Gateway
{
protected $dbHandler;

/**
* Set database handler for this gateway.
*
* @param mixed $dbHandler
*
* @throws RuntimeException if $dbHandler is not an instance of
* {@link \eZ\Publish\Core\Persistence\Database\DatabaseHandler}
* @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler
*/
public function setConnection($dbHandler)
{
// This obviously violates the Liskov substitution Principle, but with
// the given class design there is no sane other option. Actually the
// dbHandler *should* be passed to the constructor, and there should
// not be the need to post-inject it.
if (!$dbHandler instanceof DatabaseHandler) {
throw new RuntimeException('Invalid dbHandler passed');
}

$this->urlGateway->setConnection($dbHandler);
$this->dbHandler = $dbHandler;
}
protected $dbHandler;

/**
* Returns the active connection.
*
* @throws RuntimeException if no connection has been set, yet.
*
* @return DatabaseHandler
*/
protected function getConnection()
public function __construct(DatabaseHandler $dbHandler, UrlGateway $urlGateway)
{
if ($this->dbHandler === null) {
throw new RuntimeException('Missing database connection.');
}
parent::__construct($urlGateway);

return $this->dbHandler;
$this->dbHandler = $dbHandler;
}

/**
Expand Down Expand Up @@ -237,7 +209,7 @@ protected function getObjectId(array $linksRemoteIds)

if (!empty($linksRemoteIds)) {
/** @var $q \eZ\Publish\Core\Persistence\Database\SelectQuery */
$q = $this->getConnection()->createSelectQuery();
$q = $this->dbHandler->createSelectQuery();
$q
->select('id', 'remote_id')
->from('ezcontentobject')
Expand Down
2 changes: 2 additions & 0 deletions lib/settings/fieldtype_external_storages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ parameters:
services:
ezpublish.fieldType.ezxmltext.externalStorage:
class: "%ezpublish.fieldType.ezxmltext.externalStorage.class%"
arguments:
- "@ezpublish.fieldType.ezxmltext.storage_gateway"
tags:
- {name: ezpublish.fieldType.externalStorageHandler, alias: ezxmltext}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ parameters:
services:
ezpublish.fieldType.ezxmltext.storage_gateway:
class: "%ezpublish.fieldType.ezxmltext.storage_gateway.class%"
arguments: ["@ezpublish.fieldType.ezurl.storage_gateway"]
tags:
- {name: ezpublish.fieldType.externalStorageHandler.gateway, alias: ezxmltext, identifier: LegacyStorage}
arguments:
- "@ezpublish.api.storage_engine.legacy.dbhandler"
- "@ezpublish.fieldType.ezurl.storage_gateway"
7 changes: 5 additions & 2 deletions tests/lib/XmlTextSPIIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ public function getCustomHandler()
$fieldType,
new XmlTextConverter(),
new FieldType\XmlText\XmlTextStorage(
array(
'LegacyStorage' => new LegacyStorage(new UrlGateway()),
new LegacyStorage(
$this->getDatabaseHandler(),
new UrlGateway(
$this->getDatabaseHandler()
)
)
)
);
Expand Down