src/Model/Behavior/UploadBehavior.php
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        $result = true;

        foreach ($this->getConfig(null, []) as $field => $settings) {
            if (in_array($field, $this->protectedFieldNames) || Hash::get($settings, 'keepFilesOnDelete', true)) {
                continue;
            }

            $dirField = Hash::get($settings, 'fields.dir', 'dir');
            if ($entity->has($dirField)) {
                $path = $entity->get($dirField);
            } else {
                $path = $this->getPathProcessor($entity, $entity->get($field), $field, $settings)->basepath();
            }

            $callback = Hash::get($settings, 'deleteCallback', null);
            if ($callback && is_callable($callback)) {
                $files = $callback($path, $entity, $field, $settings);
            } else {
                $files = [$path . $entity->get($field)];
            }

            $writer = $this->getWriter($entity, [], $field, $settings);
            $success = $writer->delete($files);

            if ($result && (new Collection($success))->contains(false)) {
                $result = false;
            }
        }

        return $result;
    }
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        $result = true;

        foreach ($this->getConfig(null, []) as $field => $settings) {
            if (in_array($field, $this->protectedFieldNames) || Hash::get($settings, 'keepFilesOnDelete', true)) {
                continue;
            }

            $dirField = Hash::get($settings, 'fields.dir', 'dir');
            if ($entity->has($dirField)) {
                $path = $entity->get($dirField);
            } else {
                $path = $this->getPathProcessor($entity, $entity->get($field), $field, $settings)->basepath();
            }

            $callback = Hash::get($settings, 'deleteCallback', null);
            if ($callback && is_callable($callback)) {
                $files = $callback($path, $entity, $field, $settings);
            } else {
                $files = [$path . $entity->get($field)];
            }

            $writer = $this->getWriter($entity, [], $field, $settings);
            $success = $writer->delete($files);

            if ($result && (new Collection($success))->contains(false)) {
                $result = false;
            }
        }

        return $result;
    }
public function afterDelete ( Event $ event , Entity $ entity , ArrayObject $ options ) { $ result = true ; foreach ( $ this -> getConfig ( null , [ ] ) as $ field => $ settings ) { if ( in_array ( $ field , $ this -> protectedFieldNames ) || Hash :: get ( $ settings , 'keepFilesOnDelete' , true ) ) { continue ; } $ dirField = Hash :: get ( $ settings , 'fields.dir' , 'dir' ) ; if ( $ entity -> has ( $ dirField ) ) { $ path = $ entity -> get ( $ dirField ) ; } else { $ path = $ this -> getPathProcessor ( $ entity , $ entity -> get ( $ field ) , $ field , $ settings ) -> basepath ( ) ; } $ callback = Hash :: get ( $ settings , 'deleteCallback' , null ) ; if ( $ callback && is_callable ( $ callback ) ) { $ files = $ callback ( $ path , $ entity , $ field , $ settings ) ; } else { $ files = [ $ path . $ entity -> get ( $ field ) ] ; } $ writer = $ this -> getWriter ( $ entity , [ ] , $ field , $ settings ) ; $ success = $ writer -> delete ( $ files ) ; if ( $ result && ( new Collection ( $ success ) ) -> contains ( false ) ) { $ result = false ; } } return $ result ; }
Deletes the files after the entity is deleted

@param \Cake\Event\Event $event The afterDelete event that was fired
@param \Cake\ORM\Entity $entity The entity that was deleted
@param \ArrayObject $options the options passed to the delete method
@return void|false
Deletes the files after the entity is deleted