A model has been deleted, trash all of it's files

@param  string $event
@param  array $payload containg:
- Illuminate\Database\Eloquent\Model
@return void
423796
public function onDeleted($event, $payload) {

        // Destructure params
        list($model) = $payload;

        // If the model is soft deleted and the config states to NOT delete if
        // soft deleted, abort here.
        if ($this->keepsFilesOnDelete($model)) return;

        // Check that the model supports uploads through Upchuck
        if (!$this->supportsUploads($model)
            || !($attributes = $model->getUploadAttributes())) return;

        // Loop through the all of the upload attributes and get the values using
        // "original" so that you get the file value before it may have been cleared.
        event(new Events\HandlingDeleted($model));
        foreach($attributes as $attribute) {
            if (!$url = $model->getOriginal($attribute)) continue;
            $this->storage->delete($url);
        }
        event(new Events\HandledDeleted($model));
    }
465341
public function onStorageEventPostSave(StorageEvent $event)
    {
        /** @var Entity\Users $userEntity */
        $userEntity = $event->getContent();
        if (!$userEntity instanceof Entity\Users) {
            return;
        }

        if (!$userEntity->isEnabled()) {
            $this->deleteAuthtokens($userEntity);
            $this->deleteSessions($userEntity);
        }
    }
902814
public function beingDeleted($payload)
    {
        $type = get_class($payload);
        $id = $payload->id;

        Translation::where('entity_id', $id)->where('entity_type', $type)->delete();
        Archive::where('entity_id', $id)->where('entity_type', $type)->delete();

        Archive::where('entity_type', 'Grafite\Cms\Models\Translation')
            ->where('entity_data', 'LIKE', '%"entity_id":'.$id.'%')
            ->where('entity_data', 'LIKE', '%"entity_type":"'.$type.'"%')
            ->delete();

        if ($type == 'Grafite\Cms\Models\Page') {
            Link::where('page_id', $id)->delete();
        }
    }
389223
protected function resolveAndFire(array $payload)
	{
		list($class, $method) = $this->parseJob($payload['job']);

		$this->instance = $this->resolve($class);

		$this->instance->{$method}($this, $payload['data']);
	}
1262898
public function notify($event, $payload)
    {
        $result = null;

        foreach ($this->handlers as $condition => $handlers) {
            if ('*' === $condition || ($condition & $event) === $event) {
                foreach ($handlers as $handler) {
                    if ($clause = $this->clauses[spl_object_hash((object) $handler)] ?? null) {
                        if ($clause->intercepted($payload)) {
                            continue;
                        }
                    }
                    $response = $this->callHandler($handler, $payload);

                    switch (true) {
                        case $response instanceof TerminateResult:
                            return $response->content;
                        case true === $response:
                            continue 2;
                        case false === $response:
                            break 2;
                        case !empty($response) && !($result instanceof FinallyResult):
                            $result = $response;
                    }
                }
            }
        }

        return $result instanceof FinallyResult ? $result->content : $result;
    }
715192
public function fireEvent($event, $halt = true, Model $model = null, ...$payload)
    {
        if (! isset(self::$dispatcher)) {
            return true;
        }

        if (is_null($model)) {
            $model = $this->getModel();
        }

        // We will append the names of the class to the event to distinguish it from
        // other model events that are fired, allowing us to listen on each model
        // event set individually instead of catching event for all the models.
        $event = "sleeping_owl.section.{$event}: ".$this->getClass();

        // Laravel 5.8 and 5.4 support fire method
        if (version_compare('5.8.0', $this->app->version(), '<=') ||
            version_compare('5.5.0', $this->app->version(), '>')) {
            $fireMethod = 'dispatch';
        } else {
            $fireMethod = 'fire';
        }

        $method = $halt ? 'until' : $fireMethod;

        array_unshift($payload, $this, $model);

        return self::$dispatcher->$method($event, $payload);
    }
12042
protected function doSendEvent(Event $event): void
    {
        if (!$this->shouldUseGearman()) {
            $this->locator->getEventBus()->receiveEvent($event);
            return;
        }

        $envelope = new TransportEnvelope($event, 'php');
        $channel = $this->router->forEvent($event);

        try {
            $client = $this->getClient();
            @$client->doBackground($channel, $envelope->toString(), (string)$event->get('event_id'));
            $this->validateReturnCode($client, $channel);
        } catch (\GearmanException $ge) {
            if (isset(self::$reconnectCodes[$ge->getCode()])) {
                $this->destroyClient();
                $this->locator->getEventBus()->receiveEvent($event);
                return;
            }

            throw $ge;
        } catch (\Throwable $e) {
            throw $e;
        }
    }
227847
protected function doSendEvent(Event $event): void
    {
        $envelope = new TransportEnvelope($event, 'json');
        $this->client->putRecord([
            'StreamName'   => $this->router->forEvent($event),
            'PartitionKey' => $this->router->partitionForEvent($event),
            'Data'         => $envelope->toString(),
        ]);
    }
1059688
public function triggerEvent($event, Payload $payload)
    {
        if ($payload->state() === null) {
            $this->updatePayload($this->process->initialState(), $payload);
        }

        $state = $this->process->state($payload->state());

        $nextStateName = $state->triggerEvent($event, $payload);
        if ($nextStateName === null) {
            return;
        }

        $state = $this->process->state($nextStateName);

        $this->updatePayload($state, $payload);
        $this->handleOnStateWasSet($state, $payload);
    }
240035
public function beforeDelete($event)
    {
        $oldId = $this->owner->{$this->savedAttribute};
        if (($oldModel = FileModel::findOne($oldId)) !== null) {
            $event->isValid = $event->isValid && $oldModel->delete();
        }
    }
27224
public function has($event)
    {
        list($event, $payload) = $this->parseEventAndPayload($event, []);

        return array_key_exists($event, $this->listeners);
    }
141927
function (state, payload) {
        if (payload && payload.entity) {
            (new Query(state, payload.entity)).deleteAll();
            return;
        }
        Query.deleteAll(state);
    }
1111736
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        //Deletes the file
        @unlink($entity->path);

        parent::afterDelete($event, $entity, $options);
    }
783915
public function onStorageEventPreDelete(StorageEvent $event)
    {
        /** @var Entity\Users $userEntity */
        $userEntity = $event->getContent();
        if (!$userEntity instanceof Entity\Users) {
            return;
        }

        $this->deleteAuthtokens($userEntity);
        $this->deleteSessions($userEntity);
    }
793454
public static function clear(string $event = '') {
		if (empty($event)) {
			self::$events = [];
		} else {
			self::$events[$event] = [];
		}
	}
290149
public function delete($data)
	{
		switch(gettype($data))
		{
			case 'object':
				$deleted = $data->delete();
			break;

			case 'array':
				$query = $this->model;

				// Delete w/ where clauses.
				if($this->isAssociative($data))
				{
					foreach($data as $key => $value)
					{
						$query = $query->where($key, '=', $value);
					}
				}
				// Delete multiple by array of keys.
				else
				{
					$query = $query->whereIn('id', $data);
				}

				$deleted = $query->delete();
			break;

			default:
				$deleted = false;
		}

		if($deleted)
		{
			return new Payload($data, 'deleted');
		}

		return new Payload($data, 'not_deleted');
	}
805448
public function handle($event, $payload)
    {
        list($model) = $payload;
        
        if (!empty($model->locale)
            && empty($model->locale_group)
            && !is_a($model, Element::class) // Elements don't have groups
            && ($locales = Config::get('decoy.site.locales'))
            && count($locales) > 1) {
            $model->setAttribute('locale_group', Str::random());
        }
    }