/**
* Rename the file
*
* @param string $strNewName The new path
*
* @return boolean True if the operation was successful
*/
public function renameTo($strNewName)
{
$strParent = dirname($strNewName);
// Create the parent folder if it does not exist
if (!is_dir(TL_ROOT . '/' . $strParent)) {
new \Folder($strParent);
}
$return = $this->Files->rename($this->strFile, $strNewName);
// Update the database AFTER the file has been renamed
$syncSource = \Dbafs::shouldBeSynchronized($this->strFile);
$syncTarget = \Dbafs::shouldBeSynchronized($strNewName);
// Synchronize the database
if ($syncSource && $syncTarget) {
$this->objModel = \Dbafs::moveResource($this->strFile, $strNewName);
} elseif ($syncSource) {
$this->objModel = \Dbafs::deleteResource($this->strFile);
} elseif ($syncTarget) {
$this->objModel = \Dbafs::addResource($strNewName);
}
// Reset the object AFTER the database has been updated
if ($return != false) {
$this->strFile = $strNewName;
$this->arrImageSize = array();
$this->arrPathinfo = array();
}
return $return;
}