From 083799ec03899b8388352849cbdc42e4c74fbf4d Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 28 Aug 2015 09:07:55 +1200 Subject: [PATCH] FIX: Minimal data-model changes to support PHP7. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tidiest fix for this will be to update the namespace/naming of all field types to follow this pattern. I’ve broken out the minimum necessary to support PHP7 as its own commit, in case anyone needs to backport that (e.g. if someone wanted to patch a SS 3 system to get PHP7 support). Rather than introduce a new API for fieldtype namespace simplification, I’ve just used Injector. We may come up with a new configuration tool that is better, but this has the advantage of existing now, and as such I think is a good first step. --- _config/model.yml | 5 +++++ model/fieldtypes/Double.php | 5 ++++- model/fieldtypes/Float.php | 9 ++++++++- model/fieldtypes/ForeignKey.php | 5 ++++- model/fieldtypes/Int.php | 12 +++++++++++- model/fieldtypes/PrimaryKey.php | 5 ++++- tests/model/VersionedTest.php | 4 ++-- 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 _config/model.yml diff --git a/_config/model.yml b/_config/model.yml new file mode 100644 index 000000000..2a70612b0 --- /dev/null +++ b/_config/model.yml @@ -0,0 +1,5 @@ +Injector: + Int: + class: SilverStripe\Model\FieldType\DBInt + Float: + class: SilverStripe\Model\FieldType\DBFloat diff --git a/model/fieldtypes/Double.php b/model/fieldtypes/Double.php index 5d9445865..0ed535d49 100644 --- a/model/fieldtypes/Double.php +++ b/model/fieldtypes/Double.php @@ -1,10 +1,13 @@ defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0; diff --git a/model/fieldtypes/ForeignKey.php b/model/fieldtypes/ForeignKey.php index 56ad99e70..f75814614 100644 --- a/model/fieldtypes/ForeignKey.php +++ b/model/fieldtypes/ForeignKey.php @@ -1,4 +1,7 @@ defaultVal = is_int($defaultVal) ? $defaultVal : 0; @@ -64,3 +73,4 @@ class Int extends DBField { } + diff --git a/model/fieldtypes/PrimaryKey.php b/model/fieldtypes/PrimaryKey.php index 8b900dda0..d82404e24 100644 --- a/model/fieldtypes/PrimaryKey.php +++ b/model/fieldtypes/PrimaryKey.php @@ -1,4 +1,7 @@ assertInstanceOf('Int', $obj->dbObject('Version')); + $this->assertInstanceOf('SilverStripe\\Model\\FieldType\\DBInt', $obj->dbObject('Version')); $obj2 = new VersionedTest_Subclass(); // Check that the Version column is added as a full-fledged column - $this->assertInstanceOf('Int', $obj2->dbObject('Version')); + $this->assertInstanceOf('SilverStripe\\Model\\FieldType\\DBInt', $obj2->dbObject('Version')); } public function testVersionedFieldsNotInCMS() {