diff --git a/model/DataExtension.php b/model/DataExtension.php index 33c273205..3e0603459 100644 --- a/model/DataExtension.php +++ b/model/DataExtension.php @@ -63,9 +63,9 @@ abstract class DataExtension extends Extension { if(Object::has_extension(get_parent_class($class), $extensionClass)) return; // If there aren't any extraStatics we shouldn't try to load them. - if ( ! method_exists($extensionClass, $extraStaticsMethod) ) return; + if (!method_exists($extensionClass, $extraStaticsMethod) ) return; - $statics = call_user_func(array($extensionClass, $extraStaticsMethod), $class, $extension); + $statics = call_user_func(array(singleton($extensionClass), $extraStaticsMethod), $class, $extension); if($statics) { foreach($statics as $name => $newVal) { @@ -153,11 +153,14 @@ abstract class DataExtension extends Extension { * * Return a map where the keys are db, has_one, etc, and the values are * additional fields/relations to be defined. + * + * @param $class since this method might be called on the class directly + * @param $extension since this can help to extract parameters to help set indexes * * @return array Returns a map where the keys are db, has_one, etc, and * the values are additional fields/relations to be defined. */ - function extraStatics() { + function extraStatics($class=null, $extension=null) { return array(); } diff --git a/model/Hierarchy.php b/model/Hierarchy.php index 4bebe312a..fc13ecb36 100644 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -25,7 +25,13 @@ class Hierarchy extends DataExtension { function augmentWrite(&$manipulation) { } - function extraStatics($class = null) { + /** + * + * @param string $class + * @param string $extension + * @return array + */ + function extraStatics($class=null, $extension=null) { return array( 'has_one' => array( // TODO this method is called *both* statically and on an instance diff --git a/model/Versioned.php b/model/Versioned.php index 0e6c2107a..54bd927e2 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -95,13 +95,20 @@ class Versioned extends DataExtension { $this->liveStage = array_pop($stages); } - function extraStatics($class) { + /** + * + * @param string $class + * @param string $extension + * @return array + */ + function extraStatics($class=null, $extension=null) { return array( 'db' => array( 'Version' => 'Int', ), 'has_many' => array( - 'Versions' => $class, + // TODO this method is called *both* statically and on an instance + 'Versions' => ($class) ? $class : $this->owner->class, ) ); } diff --git a/search/FulltextSearchable.php b/search/FulltextSearchable.php index 4ff0caf96..8ea2a8ed1 100644 --- a/search/FulltextSearchable.php +++ b/search/FulltextSearchable.php @@ -74,7 +74,13 @@ class FulltextSearchable extends DataExtension { parent::__construct(); } - function extraStatics($class = null, $extension = null) { + /** + * + * @param string $class + * @param string $extension + * @return array + */ + function extraStatics($class=null, $extension=null) { if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) { $searchFields = $matches[1]; diff --git a/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php b/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php index d14410638..cca6e65ac 100644 --- a/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php +++ b/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php @@ -1,6 +1,6 @@ array( 'MyExtraField' => 'Varchar' diff --git a/tests/model/DataExtensionTest.php b/tests/model/DataExtensionTest.php index d8f6fb0d6..3e2ea11d9 100644 --- a/tests/model/DataExtensionTest.php +++ b/tests/model/DataExtensionTest.php @@ -177,7 +177,7 @@ class DataExtensionTest_Player extends DataObject implements TestOnly { class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnly { - function extraStatics($class) { + function extraStatics($class=null, $extension=null) { // Only add these extensions if the $class is set to DataExtensionTest_Player, to // test that the argument works. if($class == 'DataExtensionTest_Player') { @@ -198,7 +198,7 @@ class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnl class DataExtensionTest_ContactRole extends DataExtension implements TestOnly { - function extraStatics() { + function extraStatics($class=null, $extension=null) { return array( 'db' => array( 'Website' => 'Varchar', @@ -293,7 +293,7 @@ class DataExtensionTest_Ext2 extends DataExtension implements TestOnly { } class DataExtensionTest_Faves extends DataExtension implements TestOnly { - public function extraStatics() { + public function extraStatics($class=null, $extension=null) { return array( 'many_many' => array( 'Faves' => 'DataExtensionTest_RelatedObject' diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php old mode 100755 new mode 100644 index 5580c887f..6e91812ec --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -1172,7 +1172,7 @@ class DataObjectTest_FieldlessSubTable extends DataObjectTest_Team implements Te class DataObjectTest_Team_Extension extends DataExtension implements TestOnly { - function extraStatics() { + function extraStatics($class=null, $extension=null) { return array( 'db' => array( 'ExtendedDatabaseField' => 'Varchar'