Contao\Folder::renameTo PHP Method

renameTo() public method

Rename the folder
public renameTo ( string $strNewName ) : boolean
$strNewName string 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->strFolder, $strNewName);
        // Update the database AFTER the folder has been renamed
        $syncSource = \Dbafs::shouldBeSynchronized($this->strFolder);
        $syncTarget = \Dbafs::shouldBeSynchronized($strNewName);
        // Synchronize the database
        if ($syncSource && $syncTarget) {
            $this->objModel = \Dbafs::moveResource($this->strFolder, $strNewName);
        } elseif ($syncSource) {
            $this->objModel = \Dbafs::deleteResource($this->strFolder);
        } elseif ($syncTarget) {
            $this->objModel = \Dbafs::addResource($strNewName);
        }
        // Reset the object AFTER the database has been updated
        if ($return != false) {
            $this->strFolder = $strNewName;
        }
        return $return;
    }