Skip to content

Commit

Permalink
Upgrade to SilverStripe 5
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyThorpe committed May 24, 2023
1 parent 2156db7 commit ccfd1f0
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 56 deletions.
26 changes: 20 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
contributing.md export-ignore
15 changes: 0 additions & 15 deletions .scrutinizer.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .upgrade.yml

This file was deleted.

3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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).
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -14,7 +14,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.*-dev"
"dev-master": "3.*-dev"
}
},
"license": "MIT"
Expand Down
3 changes: 3 additions & 0 deletions docs/en/upgrading.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upgrading

## 3.0.0
No breaking changes

## 2.0.0
### Namespace
Add `use AntonyThorpe\Consumer\...` after your namespace declaration
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayBulkLoaderSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($data)
$this->data = $data;
}

public function getIterator()
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BulkLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/BulkLoaderSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AntonyThorpe\Consumer;

use IteratorAggregate;
use ArrayIterator;

/**
* An abstract source to bulk load records from.
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 0 additions & 5 deletions tests/ConsumerBulkLoaderRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
5 changes: 0 additions & 5 deletions tests/ConsumerBulkLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 5 additions & 5 deletions tests/ConsumerBulkLoaderUpdateRecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ccfd1f0

Please sign in to comment.