Queues up this attachments files for deletion.

@param AttachableInterface $instance
340660
public function beforeDelete(AttachableInterface $instance)
    {
        $this->instance = $instance;

        if ( ! $this->config->preserveFiles()) {
            $this->clear();
        }
    }
985595
public function fileDelete($file)
    {
        foreach ($this->files($file) as $f) {
            if (!unlink($f) && $this->fileExists($f)) {
                throw new RuntimeException(['delete `:file` failed: :last_error_message', 'file' => $f]);
            }
        }
    }
1055469
public static function removeFile(string $file): void
    {
        if (\is_file($file)) {
            if (!@\unlink($file)) {
                throw new \RuntimeException(\sprintf('Unable to delete file "%s"%s', $file, self::getErrorInfo()));
            }
        }
        
        \clearstatcache(true, $file);
    }
838399
protected function queueAllForDeletion()
    {
        if (empty($this->getAttribute('filename'))) {
            return;
        }

        // Remove old files
        if ($this->config('preserve_files', false) === false) {
            foreach ($this->styles as $name => $style) {
                $this->setQueue('deletion', $this->path($name));
            }
        }

        // Set model attributes
        $this->instanceWrite('file_name', null);
        $this->instanceWrite('file_size', null);
        $this->instanceWrite('content_type', null);
        $this->instanceWrite('updated_at', null);
        $this->instanceWrite('queue_state', self::QUEUE_DONE);
        $this->instanceWrite('queued_file', null);
    }
998974
@Override
    public void deleteInstance(String instanceId) {
        modifyInstance(instanceId, map -> {
            Instance deletedInstance = map.remove(instanceId);
            getDeletedInstancesByIdMap().put(deletedInstance.getId(), deletedInstance);
        });
    }
1210895
public function remove($id)
    {
        if ($this->fileSystem->has($id)) {
            $this->fileSystem->delete($id);
        }
    }
449158
public function can_delete_instance($instance) {
        global $DB;

        $context = context_course::instance($instance->courseid);
        if (!has_capability('enrol/category:config', $context)) {
            return false;
        }

        if (!enrol_is_enabled('category')) {
            return true;
        }
        // Allow delete only when no synced users here.
        return !$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id));
    }
1264468
public function attachFiles($id, $table, $files)
    {
        foreach ($files as $file) {
            if (!empty($file)) {
                $this->attachFile($id, $table, $file);
            }
        }
    }
164090
private function callInitMethod($instance)
    {
        $args = [];
        foreach ($this->init_method_args as $arg) {
            if (is_string($arg) && preg_match('/^\$([\w_]+)$/', $arg, $matches)) {
                $arg = $this->container->get($matches[1]);
            }
            $args[] = $arg;
        }
        call_user_func_array(array($instance, $this->init_method_name), $args);
    }
390088
public function delete_instance(int $instanceid) {
        $fielddata = api::get_instance_fields_data($this->get_fields(), $instanceid, false);
        foreach ($fielddata as $data) {
            $data->delete();
        }
    }
2590
protected function handleFiles($object)
    {
        $request = $this->getRequest();

        $rc = new \ReflectionClass($object);
        $className = $rc->getShortName();

        $repo = $this->manager->getRepository('LibrinfoMediaBundle:File');

        if ($remove = $request->get('remove_files')) {
            foreach ($remove as $key => $id) {
                $file = $repo->find($id);

                if ($file) {
                    if (method_exists($object, 'removeLibrinfoFile')) {
                        $object->removeLibrinfoFile($file);
                        $this->manager->remove($file);
                    } elseif (method_exists($object, 'setLibrinfoFile')) {
                        $object->setLibrinfoFile();
                        $this->manager->remove($file);
                    } else {
                        throw new \Exception('You must define ' . $className . '::removeLibrinfoFile() method or ' . $className . '::setFile() in case of a one to one');
                    }
                }
            }
        }

        if ($ids = $request->get('add_files')) {
            foreach ($ids as $key => $id) {
                $file = $repo->find($id);

                if ($file) {
                    if (method_exists($object, 'addLibrinfoFile')) {
                        $object->addLibrinfoFile($file);
                        $file->setOwned(true);
                    } elseif (method_exists($object, 'setLibrinfoFile')) {
                        $object->setLibrinfoFile($file);
                        $file->setOwned(true);
                    } else {
                        throw new \Exception('You must define ' . $className . '::addLibrinfoFile() method or ' . $className . '::setLibrinfoFile() in case of a one to one');
                    }
                }
            }
        }
    }
194572
public function detach(ObserverInterface $observer)
    {
        $observers = $this->getObservers();

        foreach ($observer->getEvents() as $event) {
            $count = count($observers[$event]);

            for ($i = 0; $i < $count; $i++) {
                if ($observers[$event][$i] == $observer) {
                    unset($observers[$event][$i]);
                }
            }
        }

        $this->setObservers($observers);
    }
469169
public function remove(AbstractEntity $instance)
    {
        $class = get_class($instance);
        $entityPool = $this->pool[$class] ?? [];
        $id = '' . $instance->id;
        if (isset($entityPool[$id])) {
            unset($entityPool[$id]);
            $this->pool[$class] = $entityPool;
        }
        unset($instance);

        return true;
    }
1269687
private function handlePropertyFileTreeOrder(PropertyInterface $property, ModelInterface $model)
    {
        if ('fileTreeOrder' !== $property->getWidgetType()) {
            return;
        }

        $model->setMeta($model::CSS_ROW_CLASS, 'invisible');
    }
619759
public static function swap($instance)
    {
        static::$resolvedInstance[static::getFacadeAccessor()] = $instance;

        if (isset(static::$app)) {
            static::$app->instance(static::getFacadeAccessor(), $instance);
        }
    }
1266469
public function release(ConnectionInterface $connection)
    {
        $connectionId = $connection->getConnectionId();
        if($this->hasContextConnection($connectionId)) {
            $connection->updateLastTime();
            $connection->setRecv(true);
            $connection->setAutoRelease(true);

            if (App::isCoContext()) {
                $this->releaseToChannel($connection);
            } else {
                $this->releaseToQueue($connection);
            }

            $this->removeContextConnection($connectionId);
        }
    }
806166
public function processQueue(Model $instance, $path = null, bool $cleanup = true)
    {
        $this->setInstance($instance);

        // Determine the path to use
        $path = $path ?: $this->getQueuedFilePath();

        // Set the file for processing
        $this->addUploadedFile($path);

        // Start processing the file
        $this->save();

        // Save all updated model attributes
        $this->getInstance()->save();

        // TODO: also remove non-local files
        // Remove queued file locally
        if ($cleanup === true && realpath($path) !== false) {
            @unlink($path);
            @rmdir(dirname($path));
        }
    }