app/Http/Controllers/AdminSiteController.php
public function cleanDataAction(ServerRequestInterface $request, FilesystemInterface $filesystem): ResponseInterface
    {
        $to_delete = (array) $request->get('to_delete');
        $to_delete = array_filter($to_delete);

        foreach ($to_delete as $path) {
            $metadata = $filesystem->getMetadata($path);

            if ($metadata === false) {
                // Already deleted?
                continue;
            }

            if ($metadata['type'] === 'dir') {
                try {
                    $filesystem->deleteDir($path);

                    FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', e($path)), 'danger');
                }
            }

            if ($metadata['type'] === 'file') {
                try {
                    $filesystem->delete($path);

                    FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger');
                }
            }
        }

        return redirect(route('admin-clean-data'));
    }
public function cleanDataAction(ServerRequestInterface $request, FilesystemInterface $filesystem): ResponseInterface
    {
        $to_delete = (array) $request->get('to_delete');
        $to_delete = array_filter($to_delete);

        foreach ($to_delete as $path) {
            $metadata = $filesystem->getMetadata($path);

            if ($metadata === false) {
                // Already deleted?
                continue;
            }

            if ($metadata['type'] === 'dir') {
                try {
                    $filesystem->deleteDir($path);

                    FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', e($path)), 'danger');
                }
            }

            if ($metadata['type'] === 'file') {
                try {
                    $filesystem->delete($path);

                    FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger');
                }
            }
        }

        return redirect(route('admin-clean-data'));
    }
public function cleanDataAction ( ServerRequestInterface $ request , FilesystemInterface $ filesystem ) : ResponseInterface { $ to_delete = ( array ) $ request -> get ( 'to_delete' ) ; $ to_delete = array_filter ( $ to_delete ) ; foreach ( $ to_delete as $ path ) { $ metadata = $ filesystem -> getMetadata ( $ path ) ; if ( $ metadata === false ) { // Already deleted? continue ; } if ( $ metadata [ 'type' ] === 'dir' ) { try { $ filesystem -> deleteDir ( $ path ) ; FlashMessages :: addMessage ( I18N :: translate ( 'The folder %s has been deleted.' , e ( $ path ) ) , 'success' ) ; } catch ( Exception $ ex ) { FlashMessages :: addMessage ( I18N :: translate ( 'The folder %s could not be deleted.' , e ( $ path ) ) , 'danger' ) ; } } if ( $ metadata [ 'type' ] === 'file' ) { try { $ filesystem -> delete ( $ path ) ; FlashMessages :: addMessage ( I18N :: translate ( 'The file %s has been deleted.' , e ( $ path ) ) , 'success' ) ; } catch ( Exception $ ex ) { FlashMessages :: addMessage ( I18N :: translate ( 'The file %s could not be deleted.' , e ( $ path ) ) , 'danger' ) ; } } } return redirect ( route ( 'admin-clean-data' ) ) ; }
Delete old user files in the data folder.

@param ServerRequestInterface $request
@param FilesystemInterface    $filesystem

@return ResponseInterface
Delete old user files in the data folder .