diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e5e6c8a..4678f77 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 diff --git a/README.md b/README.md index ebc3637..f6c5567 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index c3102af..67840da 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "monolog/monolog": "^2", "php-http/guzzle7-adapter": "^1.0", "woohoolabs/yang": "^3.0" @@ -27,8 +27,8 @@ "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" }, diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 2106f75..1b1d485 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -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); + } } diff --git a/tests/TestCase/BEditaClientTest.php b/tests/TestCase/BEditaClientTest.php index 9aa94ae..80be5c0 100644 --- a/tests/TestCase/BEditaClientTest.php +++ b/tests/TestCase/BEditaClientTest.php @@ -1179,6 +1179,7 @@ private function newObject($input): int * @covers ::thumbs() * @covers ::schema() * @covers ::relationData() + * @covers ::clone() */ public function testMultipurpose(): void { @@ -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']); } }