mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API-CHANGE: Renaming a folder did not update the folder's filename on the disk. This is now fixed. There is now a one-to-one mapping between a folder and its "Title" label. Files still can have a Title that is different from the Filename (fixes #6088, thanks Pike)
This commit is contained in:
parent
a204c136fe
commit
5efdc60029
@ -18,7 +18,8 @@
|
||||
* - "Name": File name (including extension) or folder name.
|
||||
* Should be the same as the actual filesystem.
|
||||
* - "Title": Optional title of the file (for display purposes only).
|
||||
* Defaults to "Name".
|
||||
* Defaults to "Name". Note that the Title field of Folder (subclass of File)
|
||||
* is linked to Name, so Name and Title will always be the same.
|
||||
* - "Filename": Path of the file or folder, relative to the webroot.
|
||||
* Usually starts with the "assets/" directory, and has no trailing slash.
|
||||
* Defaults to the "assets/" directory plus "Name" property if not set.
|
||||
|
@ -304,6 +304,24 @@ class Folder extends File {
|
||||
|
||||
parent::onBeforeDelete();
|
||||
}
|
||||
|
||||
/** Override setting the Title of Folders to that Name, Filename and Title are always in sync.
|
||||
* Note that this is not appropriate for files, because someone might want to create a human-readable name
|
||||
* of a file that is different from its name on disk. But folders should always match their name on disk. */
|
||||
function setTitle($title) {
|
||||
$this->setField('Title',$title);
|
||||
parent::setName($title); //set the name and filename to match the title
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
$this->setField('Title',$name);
|
||||
parent::setName($name);
|
||||
}
|
||||
|
||||
function setFilename($filename) {
|
||||
$this->setField('Title',$filename);
|
||||
parent::setFilename($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the database record (recursively for folders) without touching the filesystem
|
||||
@ -457,4 +475,4 @@ HTML;
|
||||
|
||||
return $classes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,41 @@ class FileTest extends SapphireTest {
|
||||
$this->assertFileExists($filePath);
|
||||
$this->assertFalse(DataObject::get_by_id('File', $fileID));
|
||||
}
|
||||
|
||||
|
||||
function testRenameFolder() {
|
||||
$newTitle = "FileTest-folder-renamed";
|
||||
|
||||
//rename a folder's title
|
||||
$folderID = $this->objFromFixture("Folder","folder2")->ID;
|
||||
$folder = DataObject::get_by_id('Folder',$folderID);
|
||||
$folder->Title = $newTitle;
|
||||
$folder->write();
|
||||
|
||||
//get folder again and see if the filename has changed
|
||||
$folder = DataObject::get_by_id('Folder',$folderID);
|
||||
$this->assertEquals($folder->Filename, ASSETS_DIR ."/". $newTitle ."/", "Folder Filename updated after rename of Title");
|
||||
|
||||
|
||||
//rename a folder's name
|
||||
$newTitle2 = "FileTest-folder-renamed2";
|
||||
$folder->Name = $newTitle2;
|
||||
$folder->write();
|
||||
|
||||
//get folder again and see if the Title has changed
|
||||
$folder = DataObject::get_by_id('Folder',$folderID);
|
||||
$this->assertEquals($folder->Title, $newTitle2, "Folder Title updated after rename of Name");
|
||||
|
||||
|
||||
//rename a folder's Filename
|
||||
$newTitle3 = "FileTest-folder-renamed3";
|
||||
$folder->Filename = $newTitle3;
|
||||
$folder->write();
|
||||
|
||||
//get folder again and see if the Title has changed
|
||||
$folder = DataObject::get_by_id('Folder',$folderID);
|
||||
$this->assertEquals($folder->Title, $newTitle3, "Folder Title updated after rename of Filename");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function setUp() {
|
||||
@ -245,7 +279,7 @@ class FileTest extends SapphireTest {
|
||||
fwrite($fh, str_repeat('x',1000000));
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
parent::tearDown();
|
||||
@ -268,6 +302,10 @@ class FileTest extends SapphireTest {
|
||||
if(file_exists('../assets/FileTest')) Filesystem::removeFolder('../assets/FileTest');
|
||||
if(file_exists('../assets/FileTest-subfolder')) Filesystem::removeFolder('../assets/FileTest-subfolder');
|
||||
if(file_exists('../assets/FileTest.txt')) unlink('../assets/FileTest.txt');
|
||||
|
||||
if (file_exists("../assets/FileTest-folder-renamed1")) Filesystem::removeFolder("../assets/FileTest-folder-renamed1");
|
||||
if (file_exists("../assets/FileTest-folder-renamed2")) Filesystem::removeFolder("../assets/FileTest-folder-renamed2");
|
||||
if (file_exists("../assets/FileTest-folder-renamed3")) Filesystem::removeFolder("../assets/FileTest-folder-renamed3");
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user