数据库删除保存日志

@param $event
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();
    }
1310723
private function fireEvent($event)
    {
        $env = $this->formatEventName($event);

        if (emitter()->bound($env)) {
            emitter()->emit($env, $this);
        }
    }
741044
public function beforeSave($event)
    {
        list($id, $attribute) = $event->data;
        if (isset(self::$_executed[$id])) {
            return;
        }
        /* @var $object \yii\db\ActiveRecord */
        $object = $event->sender;
        if (is_string($this->format) && method_exists($object, $this->format)) {
            $value = call_user_func([$object, $this->format], $object, $attribute);
        } else {
            $value = is_callable($this->format) ? call_user_func($this->format, $object, $attribute) : $this->format;
        }
        $group = md5(serialize([
            'class' => $this->unique ? get_class($object) : false,
            'group' => $this->group,
            'attribute' => $attribute,
            'value' => $value
        ]));
        $model = Autonumber::findOne($group);
        if ($model) {
            $number = $model->number + 1;
        } else {
            $model = new Autonumber([
                'group' => $group
            ]);
            $number = 1;
        }
        $model->update_time = time();
        $model->number = $number;
        if ($value === null) {
            $object->$attribute = $number;
        } else {
            $object->$attribute = str_replace('?', $this->digit ? sprintf("%0{$this->digit}d", $number) : $number, $value);
        }
        self::$_executed[$id] = true;
        try {
            $model->save(false);
        } catch (\Exception $exc) {
            $event->isValid = false;
            if ($this->throwIsStale || !($exc instanceof StaleObjectException)) {
                throw $exc;
            }
        }
    }
1237957
public function handle(EventInterface $event)
    {
        /* @var \Swoft\Task\Event\Events\BeforeTaskEvent $beforeEvent*/
        $beforeEvent = $event;

        $logid = $beforeEvent->getLogid();
        $spanid = $beforeEvent->getSpanid();
        $method = $beforeEvent->getMethod();
        $taskClass = $beforeEvent->getTaskClass();
        $uri = sprintf('%s->%s', $taskClass, $method);

        $contextData = [
            'logid'       => $logid,
            'spanid'      => $spanid,
            'uri'         => $uri,
            'requestTime' => microtime(true)
        ];
        RequestContext::setContextData($contextData);

        // 日志初始化
        App::getLogger()->initialize();

        // 连接池初始化
    }
1342644
public function beforeSave($event) {
		if ($this->getOwner()->getIsNewRecord() && ($this->createAttribute !== null)) {
			$this->getOwner()->{$this->createAttribute} = $this->getTimestampByAttribute($this->createAttribute);
		}
		if ((!$this->getOwner()->getIsNewRecord() || $this->setUpdateOnCreate) && ($this->updateAttribute !== null)) {
			$this->getOwner()->{$this->updateAttribute} = $this->getTimestampByAttribute($this->updateAttribute);
		}
	}
827178
public function handle(Login $event)
    {
        $user = $event->user;
        $ip = $this->request->ip();
        $userAgent = $this->request->userAgent();
        $known = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first();

        $authenticationLog = new AuthenticationLog([
            'ip_address' => $ip,
            'user_agent' => $userAgent,
            'login_at' => Carbon::now(),
        ]);

        $user->authentications()->save($authenticationLog);

        if (! $known && config('authentication-log.notify')) {
            $user->notify(new NewDevice($authenticationLog));
        }
    }
65364
protected function _storeFile(Event $event) {
		try {
			$beforeEvent = $this->_beforeStoreFile($event);
			if ($beforeEvent->isStopped()) {
				return $beforeEvent->result;
			}

			$fileField = $this->getConfig('fileField');
			$entity = $event->getData('entity');
			$Storage = $this->getStorageAdapter($entity['adapter']);
			$Storage->write($entity['path'], file_get_contents($entity[$fileField]['tmp_name']), true);

			$event->result = $event->getSubject()->save($entity, [
				'checkRules' => false
			]);

			$this->_afterStoreFile($event);
			if ($event->isStopped()) {
				return $event->result;
			}

			return true;
		} catch (\Exception $e) {
			$this->log($e->getMessage(), LogLevel::ERROR, ['scope' => ['storage']]);
			throw new StorageException($e->getMessage(), $e->getCode(), $e);
		}

		return false;
	}
