/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/models/BatchLogMongo.php
140 строк
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\models; use common\helpers\ArrayHelper; use Yii; use yii\helpers\Json; use yii\mongodb\ActiveRecord; use yii\web\ServerErrorHttpException; /** * This is the model class for table "batch_log". * * @property integer $request_batch_id * @property integer $request * @property integer $response * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2026 */ class BatchLogMongo extends ActiveRecord { /** * {@inheritdoc} */ public static function collectionName() { return 'batch_log_mongo'; } /** * @inheritdoc */ public function attributes() { return [ '_id', 'request_batch_id', 'request', 'response', ]; } /** * {@inheritdoc} */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [['request_batch_id'], 'required'], [ [ 'request', 'response', ], 'string' ], [['request_batch_id'], 'number'], ]); } /** * {@inheritdoc} */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'request_batch_id' => Yii::t('app', 'Request batch'), 'request' => Yii::t('app', 'Request'), 'response' => Yii::t('app', 'Response'), ]); } public static function getAlias() { return ''; } /** * Создать лог-запрос * @param $batch_id * @param $body * @return void * @throws ServerErrorHttpException * @throws \yii\db\Exception */ public static function createRequest($batch_id, $body) { $segment = Json::encode($body); $bl = BatchLogMongo::find() ->andWhere([ 'request_batch_id' => (int)$batch_id, ]) ->one(); if (!$bl) { $bl = new BatchLogMongo([ 'request_batch_id' => (int)$batch_id, ]); } $bl->setAttributes([ 'request' => $segment ]); if (!$bl->save()) { throw new ServerErrorHttpException(Yii::t('app', 'Error save BatchLog')); } } /** * Создать лог-ответ * @param $batch_id * @param $body * @return void * @throws ServerErrorHttpException * @throws \yii\db\Exception */ public static function createResponse($batch_id, $body) { $segment = Json::encode($body); $bl = BatchLogMongo::find() ->andWhere([ 'request_batch_id' => (int)$batch_id, ]) ->one(); if ($bl) { $bl->setAttributes([ 'response' => $segment ]); if (!$bl->save()) { throw new ServerErrorHttpException(Yii::t('app', 'Error save BatchLog')); } } } }