Skip to content
This repository
Browse code

ENHANCEMENT Allow disabling of File::updateFilesystem() which is useful

for manually managing the filesystem paths instead. Defaults to on, but
useful to turn off when loading File records in a YAML fixture for test
data.
  • Loading branch information...
commit 7f60ced66be1037f3b579644205ef95c0b4db55c 1 parent f8d38a3
Sean Harvey authored

Showing 1 changed file with 5 additions and 2 deletions. Show diff stats Hide diff stats

  1. 7  filesystem/File.php
7  filesystem/File.php
@@ -149,7 +149,8 @@ class File extends DataObject {
149 149
 	 */
150 150
 	public static $apply_restrictions_to_admin = true;
151 151
 
152  
-	
  152
+	public static $update_filesystem = true;
  153
+
153 154
 	/**
154 155
 	 * Cached result of a "SHOW FIELDS" call
155 156
 	 * in instance_get() for performance reasons.
@@ -476,6 +477,8 @@ protected function onAfterWrite() {
476 477
 	 * (it might have been influenced by {@link setName()} or {@link setParentID()} before).
477 478
 	 */
478 479
 	public function updateFilesystem() {
  480
+		if(!self::$update_filesystem) return false;
  481
+
479 482
 		// Regenerate "Filename", just to be sure
480 483
 		$this->setField('Filename', $this->getRelativePath());
481 484
 		
@@ -511,7 +514,7 @@ public function updateFilesystem() {
511 514
 				// Only check if we're dealing with a file, otherwise the folder will need to be created
512 515
 				if(!file_exists(dirname($pathAfterAbs))) throw new Exception("Cannot move $pathBefore to $pathAfter - Directory " . dirname($pathAfter) . " doesn't exist");
513 516
 			} 
514  
-			
  517
+
515 518
 			// Rename file or folder
516 519
 			$success = rename($pathBeforeAbs, $pathAfterAbs);
517 520
 			if(!$success) throw new Exception("Cannot move $pathBeforeAbs to $pathAfterAbs");

0 notes on commit 7f60ced

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