814184
public function save(IEvent $event)
    {
        $this->latestEvent = $event;

        if (null === $event->getId()) {
            $event->setId((string)Uuid::uuid4());
        }

        $filename = sprintf('%s.%s.event', $this->prepareFilename($event->getEndpoint()), $event->getId());

        $file = null;

        try {
            $filePath = $this->directory . '/' . $filename;

            if (!file_exists($filePath)) {
                $this->writer->open($filePath, 'w+');
                $this->writer->write($event->getMethod() . ' ' . $event->getEndpoint() . PHP_EOL);
                $this->writer->write($event->getReference() . PHP_EOL);
                $this->writer->write($event->getRequest() . PHP_EOL);
            } else {
                $this->writer->open($filePath, 'a');
                $this->writer->write($event->getLatency() . PHP_EOL);
                $this->writer->write($event->getResponse() . PHP_EOL);
            }
        } catch (Exception $e) {
            if (null !== $this->logger) {
                $this->logger->error($e);
            }
        } finally {
            if ($this->writer->isOpen()) {
                $this->writer->close();
            }
        }

        return $event;
    }
1194841
public function addLogRecord($event) {
        /**
         * If logging is enabled
         */
        if ($event->sender->module->enableLog) {

            $userId = \Yii::$app->user->id;
            $order = $event->model;

            $message = "ID: $order->id userId: $userId";

            Yii::info($message, $event->name);
        }
    }
114756
protected function beforeSave($event)
    {
        if ($this->autoSave) {
            $this->saveFile($this->owner->{$this->uploadAttribute}, $this->name, $this->path);
        }
    }
85254
public function logActivity($event)
    {
        // if cronjob / no user
        if (user()->id <= 0) {
            return;
        }

        // log adjustment
        LogAdminActivity::create([
            'subject_id'   => $this->id,
            'subject_type' => get_class($this),
            'name'         => $this->getActivityName($this, $event),
            'before'       => $this->before,
            'after'        => $this->after,
            'user_id'      => user()->id,
        ]);
    }
1289255
public function beforeLog(Event $event, array $logs)
    {
        foreach ($logs as $log) {
            $log->setMetaInfo($log->getMetaInfo() + $this->data);
        }
    }
353651
public function persistPageData($event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleDocument) {
            return;
        }

        $this->setPageData($document, $event->getNode(), $event->getLocale());
    }
1278686
public function addLogRecord($event) {
        /**
         * If logging is enabled
         */
        $module = \Yii::$app->getModule('cart');
        if ($module->enableLog) {

            $message = "UserId: $event->id";

            Yii::info($message, $event->name);
        }
    }
602046
public function attach($event)
    {
        $this->attachRows($event);
        $this->attachSeo($event);
        $this->attachAnonsModule($event);
    }
810820
public function fireEvent(string $event): void
    {
        $this->log->debug('Event {event} has been fired.', ['event' => $event]);
        foreach ($this->event_handlers as $handler) {
            /** @var EventHandler $handler */
            if ($event === $handler->getEvent()) {
                $handler->execute();
            }
        }
    }
946335
public function eventAfterDelete($event)
    {
        if ($this->isLoggable()) {
            Yii::$app->db->createCommand()->insert('{{%admin_ngrest_log}}', [
                'user_id' => $this->getUserId(),
                'timestamp_create' => time(),
                'route' => $this->route,
                'api' => $this->api,
                'is_insert' => false,
                'is_update' => false,
                'is_delete' => true,
                'attributes_json' => $this->toJson($event->sender->getAttributes()),
                'table_name' => $event->sender->tableName(),
                'pk_value' => implode("-", $event->sender->getPrimaryKey(true)),
            ])->execute();
        }
    }