Skip to content
This repository
Browse code

BUGFIX Removing use of deprecated Object static functions like

get_static(), set_static(), uninherited() etc. Replace with equivalent
Config system get(), update()
  • Loading branch information...
commit 4c6be2931b71a5b9c2a1e6df308e99e081e8552d 1 parent 926daa2
Sean Harvey authored
6  admin/code/CMSBatchActionHandler.php
@@ -130,7 +130,7 @@ function handleAction($request) {
130 130
 
131 131
 	function handleApplicablePages($request) {
132 132
 		// Find the action handler
133  
-		$actions = Object::get_static($this->class, 'batch_actions');
  133
+		$actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET);
134 134
 		$actionClass = $actions[$request->param('BatchAction')];
135 135
 		$actionHandler = new $actionClass['class']();
136 136
 
@@ -152,7 +152,7 @@ function handleApplicablePages($request) {
152 152
 	
153 153
 	function handleConfirmation($request) {
154 154
 		// Find the action handler
155  
-		$actions = Object::get_static($this->class, 'batch_actions');
  155
+		$actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET);
156 156
 		$actionClass = $actions[$request->param('BatchAction')];
157 157
 		$actionHandler = new $actionClass();
158 158
 
@@ -203,7 +203,7 @@ function batchActionList() {
203 203
 	 * @return array See {@link register()} for the returned format.
204 204
 	 */
205 205
 	function batchActions() {
206  
-		$actions = Object::get_static($this->class, 'batch_actions');
  206
+		$actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET)
207 207
 		if($actions) foreach($actions as $action) {
208 208
 			if($action['recordClass'] != $this->recordClass) unset($action);
209 209
 		}
18  admin/code/CMSMenu.php
@@ -59,9 +59,9 @@ public static function add_controller($controllerClass) {
59 59
 	 * Return a CMSMenuItem to add the given controller to the CMSMenu
60 60
 	 */
61 61
 	protected static function menuitem_for_controller($controllerClass) {
62  
-		$urlBase      = Object::get_static($controllerClass, 'url_base');
63  
-		$urlSegment   = Object::get_static($controllerClass, 'url_segment');
64  
-		$menuPriority = Object::get_static($controllerClass, 'menu_priority');
  62
+		$urlBase      = Config::inst()->get($controllerClass, 'url_base', Config::FIRST_SET);
  63
+		$urlSegment   = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET);
  64
+		$menuPriority = Config::inst()->get($controllerClass, 'menu_priority', Config::FIRST_SET);
65 65
 		
66 66
 		// Don't add menu items defined the old way
67 67
 		if($urlSegment === null && $controllerClass != "CMSMain") return;
@@ -81,12 +81,12 @@ protected static function menuitem_for_controller($controllerClass) {
81 81
 	 * Add the appropriate Director rules for the given controller.
82 82
 	 */
83 83
 	protected static function add_director_rule_for_controller($controllerClass) {
84  
-		$urlBase      = Object::get_static($controllerClass, 'url_base');
85  
-		$urlSegment   = Object::get_static($controllerClass, 'url_segment');
86  
-		$urlRule      = Object::get_static($controllerClass, 'url_rule');
87  
-		$urlPriority  = Object::get_static($controllerClass, 'url_priority');
88  
-		
89  
-		if($urlSegment || $controllerClass == "CMSMain") {
  84
+		$urlBase      = Config::inst()->get($controllerClass, 'url_base', Config::FIRST_SET);
  85
+		$urlSegment   = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET);
  86
+		$urlRule      = Config::inst()->get($controllerClass, 'url_rule', Config::FIRST_SET);
  87
+		$urlPriority  = Config::inst()->get($controllerClass, 'url_priority', Config::FIRST_SET);
  88
+
  89
+		if($urlSegment || $controllerClass == 'CMSMain') {
90 90
 			$link = Controller::join_links($urlBase, $urlSegment) . '/';
91 91
 		
92 92
 			// Make director rule
4  control/RequestHandler.php
@@ -138,8 +138,8 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
138 138
 		
139 139
 		// We stop after RequestHandler; in other words, at ViewableData
140 140
 		while($handlerClass && $handlerClass != 'ViewableData') {
141  
-			$urlHandlers = Object::get_static($handlerClass, 'url_handlers');
142  
-			
  141
+			$urlHandlers = Config::inst()->get($handlerClass, 'url_handlers', Config::FIRST_SET);
  142
+
143 143
 			if($urlHandlers) foreach($urlHandlers as $rule => $action) {
144 144
 				if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class");
145 145
 				if($params = $request->match($rule, true)) {
22  core/Object.php
@@ -333,9 +333,6 @@ public static function static_lookup($class, $name, $default = null) {
333 333
 	 * If any extra values are discovered, they are then merged with the default PHP static values, or in some cases
334 334
 	 * completely replace the default PHP static when you set $replace = true, and do not define extra data on any child
335 335
 	 * classes
336  
-	 * 
337  
-	 * Note that from SilverStripe 2.3.2, Object::get_static() can only be used to get public
338  
-	 * static variables, not protected ones.
339 336
 	 *
340 337
 	 * @param string $class
341 338
 	 * @param string $name the property name
@@ -343,7 +340,7 @@ public static function static_lookup($class, $name, $default = null) {
343 340
 	 * @return mixed
344 341
 	 */
345 342
 	public static function get_static($class, $name, $uncached = false) {
346  
-		Deprecation::notice('3.1.0', 'combined_static is deprecated, replaced by Config#get');
  343
+		Deprecation::notice('3.1.0', 'get_static is deprecated, replaced by Config#get');
347 344
 		return Config::inst()->get($class, $name, Config::FIRST_SET);
348 345
 	}
349 346
 
@@ -355,17 +352,12 @@ public static function get_static($class, $name, $uncached = false) {
355 352
 	 * @param mixed $value
356 353
 	 */
357 354
 	public static function set_static($class, $name, $value) {
358  
-		Deprecation::notice('3.1.0', 'set_static is deprecated, replaced by Config#set');
  355
+		Deprecation::notice('3.1.0', 'set_static is deprecated, replaced by Config#update');
359 356
 		Config::inst()->update($class, $name, $value);
360 357
 	}
361 358
 
362 359
 	/**
363 360
 	 * Get an uninherited static variable - a variable that is explicity set in this class, and not in the parent class.
364  
-	 * 
365  
-	 * Note that from SilverStripe 2.3.2, Object::uninherited_static() can only be used to get public
366  
-	 * static variables, not protected ones.
367  
-	 * 
368  
-	 * @todo Recursively filter out parent statics, currently only inspects the parent class
369 361
 	 *
370 362
 	 * @param string $class
371 363
 	 * @param string $name
@@ -401,7 +393,7 @@ public static function combined_static($class, $name, $ceiling = false) {
401 393
 	 * @param bool $replace replace existing static vars
402 394
 	 */
403 395
 	public static function addStaticVars($class, $properties, $replace = false) {
404  
-		Deprecation::notice('3.1.0', 'addStaticVars is deprecated, replaced by Config#set');
  396
+		Deprecation::notice('3.1.0', 'addStaticVars is deprecated, replaced by Config#update');
405 397
 		foreach($properties as $prop => $value) self::add_static_var($class, $prop, $value, $replace);
406 398
 	}
407 399
 	
@@ -422,7 +414,7 @@ public static function addStaticVars($class, $properties, $replace = false) {
422 414
 	 * @param bool $replace completely replace existing static values
423 415
 	 */
424 416
 	public static function add_static_var($class, $name, $value, $replace = false) {
425  
-		Deprecation::notice('3.1.0', 'add_static_var is deprecated, replaced by Config#set');
  417
+		Deprecation::notice('3.1.0', 'add_static_var is deprecated, replaced by Config#remove and Config#update');
426 418
 
427 419
 		if ($replace) Config::inst()->remove($class, $name);
428 420
 		Config::inst()->update($class, $name, $value);
@@ -783,21 +775,21 @@ protected function createMethod($method, $code) {
783 775
 	 * @see Object::get_static()
784 776
 	 */
785 777
 	public function stat($name, $uncached = false) {
786  
-		return self::get_static(($this->class ? $this->class : get_class($this)), $name, $uncached);
  778
+		return Config::inst()->get(($this->class ? $this->class : get_class($this)), $name, Config::FIRST_SET);
787 779
 	}
788 780
 	
789 781
 	/**
790 782
 	 * @see Object::set_static()
791 783
 	 */
792 784
 	public function set_stat($name, $value) {
793  
-		self::set_static(($this->class ? $this->class : get_class($this)), $name, $value);
  785
+		Config::inst()->update(($this->class ? $this->class : get_class($this)), $name, $value);
794 786
 	}
795 787
 	
796 788
 	/**
797 789
 	 * @see Object::uninherited_static()
798 790
 	 */
799 791
 	public function uninherited($name) {
800  
-		return self::uninherited_static(($this->class ? $this->class : get_class($this)), $name);
  792
+		return Config::inst()->get(($this->class ? $this->class : get_class($this)), $name, Config::UNINHERITED);
801 793
 	}
802 794
 	
803 795
 	/**
2  dev/Deprecation.php
@@ -145,7 +145,7 @@ public static function notice($atVersion, $string = '') {
145 145
 
146 146
 			// Get the level to raise the notice as
147 147
 			$level = self::$notice_level;
148  
-			if (!$level) $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE;
  148
+			if (!$level) $level = E_USER_DEPRECATED;
149 149
 
150 150
 			// Then raise the notice
151 151
 			if(substr($string,-1) != '.') $string .= ".";
6  dev/SapphireTest.php
@@ -332,8 +332,8 @@ protected function idFromFixture($className, $identifier) {
332 332
 			$match = $fixture->idFromFixture($className, $identifier);
333 333
 			if($match) return $match;
334 334
 		}
335  
-		
336  
-		$fixtureFiles = Object::get_static(get_class($this), 'fixture_file');
  335
+
  336
+		$fixtureFiles = Config::inst()->get(get_class($this), 'fixture_file', Config::FIRST_SET);
337 337
 		user_error(sprintf(
338 338
 			"Couldn't find object '%s' (class: %s) in files %s",
339 339
 			$identifier,
@@ -381,7 +381,7 @@ protected function objFromFixture($className, $identifier) {
381 381
 			if($match) return $match;
382 382
 		}
383 383
 
384  
-		$fixtureFiles = Object::get_static(get_class($this), 'fixture_file');
  384
+		$fixtureFiles = Config::inst()->get(get_class($this), 'fixture_file', Config::FIRST_SET);
385 385
 		user_error(sprintf(
386 386
 			"Couldn't find object '%s' (class: %s) in files %s",
387 387
 			$identifier,
3  model/DataObject.php
@@ -2229,10 +2229,9 @@ function can($perm, $member = null) {
2229 2229
 							}
2230 2230
 					}
2231 2231
 
2232  
-					$this->set_uninherited('permissionCache', $permissionCache);
  2232
+					Config::inst()->update($this->class, 'permissionCache', $permissionCache);
2233 2233
 				}
2234 2234
 
2235  
-
2236 2235
 				if($permissionCache[$memberID][$perm]) {
2237 2236
 					return in_array($this->ID, $permissionCache[$memberID][$perm]);
2238 2237
 				}
2  model/Versioned.php
@@ -308,7 +308,7 @@ function augmentDatabase() {
308 308
 			else $table = $classTable;
309 309
 
310 310
 			if($fields = DataObject::database_fields($this->owner->class)) {
311  
-				$options = Object::get_static($this->owner->class, 'create_table_options');
  311
+				$options = Config::inst()->get($this->owner->class, 'create_table_options', Config::FIRST_SET);
312 312
 				$indexes = $this->owner->databaseIndexes();
313 313
 				if ($suffix && ($ext = $this->owner->getExtensionInstance($allSuffixes[$suffix]))) {
314 314
 					if (!$ext->isVersionedTable($table)) continue;
2  view/ViewableData.php
@@ -243,7 +243,7 @@ public function castingHelper($field) {
243 243
 			return $fieldSpec;
244 244
 		}
245 245
 
246  
-		$specs = Object::combined_static(get_class($this), 'casting');
  246
+		$specs = Config::inst()->get(get_class($this), 'casting');
247 247
 		if(isset($specs[$field])) return $specs[$field];
248 248
 
249 249
 		if($this->failover) return $this->failover->castingHelper($field);

0 notes on commit 4c6be29

Please sign in to comment.
Something went wrong with that request. Please try again.