Find changes to the model and save them as AuditField records.
Do not call this method directly, it will be called after the model is deleted.
@param CModelEvent $event
5554
public function afterDelete($event)
    {
        if (!$this->enableAuditField) {
            parent::afterDelete($event);
            return;
        }

        $date = time();
        $auditModels = $this->getAuditModels();
        $auditRequestId = $this->getAuditRequestId();
        $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0;
        $auditFields = array();

        // prepare the logs
        $pk = $this->getModelPrimaryKeyString($this->auditModel);
        foreach ($auditModels as $auditModel) {
            $prefix = isset($auditModel['prefix']) ? $auditModel['prefix'] . '.' . $pk : '';
            $auditFields[] = array(
                'old_value' => '',
                'new_value' => '',
                'action' => 'DELETE',
                'model_name' => $auditModel['model_name'],
                'model_id' => $auditModel['model_id'],
                'field' => $prefix . '*',
                'created' => $date,
                'user_id' => $userId,
                'audit_request_id' => $auditRequestId,
            );
        }

        // insert the audit_field records
        $this->addAuditFields($auditFields);

        parent::afterDelete($event);
    }
352113
protected function propagateEntityChangedEvent(EntityChangedEvent $event)
    {
        foreach ($this->listeners as $listener) {
            $listener->onEntityChanged($event);
        }
    }
1060310
public function saveFile(FileCreateOrUpdateEvent $event)
    {
        $model = $event->getModel();
        $model->setFile(sprintf("tmp/%s", $event->getUploadedFile()->getFilename()));
        $con = Propel::getWriteConnection(ProductImageTableMap::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $nbModifiedLines = $model->save($con);
            $event->setModel($model);

            if (!$nbModifiedLines) {
                throw new FileException(
                    sprintf(
                        'File "%s" (type %s) with parent id %s failed to be saved',
                        $event->getParentName(),
                        \get_class($model),
                        $event->getParentId()
                    )
                );
            }

            $newUploadedFile = $this->fileManager->copyUploadedFile($event->getModel(), $event->getUploadedFile());

            $event->setUploadedFile($newUploadedFile);
            $con->commit();
        } catch (\Exception $e) {
            $con->rollBack();

            throw $e;
        }
    }
172231
public function deleteRecord(): void
    {
        // Create a pending change
        if (!$this->isPendingDeletion()) {
            DB::table('change')->insert([
                'gedcom_id'  => $this->tree->id(),
                'xref'       => $this->xref,
                'old_gedcom' => $this->gedcom(),
                'new_gedcom' => '',
                'user_id'    => Auth::id(),
            ]);
        }

        // Auto-accept this pending change
        if (Auth::user()->getPreference('auto_accept')) {
            FunctionsImport::acceptAllChanges($this->xref, $this->tree);
        }

        // Clear the cache
        self::$gedcom_record_cache  = [];
        self::$pending_record_cache = [];

        Log::addEditLog('Delete: ' . static::RECORD_TYPE . ' ' . $this->xref, $this->tree);
    }
375722
public function saveVersionListener(MigrationEvent $event)
    {
        $version = $event->getVersion();
        $this->command->getStorage()->update($version);
    }
604680
public function triggerEvent(string $event): void
    {
        // TODO: use event library and allow attach events to IFile and ICacheStateful.
        // cache triggers
        if ($this->file instanceof ICacheStateful) {
            switch ($event) {
                case self::EVENT_CACHED:
                    $this->file->setCachedAt($this->name, time());
                    break;
                case self::EVENT_EMPTY:
                case self::EVENT_ERROR:
                case self::EVENT_NOT_FOUND:
                    // TODO: split those and save different cases of cache state.
                    $this->file->setCachedAt($this->name, null);
                    break;
            }

            $this->file->saveState();
        }

        // other triggers
    }
326933
public function afterDelete(Event $Event) {
		if ($this->_checkEvent($Event)) {
			$record = $Event->getData('record');
			$string = $this->_buildPath($record, true, null);
			if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') {
				$string = str_replace('\\', '/', $string);
			}
			try {
				$Storage = StorageManager::adapter($record['adapter']);
				if (!$Storage->has($string)) {
					$Event->stopPropagation();
					$Event->result = false;

					return false;
				}
				$Storage->delete($string);
			} catch (\Exception $e) {
				$this->log($e->getMessage());
				$Event->stopPropagation();
				$Event->result = false;

				return false;
			}
			$operations = Configure::read('FileStorage.imageSizes.' . $record['model']);
			if (!empty($operations)) {
				$Event->setData('operations', $operations);
				$this->_removeVersions($Event);
			}
			$Event->stopPropagation();
			$Event->result = true;

			return true;
		}
	}
1011092
final private function replayChange(Event $event)
    {
        $this->apply($event->payload());
        $this->lastCommittedEventSequenceNumber = $event->sequenceNumber();
    }
690432
public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $options) {
		$field = $this->getConfig('field');

		$value = $entity->get($field);
		if (!$value) {
			return;
		}

		$conditions = $this->buildConditions($entity);

		$order = $this->getConfig('findOrder');
		if ($order === null) {
			$order = [];
			if ($this->_table->getSchema()->getColumn('modified')) {
				$order['modified'] = 'DESC';
			}
		}
		$entity = $this->_table->find()->where($conditions)->order($order)->first();
		if (!$entity) {
			// This should be caught with a validation rule if at least one "primary" must exist
			return;
		}

		$entity->set($field, true);
		$this->_table->saveOrFail($entity);
	}
