From 4cf8db3ee41dbefb7299295dd9180f99e2fc2ee2 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 19 Apr 2012 08:30:12 +1200 Subject: [PATCH] ENHANCEMENT Remove use of deprecated extraStatics in core files --- core/Extension.php | 2 +- model/DataExtension.php | 44 ++++++++--------- tests/forms/uploadfield/UploadFieldTest.php | 38 +++++++-------- .../code/i18nTestModuleDecorator.php | 12 ++--- tests/model/DataExtensionTest.php | 48 +++++++++---------- 5 files changed, 66 insertions(+), 78 deletions(-) diff --git a/core/Extension.php b/core/Extension.php index 24718a0d5..7eb2a8ce7 100644 --- a/core/Extension.php +++ b/core/Extension.php @@ -52,7 +52,7 @@ abstract class Extension { * @static * @param $class */ - static function add_to_class($class, $extensionClass, $args) { + static function add_to_class($class, $extensionClass, $args = null) { Config::add_static_source($class, $extensionClass); } diff --git a/model/DataExtension.php b/model/DataExtension.php index 6f84415da..631e8e55d 100644 --- a/model/DataExtension.php +++ b/model/DataExtension.php @@ -1,6 +1,6 @@ true, + 'db' => true, 'has_one' => true, 'belongs_to' => true, - 'indexes' => true, - 'defaults' => true, - 'has_many' => true, - 'many_many' => true, - 'belongs_many_many' => true, + 'indexes' => true, + 'defaults' => true, + 'has_many' => true, + 'many_many' => true, + 'belongs_many_many' => true, 'many_many_extraFields' => true, 'searchable_fields' => true, 'api_access' => false, ); - static function add_to_class($class, $extensionClass, $args = null) { if(method_exists($class, 'extraDBFields')) { $extraStaticsMethod = 'extraDBFields'; @@ -185,12 +184,12 @@ abstract class DataExtension extends Extension { * by the extension * By default, the summaryField() of its owner will merge more fields defined in the extension's * $extra_fields['summary_fields'] + * + * @param array $fields Array of field names */ - function updateSummaryFields(&$fields){ - $extra_fields = $this->extraStatics(); - if(isset($extra_fields['summary_fields'])){ - $summary_fields = $extra_fields['summary_fields']; - + function updateSummaryFields(&$fields) { + $summary_fields = Config::inst()->get($this->class, 'summary_fields'); + if($summary_fields) { // if summary_fields were passed in numeric array, // convert to an associative array if($summary_fields && array_key_exists(0, $summary_fields)) { @@ -199,26 +198,21 @@ abstract class DataExtension extends Extension { if($summary_fields) $fields = array_merge($fields, $summary_fields); } } - + /** * this function is used to provide modifications to the fields labels in CMS * by the extension * By default, the fieldLabels() of its owner will merge more fields defined in the extension's * $extra_fields['field_labels'] + * + * @param array $labels Array of field labels */ - function updateFieldLabels(&$lables){ - $extra_fields = $this->extraStatics(); - if(isset($extra_fields['field_labels'])){ - $field_labels = $extra_fields['field_labels']; - if($field_labels) $lables = array_merge($lables, $field_labels); + function updateFieldLabels(&$labels) { + $field_labels = Config::inst()->get($this->class, 'field_labels'); + if($field_labels) { + $labels = array_merge($labels, $field_labels); } } - - /** - * Clear any internal caches. - */ - function flushCache() { - } } diff --git a/tests/forms/uploadfield/UploadFieldTest.php b/tests/forms/uploadfield/UploadFieldTest.php index 4c33fa592..7df16d2ad 100644 --- a/tests/forms/uploadfield/UploadFieldTest.php +++ b/tests/forms/uploadfield/UploadFieldTest.php @@ -612,34 +612,32 @@ class UploadFieldTest_Record extends DataObject implements TestOnly { -static $db = array( - 'Title' => 'Text', -); + static $db = array( + 'Title' => 'Text', + ); -static $has_one = array( - 'HasOneFile' => 'File', - 'HasOneFileMaxOne' => 'File', - 'HasOneFileMaxTwo' => 'File', -); + static $has_one = array( + 'HasOneFile' => 'File', + 'HasOneFileMaxOne' => 'File', + 'HasOneFileMaxTwo' => 'File', + ); -static $has_many = array( - 'HasManyFiles' => 'File', - 'HasManyFilesMaxTwo' => 'File', -); + static $has_many = array( + 'HasManyFiles' => 'File', + 'HasManyFilesMaxTwo' => 'File', + ); -static $many_many = array( - 'ManyManyFiles' => 'File', -); + static $many_many = array( + 'ManyManyFiles' => 'File', + ); } class UploadFieldTest_FileExtension extends DataExtension implements TestOnly { - function extraStatics($class = null, $extension = null) { - return array( - 'has_one' => array('Record' => 'UploadFieldTest_Record') - ); - } + public static $has_one = array( + 'Record' => 'UploadFieldTest_Record' + ); function canDelete($member = null) { if($this->owner->Name == 'nodelete.txt') return false; diff --git a/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php b/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php index 49de61fea..ab257c5de 100644 --- a/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php +++ b/tests/i18n/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php @@ -1,10 +1,8 @@ array( - 'MyExtraField' => 'Varchar' - ) - ); - } + + public static $db = array( + 'MyExtraField' => 'Varchar' + ); + } diff --git a/tests/model/DataExtensionTest.php b/tests/model/DataExtensionTest.php index 869b9f3ad..082c0d6a8 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=null, $extension=null) { + public static function add_to_class($class = null, $extensionClass = null, $args = null) { // Only add these extensions if the $class is set to DataExtensionTest_Player, to // test that the argument works. if($class == 'DataExtensionTest_Player') { @@ -197,23 +197,21 @@ class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnl } class DataExtensionTest_ContactRole extends DataExtension implements TestOnly { - - function extraStatics($class=null, $extension=null) { - return array( - 'db' => array( - 'Website' => 'Varchar', - 'Phone' => 'Varchar(255)', - ), - 'has_many' => array( - 'RelatedObjects' => 'DataExtensionTest_RelatedObject' - ), - 'defaults' => array( - 'Phone' => '123' - ), - 'api_access' => true, - ); - } - + + public static $db =array( + 'db' => array( + 'Website' => 'Varchar', + 'Phone' => 'Varchar(255)', + ), + 'has_many' => array( + 'RelatedObjects' => 'DataExtensionTest_RelatedObject' + ), + 'defaults' => array( + 'Phone' => '123' + ), + 'api_access' => true, + ); + } class DataExtensionTest_RelatedObject extends DataObject implements TestOnly { @@ -293,19 +291,19 @@ class DataExtensionTest_Ext2 extends DataExtension implements TestOnly { } class DataExtensionTest_Faves extends DataExtension implements TestOnly { - public function extraStatics($class=null, $extension=null) { - return array( - 'many_many' => array( - 'Faves' => 'DataExtensionTest_RelatedObject' - ) - ); - } + + public static $many_many = array( + 'Faves' => 'DataExtensionTest_RelatedObject' + ); + } class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly { + public function testMethodApplied() { return "hello world"; } + } DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext1');