afterSave Event

@param \Cake\Event\Event $event Event
@param \Cake\ORM\Entity $entity Record
@return void
975075
public function afterSave(Event $event, Entity $entity): void
    {
        $fields = array_merge([
            $this->_table->getPrimaryKey(),
            $this->getConfig('sortField'),
        ], $this->getConfig('columnScope'));
        $savedEntity = $this->_table->get($entity->get($this->_table->getPrimaryKey()), [
            'fields' => $fields,
        ]);
        $scope = $this->getConfig('scope');

        foreach ($this->getConfig('columnScope') as $column) {
            $scope[$column] = $savedEntity->get($column);
        }
        $entitySort = $savedEntity->{$this->getConfig('sortField')};
        $entityId = $entity->get($this->_table->getPrimaryKey());

        if (empty($entitySort)) {
            $nextSortValue = $this->getNextSortValue($scope);
            $this->_table->updateAll([
                $this->getConfig('sortField') => $nextSortValue,
            ], [
                $this->_table->getPrimaryKey() => $entityId,
            ]);
        } else {
            if ($entitySort < $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} <" . $this->__originalSortValue;
                $currentScope[] = "{$this->getConfig('sortField')} >=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' + 1'),
                ]);
                $query->execute();
            } elseif ($entitySort > $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} >" . $this->__originalSortValue;
                $currentScope[] = "{$this->getConfig('sortField')} <=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' - 1'),
                ]);
                $query->execute();
            } elseif ($entitySort == $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} >=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' + 1'),
                ]);
                $query->execute();
            }
        }
        $this->__originalSortValue = null;
    }
1290323
public function afterFind($event)
    {
        $this->_dbAttributes = $this->owner->getAttributes();
        parent::afterFind($event);
    }
1031482
public function afterDelete(Event $event, Entity $entity) {
        // configuration set?
        $this->check();

        // delete existing files linked to this entity
        foreach($this->_config['fields'] as $field => $path)
            $this->deleteFile($entity->get($field));
    }
1111736
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        //Deletes the file
        @unlink($entity->path);

        parent::afterDelete($event, $entity, $options);
    }
618460
public function afterStore(Event $event) {
		$this->pathBuilder($event->getSubject()->pathBuilder());
		$this->subject = $event->getSubject();

		$this->autoProcessImageVersions($event->getData('entity'), 'create');
	}
222094
public function beforeSave($event, $entity, $options)
    {
        $auth = Configure::read('GlobalAuth');
        $id = $auth['id'];

        if ($entity->isNew()) {
            if ($this->config('created_by')) {
                $entity->set($this->config('created_by'), $id);
            }
        }

        if ($this->config('modified_by')) {
            $entity->set($this->config('modified_by'), $id);
        }
    }
590157
public function beforeSave($event, $entity, $options)
    {
        $uploads = [];
        $fields = $this->getFieldList();
        foreach ($fields as $field => $data) {
            if (!is_string($entity->get($field))) {
                $uploads[$field] = $entity->get($field);
                $entity->set($field, null);
            }

            if (!$entity->isNew()) {
                $dirtyField = $entity->dirty($field);
                $originalField = $entity->getOriginal($field);
                if ($dirtyField && !is_null($originalField) && !is_array($originalField)) {
                    $fieldConfig = $this->config($field);

                    if ($fieldConfig['removeFileOnUpdate']) {
                        $this->_removeFile($entity->getOriginal($field));
                    }
                }
            }
        }
        $this->_uploads = $uploads;
    }
568720
public function setEntity(Entity $entity)
    {
        /** @var SharedEventManager $events */
        $events = $this->getContainer()->get('sharedEventManager');
        $events->attach(
            get_class($entity),
            Save::BEFORE_SAVE,
            [$this, 'beforeSave']
        );
        $events->attach(
            get_class($entity),
            Select::BEFORE_SELECT,
            [$this, 'beforeSelect']
        );
        $events->attach(
            get_class($entity),
            Select::AFTER_SELECT,
            [$this, 'afterSelect']
        );
        $this->getContainer()->set('sharedEventManager', $events);
        return parent::setEntity($entity);
    }
907387
public function afterAction($event)
    {
        if ($this->schedule) {
            if ($event->result === false) {
                $exitCode = CronScheduleStatus::ERROR;
            } else {
                $exitCode = CronScheduleStatus::SUCCESS;
            }
            $this->schedule->endCronSchedule($exitCode);
            $this->schedule = null;
        }
    }
909094
public function persist(AbstractEntity $entity)
    {
        if ($this->prepareEntityForPersist($entity)) {
            $this->getRepository()->persist($entity);
        }

        $this->afterPersist($entity);
    }
363168
public function moveAfter($entity)
    {
        if ($this->parent_id == $entity->parent_id) {
            $this->position = $entity->position + 1;
            $this->save();
        } else {
            $this->moveTo($entity->position + 1, $entity->parent_id);
        }
    }
1317091
public function afterSave(Event $event, EntityInterface $entity)
    {
        $uploads = $entity->get($this->config('formFieldName'));
        if (!empty($uploads)) {
            $this->Attachments->addUploads($entity, $uploads);
        }
    }
611796
public function save(AbstractEntity $entity)
    {
        if (empty($entity->getId())) {
            $this->getEntityManager()->persist($entity);
        }
        $this->getEntityManager()->flush($entity);
    }
898493
public function afterSave(Event $event, Entity $entity, ArrayObject $options)
    {
        //Creates the folder
        (new Folder($entity->path, true, 0777));

        parent::afterSave($event, $entity, $options);
    }
1253414
public function setEvent(Event $e) : void
    {
        if ( ! $e instanceof DoctrineEvent) {
            $eventParams = $e->getParams();
            $e = new DoctrineEvent();
            $e->setParams($eventParams);
            unset($eventParams);
        }
        $this->event = $e;
    }
921565
public function afterPaginate(Event $event)
    {
        $event;
        if (!$this->_table()->behaviors()->has('Search')) {
            return;
        }

        $enabled = $this->getConfig('enabled') ?: !$this->_request()->is('api');
        if (!$enabled) {
            return;
        }

        $fields = $this->fields();
        $this->_controller()->set('searchInputs', $fields);
    }
943935
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options)
    {
        if (!$this->config('status')) {
            return true;
        }

        // as we don't know entity's ID on beforeSave, we must delay values storage;
        // all this occurs inside a transaction so we are safe
        if (!empty($this->_cache['createValues'])) {
            foreach ($this->_cache['createValues'] as $valueEntity) {
                $valueEntity->set('entity_id', $this->_toolbox->getEntityId($entity));
                $valueEntity->unsetProperty('id');
                TableRegistry::get('Eav.EavValues')->save($valueEntity);
            }
            $this->_cache['createValues'] = [];
        }

        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            $field->afterSave();
        }

        if ($this->config('cacheMap')) {
            $this->updateEavCache($entity);
        }

        return true;
    }