Contao\DC_Folder::delete PHP Метод

delete() публичный Метод

Recursively delete files and folders
public delete ( string $source = null )
$source string
    public function delete($source = null)
    {
        if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable']) {
            throw new InternalServerErrorException('Table "' . $this->strTable . '" is not deletable.');
        }
        $blnDoNotRedirect = $source !== null;
        if ($source === null) {
            $source = $this->intId;
        }
        $this->isValid($source);
        // Delete the file or folder
        if (!file_exists(TL_ROOT . '/' . $source) || !$this->isMounted($source)) {
            throw new AccessDeniedException('File or folder "' . $source . '" is not mounted or cannot be found.');
        }
        // Call the ondelete_callback
        if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'])) {
            foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'] as $callback) {
                if (is_array($callback)) {
                    $this->import($callback[0]);
                    $this->{$callback[0]}->{$callback[1]}($source, $this);
                } elseif (is_callable($callback)) {
                    $callback($source, $this);
                }
            }
        }
        $this->import('Files');
        // Delete the folder or file
        if (is_dir(TL_ROOT . '/' . $source)) {
            $this->Files->rrdir($source);
        } else {
            $this->Files->delete($source);
        }
        // Update the database AFTER the resource has been deleted
        if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($source)) {
            \Dbafs::deleteResource($source);
        }
        // Add a log entry
        $this->log('File or folder "' . $source . '" has been deleted', __METHOD__, TL_FILES);
        // Redirect
        if (!$blnDoNotRedirect) {
            $this->redirect($this->getReferer());
        }
    }