diff --git a/.editorconfig b/.editorconfig index 47ae637..347aa2f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,6 @@ -# For more information about the properties used in this file, -# please see the EditorConfig documentation: -# http://editorconfig.org +# For more information about the properties used in +# this file, please see the EditorConfig documentation: +# http://editorconfig.org/ [*] charset = utf-8 @@ -10,8 +10,22 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[{*.yml,package.json}] +[*.md] +trim_trailing_whitespace = false + +[*.{yml,js,json,css,scss,eslintrc,feature}] indent_size = 2 +indent_style = space + +[composer.json] +indent_size = 4 + +# Don't perform any clean-up on thirdparty files + +[thirdparty/**] +trim_trailing_whitespace = false +insert_final_newline = false -# The indent size used in the package.json file cannot be changed: -# https://github.com/npm/npm/pull/3180#issuecomment-16336516 +[admin/thirdparty/**] +trim_trailing_whitespace = false +insert_final_newline = false diff --git a/.gitattributes b/.gitattributes index 67eed57..e200dbf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,5 +3,4 @@ .gitattributes export-ignore .gitignore export-ignore .scrutinizer.yml export-ignore -.travis.yml export-ignore contributing.md export-ignore diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 051ef9a..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,15 +0,0 @@ -inherit: true - -build: - nodes: - analysis: - tests: - override: [php-scrutinizer-run] - -checks: - php: - code_rating: true - duplication: true - -filter: - paths: [src/*, tests/*] diff --git a/.upgrade.yml b/.upgrade.yml deleted file mode 100644 index 56113ea..0000000 --- a/.upgrade.yml +++ /dev/null @@ -1,7 +0,0 @@ -mappings: - Consumer: AntonyThorpe\Consumer\Consumer - BulkLoader: AntonyThorpe\Consumer\BulkLoader - BulkLoaderSource: AntonyThorpe\Consumer\BulkLoaderSource - Utilities: AntonyThorpe\Consumer\Utilities - BulkLoaderResult: AntonyThorpe\Consumer\BulkLoaderResult - ArrayBulkLoaderSource: AntonyThorpe\Consumer\ArrayBulkLoaderSource diff --git a/LICENSE b/LICENSE index 7e07eaa..daab9ad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Antony Thorpe +Copyright (c) 2023 Antony Thorpe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index 2c03cfd..702e425 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ A SilverStripe BulkLoader for consuming external APIs [![CI](https://github.com/AntonyThorpe/consumer/actions/workflows/ci.yml/badge.svg)](https://github.com/AntonyThorpe/consumer/actions/workflows/ci.yml) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/antonythorpe/consumer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/antonythorpe/consumer/?branch=master) [![Latest Stable Version](https://poser.pugx.org/antonythorpe/consumer/v/stable)](https://packagist.org/packages/antonythorpe/consumer) [![Total Downloads](https://poser.pugx.org/antonythorpe/consumer/downloads)](https://packagist.org/packages/antonythorpe/consumer) [![Latest Unstable Version](https://poser.pugx.org/antonythorpe/consumer/v/unstable)](https://packagist.org/packages/antonythorpe/consumer) @@ -19,7 +18,7 @@ Maintain data integrity with an external source of truth. Keep dataobjects up t ## Use Case Where there is an external source of truth that a dataobject needs to be updated from. -An [example](https://github.com/AntonyThorpe/silvershop-unleashed) is an eCommerce website where the product prices need to be kept in alignment with an online inventory system (which is used post-sale to manage fulfilment of an order). With the eCommerce site being a subset of the total inventory items in stock, updating, without creating new product items, is required. The pricing and other properties change frequently. Based upon the philosophy of *entering data only once* a sync from the external source of truth would keep the website accurate, up to date and reduce end user maintenance. +An [example](https://github.com/AntonyThorpe/silvershop-unleashed) is an eCommerce website where the product prices need to be kept in alignment with an online inventory system (which is used post-sale to manage fulfilment of an order). With the eCommerce website being a subset of the total inventory items in stock, updating, without creating new product items, is required. The pricing and other properties change frequently. Based upon the philosophy of *entering data only once* a sync from the external source of truth would keep the website accurate, up to date and reduce maintenance. ## How to use * Subclass `\AntonyThorpe\Consumer\BulkLoader` and set your column map between the external API fields and the dataobject (see docs and tests folder for guidance). diff --git a/changelog.md b/changelog.md index 3323957..5190263 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # Change Log of Consumer +* 3.0.0 Upgrade for SilverStripe 5 * 2.0.0 Upgrade for SilverStripe 4 and Namespaces * 1.0.1 Remove dependency on burnbright/silverstripe-importexport * 1.0.0 Initial Release diff --git a/composer.json b/composer.json index 05bd764..567df47 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "silverstripe-vendormodule", "keywords": ["Silverstripe", "BulkLoader", "JSON", "XML"], "require": { - "silverstripe/framework": "^4.0.0" + "silverstripe/framework": "^5.0.0" }, "autoload": { "psr-4": { @@ -14,7 +14,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.*-dev" + "dev-master": "3.*-dev" } }, "license": "MIT" diff --git a/docs/en/upgrading.md b/docs/en/upgrading.md index 7ce89fd..b766b47 100644 --- a/docs/en/upgrading.md +++ b/docs/en/upgrading.md @@ -1,5 +1,8 @@ # Upgrading +## 3.0.0 +No breaking changes + ## 2.0.0 ### Namespace Add `use AntonyThorpe\Consumer\...` after your namespace declaration diff --git a/src/ArrayBulkLoaderSource.php b/src/ArrayBulkLoaderSource.php index 7f0e80e..6d02140 100755 --- a/src/ArrayBulkLoaderSource.php +++ b/src/ArrayBulkLoaderSource.php @@ -18,7 +18,7 @@ public function __construct($data) $this->data = $data; } - public function getIterator() + public function getIterator(): ArrayIterator { return new ArrayIterator($this->data); } diff --git a/src/BulkLoader.php b/src/BulkLoader.php index 493c2b2..6e5c642 100644 --- a/src/BulkLoader.php +++ b/src/BulkLoader.php @@ -270,7 +270,7 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals } //callback access to every object - if (method_exists($this, $this->recordCallback)) { + if ($this->recordCallback && method_exists($this, $this->recordCallback)) { $callback = $this->recordCallback; $this->{$callback}($obj, $record); } diff --git a/src/BulkLoaderSource.php b/src/BulkLoaderSource.php index 57fec53..d356d33 100755 --- a/src/BulkLoaderSource.php +++ b/src/BulkLoaderSource.php @@ -3,6 +3,7 @@ namespace AntonyThorpe\Consumer; use IteratorAggregate; +use ArrayIterator; /** * An abstract source to bulk load records from. @@ -16,7 +17,7 @@ abstract class BulkLoaderSource implements IteratorAggregate /** * Provide iterator for bulk loading from. * Records are expected to be 1 dimensional key-value arrays. - * @return \ArrayIterator + * @return ArrayIterator */ - abstract public function getIterator(); + abstract public function getIterator(): ArrayIterator; } diff --git a/src/Consumer.php b/src/Consumer.php index 0206fd0..043d968 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -32,9 +32,9 @@ public static function convertUnix2UTC($data) $date = new DateTime(); if (strlen($string) > 10) { - $date->setTimestamp($string/1000); // Unix date with milliseconds + $date->setTimestamp(intval($string/1000)); // Unix date with milliseconds } else { - $date->setTimestamp($string); + $date->setTimestamp(intval($string)); } return $date->format('Y-m-d\TH:i:s.u'); diff --git a/tests/ConsumerBulkLoaderRelationTest.php b/tests/ConsumerBulkLoaderRelationTest.php index f4ec3c9..1fb6d00 100644 --- a/tests/ConsumerBulkLoaderRelationTest.php +++ b/tests/ConsumerBulkLoaderRelationTest.php @@ -195,9 +195,4 @@ public function testRelationList() $this->assertEquals(3, $results->CreatedCount(), "3 more records created"); $this->assertEquals(3, $list->count(), "relation list count remains the same"); } - - public function testRequiredRelation() - { - //$this->markTestIncomplete("Required relations should be checked"); - } } diff --git a/tests/ConsumerBulkLoaderTest.php b/tests/ConsumerBulkLoaderTest.php index 135cb02..6a18d21 100644 --- a/tests/ConsumerBulkLoaderTest.php +++ b/tests/ConsumerBulkLoaderTest.php @@ -129,11 +129,6 @@ public function testLoadUpdatesOnly() $this->assertSame(2, (int)$bruce->CountryID, 'Bruce should still have the CountryID for Australia'); } - public function testColumnMap() - { - //$this->markTestIncomplete("Implement this"); - } - public function testTransformCallback() { $loader = new BulkLoader('AntonyThorpe\Consumer\Tests\Person'); diff --git a/tests/ConsumerBulkLoaderUpdateRecordsTest.php b/tests/ConsumerBulkLoaderUpdateRecordsTest.php index ba1ecfd..3c96409 100644 --- a/tests/ConsumerBulkLoaderUpdateRecordsTest.php +++ b/tests/ConsumerBulkLoaderUpdateRecordsTest.php @@ -24,10 +24,10 @@ public function setUp(): void parent::setUp(); //publish some product categories and products so as to test the Live version - $this->objFromFixture(Product::class, 'products')->publish('Stage', 'Live'); - $this->objFromFixture(Product::class, 'pm1')->publish('Stage', 'Live'); - $this->objFromFixture(Product::class, 'pm2')->publish('Stage', 'Live'); - $this->objFromFixture(Product::class, 'pm3')->publish('Stage', 'Live'); + $this->objFromFixture(Product::class, 'products')->copyVersionToStage('Stage', 'Live'); + $this->objFromFixture(Product::class, 'pm1')->copyVersionToStage('Stage', 'Live'); + $this->objFromFixture(Product::class, 'pm2')->copyVersionToStage('Stage', 'Live'); + $this->objFromFixture(Product::class, 'pm3')->copyVersionToStage('Stage', 'Live'); } public function testUpdateRecords() @@ -139,7 +139,7 @@ public function testUpdateRecordsWhenDataobjectExtendsPage() $this->assertEquals($results->CreatedCount(), 0); $this->assertEquals($results->UpdatedCount(), 2); $this->assertEquals($results->DeletedCount(), 0); - $this->assertEquals($results->SkippedCount(), 0); + $this->assertEquals($results->SkippedCount(), 2); $this->assertEquals($results->Count(), 2); $this->assertStringContainsString(