From 24ea2638fe68a764a150fb04a819d62b17cd2c49 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 12 Feb 2018 11:05:38 +0000 Subject: [PATCH 1/5] Create licence file so that GitHub (and humans) can more easily find it --- LICENSE | 29 +++++++++++++++++++++++++++++ README.md | 20 -------------------- 2 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..65f4b0c70 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2006-2018, SilverStripe Limited - www.silverstripe.com +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index dc579b3b9..8f8c6b34a 100644 --- a/README.md +++ b/README.md @@ -34,26 +34,6 @@ If you would like to make changes to the SilverStripe core codebase, we have an * [Bugtracker: Installer](https://github.com/silverstripe/silverstripe-installer/issues) * [Forums](http://silverstripe.org/forums) * [Developer Mailinglist](https://groups.google.com/forum/#!forum/silverstripe-dev) - -## License ## - - Copyright (c) 2006-2014, SilverStripe Limited - www.silverstripe.com - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. ## Attribution ## From 6b38031a1e16e94d5bafcbcce4bdcb2d6b3680ed Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 7 Feb 2018 11:03:32 +1300 Subject: [PATCH 2/5] BUG Fix Director::test() not persisting removed session keys on teardown --- src/Control/Director.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index 316148578..26f8cc464 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -207,12 +207,17 @@ class Director implements TemplateGlobalProvider if ($session instanceof Session) { // Note: If passing $session as object, ensure that changes are written back // This is important for classes such as FunctionalTest which emulate cross-request persistence - $newVars['_SESSION'] = $session->getAll(); - $finally[] = function () use ($session) { + $newVars['_SESSION'] = $sessionArray = $session->getAll(); + $finally[] = function () use ($session, $sessionArray) { if (isset($_SESSION)) { + // Set new / updated keys foreach ($_SESSION as $key => $value) { $session->set($key, $value); } + // Unset removed keys + foreach (array_diff_key($sessionArray, $_SESSION) as $key => $value) { + $session->clear($key); + } } }; } else { From 9ce21338a3083c80128c5923eab3d8b968f4dd83 Mon Sep 17 00:00:00 2001 From: zanderwar Date: Tue, 13 Feb 2018 09:03:01 +1000 Subject: [PATCH 3/5] ENHANCEMENT composer.json missing notice --- src/Core/Manifest/ModuleResourceLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Manifest/ModuleResourceLoader.php b/src/Core/Manifest/ModuleResourceLoader.php index aa5b8dd8a..fde34adb1 100644 --- a/src/Core/Manifest/ModuleResourceLoader.php +++ b/src/Core/Manifest/ModuleResourceLoader.php @@ -103,7 +103,7 @@ class ModuleResourceLoader implements TemplateGlobalProvider $resource = $matches['resource']; $moduleObj = ModuleLoader::getModule($module); if (!$moduleObj) { - throw new InvalidArgumentException("Can't find module '$module'"); + throw new InvalidArgumentException("Can't find module '$module', the composer.json file may be missing from the modules installation directory"); } $resourceObj = $moduleObj->getResource($resource); if (!$resourceObj->exists()) { From f2b82b1f77a60de4bf1b5807e1b820aad263ae1b Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Tue, 13 Feb 2018 16:31:51 +1300 Subject: [PATCH 4/5] Fix docs for configuring before/after a specific config file --- _config/i18n.yml | 2 +- docs/en/02_Developer_Guides/02_Controllers/01_Introduction.md | 2 +- docs/en/02_Developer_Guides/02_Controllers/02_Routing.md | 2 +- docs/en/02_Developer_Guides/13_i18n/index.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_config/i18n.yml b/_config/i18n.yml index 32e72f433..a219828b8 100644 --- a/_config/i18n.yml +++ b/_config/i18n.yml @@ -1,6 +1,6 @@ --- Name: basei18n -Before: '/i18n' +Before: '#defaulti18n' --- SilverStripe\i18n\Data\Sources: module_priority: diff --git a/docs/en/02_Developer_Guides/02_Controllers/01_Introduction.md b/docs/en/02_Developer_Guides/02_Controllers/01_Introduction.md index 398fc525d..44c6810b4 100644 --- a/docs/en/02_Developer_Guides/02_Controllers/01_Introduction.md +++ b/docs/en/02_Developer_Guides/02_Controllers/01_Introduction.md @@ -51,7 +51,7 @@ Make sure that after you have modified the `routes.yml` file, that you clear you ```yml --- Name: mysiteroutes -After: framework/routes#coreroutes +After: framework/_config/routes#coreroutes --- SilverStripe\Control\Director: rules: diff --git a/docs/en/02_Developer_Guides/02_Controllers/02_Routing.md b/docs/en/02_Developer_Guides/02_Controllers/02_Routing.md index 4cf305a59..710906fc3 100644 --- a/docs/en/02_Developer_Guides/02_Controllers/02_Routing.md +++ b/docs/en/02_Developer_Guides/02_Controllers/02_Routing.md @@ -20,7 +20,7 @@ These routes by standard, go into a `routes.yml` file in your applications `_con ```yml --- Name: mysiteroutes -After: framework/routes#coreroutes +After: framework/_config/routes#coreroutes --- SilverStripe\Control\Director: rules: diff --git a/docs/en/02_Developer_Guides/13_i18n/index.md b/docs/en/02_Developer_Guides/13_i18n/index.md index 9cd295db6..409eace1d 100644 --- a/docs/en/02_Developer_Guides/13_i18n/index.md +++ b/docs/en/02_Developer_Guides/13_i18n/index.md @@ -337,7 +337,7 @@ To create a custom module order, you need to specify a config fragment that inse ```yml --- Name: customi18n -Before: 'defaulti18n' +Before: '#defaulti18n' --- SilverStripe\i18n\i18n: module_priority: From c767e472dc494408460ef47c27b8d34475da4ac6 Mon Sep 17 00:00:00 2001 From: Jonathon Menz Date: Mon, 12 Feb 2018 20:29:48 -0800 Subject: [PATCH 5/5] FIX DataObject singleton creation Ensure DataObject instances are aware they are singletons so functions like populateDefaults() can be skipped. (fixes #4878) --- control/injector/Injector.php | 5 ++++ tests/model/DataObjectTest.php | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/control/injector/Injector.php b/control/injector/Injector.php index 1c247b35e..96c69854b 100644 --- a/control/injector/Injector.php +++ b/control/injector/Injector.php @@ -551,6 +551,11 @@ class Injector { $constructorParams = $spec['constructor']; } + // If we're dealing with a DataObject, pass through Singleton flag as second argument + if ($type != 'prototype' && empty($constructorParams) && is_subclass_of($class, 'DataObject')) { + $constructorParams = array(null, true); + } + $factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator(); $object = $factory->create($class, $constructorParams); diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index 8d7cdf474..8855693eb 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -33,6 +33,51 @@ class DataObjectTest extends SapphireTest { 'ManyManyListTest_Category', ); + /** + * @dataProvider provideSingletons + */ + public function testSingleton($inst, $defaultValue, $altDefaultValue) + { + $inst = $inst(); + // Test that populateDefaults() isn't called on singletons + // which can lead to SQL errors during build, and endless loops + if ($defaultValue) { + $this->assertEquals($defaultValue, $inst->MyFieldWithDefault); + } else { + $this->assertEmpty($inst->MyFieldWithDefault); + } + + if ($altDefaultValue) { + $this->assertEquals($altDefaultValue, $inst->MyFieldWithAltDefault); + } else { + $this->assertEmpty($inst->MyFieldWithAltDefault); + } + } + + public function provideSingletons() + { + // because PHPUnit evalutes test providers *before* setUp methods + // any extensions added in the setUp methods won't be available + // we must return closures to generate the arguments at run time + return array( + array(function () { + return DataObjectTest_Fixture::create(); + }, 'Default Value', 'Default Value'), + array(function () { + return new DataObjectTest_Fixture(); + }, 'Default Value', 'Default Value'), + array(function () { + return singleton('DataObjectTest_Fixture'); + }, null, null), + array(function () { + return DataObjectTest_Fixture::singleton(); + }, null, null), + array(function () { + return new DataObjectTest_Fixture(null, true); + }, null, null), + ); + } + public function testDb() { $obj = new DataObjectTest_TeamComment(); $dbFields = $obj->db();