/** * @param \yii\base\Event $Event */ public function logDelete($Event) { $Storage = $this->getStorage(); /** @var BaseActiveRecord $Model */ $Model = $Event->sender; $attributes = $Model->attributes; $this->unsetIgnoreAttributes($attributes); /** @var Log $Log */ $Log = Instance::ensure(['class' => Log::className()]); $Log->action($Storage::ACTION_DELETE)->entity($Model)->changes(['delete' => $attributes]); $Storage::store($Log); }
/** * @inheritdoc */ public static function save() { /** @var Changelog $Model */ $Model = Instance::ensure(['class' => Changelog::className()]); /** @var Log $Log */ $Log = Instance::ensure(['class' => Log::className()]); $columns = $Log::schema(); $rows = []; $Logs = static::$storage; if (!empty($Logs)) { foreach ($Logs as $Log) { $rows[] = $Log->export(); } } if (!empty($rows)) { /** @var \yii\db\Connection $DB */ $DB = \Yii::$app->get('db'); $DB->createCommand()->batchInsert($Model::tableName(), $columns, $rows)->execute(); } }