Skip to content

Commit e1becf8

Browse files
authored
Merge pull request #54 from didoda/feat/clone
Prepare release 4: BEdita API 5 only, php >= 8.1 and clone
2 parents ce664f5 + 46e78c5 commit e1becf8

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

.github/workflows/php.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@ jobs:
3232
with:
3333
php_versions: '["8.3"]'
3434

35-
unit-4:
36-
uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2
37-
with:
38-
php_versions: '["7.4","8.1","8.2","8.3"]'
39-
bedita_version: '4'
40-
coverage_min_percentage: 99
41-
4235
unit-5:
4336
uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2
4437
with:
45-
php_versions: '["7.4","8.1","8.2","8.3"]'
38+
php_versions: '["8.1","8.2","8.3"]'
4639
bedita_version: '5'
4740
coverage_min_percentage: 99

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BEdita PHP Official PHP SDK
1212

1313
## Prerequisites
1414

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

1818
## Install

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=7.4",
22+
"php": ">=8.1",
2323
"monolog/monolog": "^2",
2424
"php-http/guzzle7-adapter": "^1.0",
2525
"woohoolabs/yang": "^3.0"
2626
},
2727
"require-dev": {
2828
"cakephp/cakephp-codesniffer": "^3.0",
2929
"josegonzalez/dotenv": "2.*",
30-
"phpstan/phpstan": "^1.5",
31-
"phpunit/phpunit": "^6.0|^8.0|^9.0",
30+
"phpstan/phpstan": "^1.10",
31+
"phpunit/phpunit": "^9.0",
3232
"psy/psysh": "@stable",
3333
"vimeo/psalm": "^5.18"
3434
},

src/BEditaClient.php

+26
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,30 @@ public function restoreObjects(array $ids, string $type = 'objects'): ?array
410410

411411
return $res;
412412
}
413+
414+
/**
415+
* Clone an object.
416+
* This requires BEdita API >= 5.36.0
417+
*
418+
* @param string $type Object type name
419+
* @param string $id Source object id
420+
* @param array $modified Object attributes to overwrite
421+
* @param array $included Associations included: can be 'relationships' and 'translations'
422+
* @param array|null $headers Custom request headers
423+
* @return array|null Response in array format
424+
*/
425+
public function clone(string $type, string $id, array $modified, array $included, ?array $headers = null): ?array
426+
{
427+
$body = json_encode([
428+
'data' => [
429+
'type' => $type,
430+
'attributes' => $modified,
431+
'meta' => [
432+
'included' => $included,
433+
],
434+
],
435+
]);
436+
437+
return $this->post(sprintf('/%s/%s/actions/clone', $type, $id), $body, $headers);
438+
}
413439
}

tests/TestCase/BEditaClientTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ private function newObject($input): int
11791179
* @covers ::thumbs()
11801180
* @covers ::schema()
11811181
* @covers ::relationData()
1182+
* @covers ::clone()
11821183
*/
11831184
public function testMultipurpose(): void
11841185
{
@@ -1439,5 +1440,10 @@ function ($document) {
14391440
static::assertArrayHasKey('data', $relationData);
14401441
static::assertArrayHasKey('attributes', $relationData['data']);
14411442
static::assertArrayHasKey('params', $relationData['data']['attributes']);
1443+
1444+
// test clone
1445+
$clone = $this->client->clone('images', $mediaId, ['title' => 'Cloned image'], ['relationships', 'translations']);
1446+
static::assertNotEmpty($clone['data']['id']);
1447+
static::assertSame('Cloned image', $clone['data']['attributes']['title']);
14421448
}
14431449
}

0 commit comments

Comments
 (0)