From 02e31932f838b35620eadc472e96dd7ff382b86a Mon Sep 17 00:00:00 2001 From: Joe Chenevey Date: Tue, 8 Jan 2019 15:02:22 -0500 Subject: [PATCH 1/4] Update Object.php Check to ensure `self::$extra_methods[$this->class][$method]` exists before trying to retrieve it. Prevents a bunch of notices from being generated. --- core/Object.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/Object.php b/core/Object.php index 0a28bae0a..7cc0181a2 100644 --- a/core/Object.php +++ b/core/Object.php @@ -908,10 +908,12 @@ abstract class SS_Object { $methods = $this->findMethodsFromExtension($extension); if ($methods) { foreach ($methods as $method) { - $methodInfo = self::$extra_methods[$this->class][$method]; + if (isset(self::$extra_methods[$this->class][$method])) { + $methodInfo = self::$extra_methods[$this->class][$method]; - if ($methodInfo['property'] === $property && $methodInfo['index'] === $index) { - unset(self::$extra_methods[$this->class][$method]); + if ($methodInfo['property'] === $property && $methodInfo['index'] === $index) { + unset(self::$extra_methods[$this->class][$method]); + } } } From 1bc51a1c3949260e488b88fc2dd1fcf38b14bf39 Mon Sep 17 00:00:00 2001 From: Joe Chenevey Date: Tue, 8 Jan 2019 15:28:15 -0500 Subject: [PATCH 2/4] Update Object.php Switch to an early `continue` rather than wrapping contents of `foreach` in an `if` and indenting. --- core/Object.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/Object.php b/core/Object.php index 7cc0181a2..21a741511 100644 --- a/core/Object.php +++ b/core/Object.php @@ -908,12 +908,14 @@ abstract class SS_Object { $methods = $this->findMethodsFromExtension($extension); if ($methods) { foreach ($methods as $method) { - if (isset(self::$extra_methods[$this->class][$method])) { - $methodInfo = self::$extra_methods[$this->class][$method]; + if (!isset(self::$extra_methods[$this->class][$method])) { + continue; + } + + $methodInfo = self::$extra_methods[$this->class][$method]; - if ($methodInfo['property'] === $property && $methodInfo['index'] === $index) { - unset(self::$extra_methods[$this->class][$method]); - } + if ($methodInfo['property'] === $property && $methodInfo['index'] === $index) { + unset(self::$extra_methods[$this->class][$method]); } } From 16a837d6a093115755cd821c63be1e3be088645b Mon Sep 17 00:00:00 2001 From: lerni Date: Fri, 11 Jan 2019 17:22:58 +0100 Subject: [PATCH 3/4] fix [Warning] on count() with PHP >= 7.2 --- model/Versioned.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model/Versioned.php b/model/Versioned.php index 399b2b50d..f525d5db1 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -446,7 +446,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider { // Build a list of suffixes whose tables need versioning $allSuffixes = array(); - $versionableExtensions = $this->owner->config()->versionableExtensions; + $versionableExtensions = (array)$this->owner->config()->versionableExtensions; if(count($versionableExtensions)){ foreach ($versionableExtensions as $versionableExtension => $suffixes) { @@ -936,7 +936,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider { * @return string */ public function extendWithSuffix($table) { - $versionableExtensions = $this->owner->config()->versionableExtensions; + $versionableExtensions = (array)$this->owner->config()->versionableExtensions; if(count($versionableExtensions)){ foreach ($versionableExtensions as $versionableExtension => $suffixes) { From 746c0679ad1d6ceac03d2adf167367f0ca2259cd Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Wed, 23 Jan 2019 11:26:16 +0000 Subject: [PATCH 4/4] FIX: Injector may instantiate prototypes as if they're singletons (fixes #8567) --- control/injector/Injector.php | 2 +- tests/model/DataObjectTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/control/injector/Injector.php b/control/injector/Injector.php index 96c69854b..3ab429a29 100644 --- a/control/injector/Injector.php +++ b/control/injector/Injector.php @@ -866,7 +866,7 @@ class Injector { return $this->instantiate($spec, $name); } - return $this->instantiate($spec); + return $this->instantiate($spec, null, 'prototype'); } /** diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index 8855693eb..a9ed94cca 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -29,6 +29,7 @@ class DataObjectTest extends SapphireTest { 'DataObjectTest_Play', 'DataObjectTest_Ploy', 'DataObjectTest_Bogey', + 'DataObjectTest_Sortable', 'ManyManyListTest_Product', 'ManyManyListTest_Category', ); @@ -38,6 +39,13 @@ class DataObjectTest extends SapphireTest { */ public function testSingleton($inst, $defaultValue, $altDefaultValue) { + // Calls to scaffold the test database may have cached service specs for DataObjects + // with the incorrect 'type' set (singleton instead of prototype) + Injector::nest(); + $reflectionProp = new ReflectionProperty('Injector', 'specs'); + $reflectionProp->setAccessible(true); + $reflectionProp->setValue(Injector::inst(), array()); + $inst = $inst(); // Test that populateDefaults() isn't called on singletons // which can lead to SQL errors during build, and endless loops @@ -52,6 +60,8 @@ class DataObjectTest extends SapphireTest { } else { $this->assertEmpty($inst->MyFieldWithAltDefault); } + + Injector::unnest(); } public function provideSingletons()