Skip to content
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
9 changes: 1 addition & 8 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,9 @@ jobs:
with:
php_versions: '["8.3"]'

unit-4:
uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2
with:
php_versions: '["7.4","8.1","8.2","8.3"]'
bedita_version: '4'
coverage_min_percentage: 99

unit-5:
uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2
with:
php_versions: '["7.4","8.1","8.2","8.3"]'
php_versions: '["8.1","8.2","8.3"]'
bedita_version: '5'
coverage_min_percentage: 99
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BEdita PHP Official PHP SDK

## Prerequisites

* PHP 7.4, 8.0, 8.1, 8.2, 8.3
* PHP >= 8.1
* [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)

## Install
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"monolog/monolog": "^2",
"php-http/guzzle7-adapter": "^1.0",
"woohoolabs/yang": "^3.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^3.0",
"josegonzalez/dotenv": "2.*",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^6.0|^8.0|^9.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.0",
"psy/psysh": "@stable",
"vimeo/psalm": "^5.18"
},
Expand Down
26 changes: 26 additions & 0 deletions src/BEditaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,30 @@ public function restoreObjects(array $ids, string $type = 'objects'): ?array

return $res;
}

/**
* Clone an object.
* This requires BEdita API >= 5.36.0
*
* @param string $type Object type name
* @param string $id Source object id
* @param array $modified Object attributes to overwrite
* @param array $included Associations included: can be 'relationships' and 'translations'
* @param array|null $headers Custom request headers
* @return array|null Response in array format
*/
public function clone(string $type, string $id, array $modified, array $included, ?array $headers = null): ?array
{
$body = json_encode([
'data' => [
'type' => $type,
'attributes' => $modified,
'meta' => [
'included' => $included,
],
],
]);

return $this->post(sprintf('/%s/%s/actions/clone', $type, $id), $body, $headers);
}
}
6 changes: 6 additions & 0 deletions tests/TestCase/BEditaClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ private function newObject($input): int
* @covers ::thumbs()
* @covers ::schema()
* @covers ::relationData()
* @covers ::clone()
*/
public function testMultipurpose(): void
{
Expand Down Expand Up @@ -1439,5 +1440,10 @@ function ($document) {
static::assertArrayHasKey('data', $relationData);
static::assertArrayHasKey('attributes', $relationData['data']);
static::assertArrayHasKey('params', $relationData['data']['attributes']);

// test clone
$clone = $this->client->clone('images', $mediaId, ['title' => 'Cloned image'], ['relationships', 'translations']);
static::assertNotEmpty($clone['data']['id']);
static::assertSame('Cloned image', $clone['data']['attributes']['title']);
}
}
Loading