841517
public function onSaving($event, $payload) {

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

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

        // Loop through the all of the upload attributes ...
        event(new Events\HandlingSaving($model));
        foreach($attributes as $attribute) {

            // Check if there is an uploaded file in the upload attribute
            if (($file = $model->getAttribute($attribute))
                && is_a($file, UploadedFile::class)) {

                // Move the upload and get the new URL
                $url = $this->storage->moveUpload($file);
                $model->setUploadAttribute($attribute, $url);
            }

            // If the attribute field is dirty, delete the old file
            if ($model->isDirty($attribute)
                && !$this->keepsFilesOnDelete($model)
                && ($old = $model->getOriginal($attribute))) {
                $this->storage->delete($old);
            }
        }
        event(new Events\HandledSaving($model));
    }
971735
public function handlePersistStagedProperties(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$this->supportsBehavior($document)) {
            return;
        }

        $document->getStructure()->commitStagedData($event->getOption('clear_missing_content'));
    }
180098
public static function delete($event)
    {
        $desc = '<br>';
        foreach ($event->sender->getAttributes() as $name => $value) {
            $desc .= $event->sender->getAttributeLabel($name) . '(' . $name . ') => ' . $value . ',<br>';
        }
        $desc = substr($desc, 0, -5);
        $model = new AdminLogModel();
        $class = $event->sender->className();
        $id_des = '';
        if (isset($event->sender->id)) {
            $id_des = '{{%ID%}} ' . $event->sender->id;
        }
        $model->description = '{{%ADMIN_USER%}} [ ' . yii::$app->getUser()->getIdentity()->username . ' ] {{%BY%}} ' . $class . ' [ ' . $class::tableName() . ' ] ' . " {{%DELETED%}} {$id_des} {{%RECORD%}}: " . $desc;
        $model->route = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
        $model->user_id = yii::$app->getUser()->id;
        $model->save();
    }
846782
public function onDeleteRelation($event)
    {
        $sender = $event->sender;
        /* @var $sender static */
        if ($sender->relationType == static::$relationMutual) {
            $sender->off(static::EVENT_AFTER_DELETE, [$sender, 'onDeleteRelation']);
            static::removeAllRelations($sender->recipient, $sender->initiator);
            $sender->on(static::EVENT_AFTER_DELETE, [$sender, 'onDeleteRelation']);
        }
    }
268391
public static function onPostLoad(Event $event)
    {
        $revision = $event->getTarget();
        $dispatcher = $event->getDispatcher();
        $application = $dispatcher->getApplication();

        if (null !== $application) {
            $em = $application->getEntityManager();
            $revision
                ->setEntityManager($em)
                ->setToken($application->getBBUserToken())
            ;

            if (null === $revision->getContent()) {
                $db = $em->getConnection();
                $stmt = $db->executeQuery(
                    'SELECT `content_uid`, `classname` FROM `revision` WHERE `uid` = ?',
                    [$revision->getUid()]
                );

                $items = $stmt->fetchAll();
                if ($items) {
                    foreach ($items as $item) {
                        $content = $em->find(Revision::getFullClassname($item['classname']), $item['content_uid']);
                        if ($content) {
                            $revision->setContent($content);
                        }
                    }
                }
            }
        }

        $revision->postLoad();
    }
750795
private function captureStepEvent(Event $event)
    {
        if ($event instanceof AfterStepTested) {
            $this->afterStepTestedEvents[$event->getStep()->getLine()] = $event;
        }
        if ($event instanceof AfterStepSetup) {
            $this->afterStepSetupEvents[$event->getStep()->getLine()] = $event;
        }
    }
1366184
protected function filterFields(Event $event) : void
    {
        $panelActions = (array)Configure::read('CsvMigrations.panels.actions');
        $dynamicPanelActions = (array)Configure::read('CsvMigrations.panels.dynamic_actions');
        if (!in_array($this->request->getParam('action'), array_diff($panelActions, $dynamicPanelActions))) {
            return;
        }

        $controller = $event->getSubject();
        Assert::isInstanceOf($controller, Controller::class);

        $config = new ModuleConfig(ConfigType::MODULE(), $controller->getName());
        $config = json_encode($config->parse());
        $config = false === $config ? [] : json_decode($config, true);

        $panels = $this->getPanels($config, $controller->viewVars['entity']->toArray());
        if (! empty($panels['fail'])) {
            // filter out fields of hidden panels
            $controller->viewVars['fields'] = array_diff_key(
                $controller->viewVars['fields'],
                array_flip($panels['fail'])
            );
        }

        if ((string)Configure::read('CsvMigrations.batch.action') === $this->request->getParam('action')) {
            $this->filterBatchFields($event);
        }
    }
883339
public function after($event = []) {
		$modelDynSchema = ClassRegistry::init('CakeLdap.DynSchema');
		$modelDynSchema->updateSchema($event, $this->connection);
	}