123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\models;
- use Yii;
- use walle\command\Command;
- class Record extends \yii\db\ActiveRecord
- {
-
- const ACTION_PERMSSION = 1;
-
- const ACTION_CLONE = 2;
-
- const ACTION_SYNC = 3;
-
- const ACTION_LINK = 4;
- public static $ACTION_PERCENT = [
- self::ACTION_PERMSSION => '25',
- self::ACTION_CLONE => '50',
- self::ACTION_SYNC => '75',
- self::ACTION_LINK => '100',
- ];
-
- public static function tableName()
- {
- return 'record';
- }
-
- public function rules()
- {
- return [
- [['user_id', 'task_id', 'status'], 'required'],
- [['user_id', 'task_id', 'status', 'created_at', 'duration', 'action'], 'integer'],
- [['memo', 'command'], 'string'],
- ];
- }
-
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => 'user_id',
- 'task_id' => 'task_id',
- 'status' => 'Status',
- 'created_at' => 'created_at',
- 'action' => 'action',
- 'duration' => 'duration',
- 'memo' => 'memo',
- ];
- }
-
- public static function saveRecord(Command $commandObj, $task_id, $action, $duration) {
- $record = new static();
- $record->attributes = [
- 'user_id' => \Yii::$app->user->id,
- 'task_id' => $task_id,
- 'status' => (int)$commandObj->getExeStatus(),
- 'action' => $action,
- 'created_at' => time(),
- 'command'=> var_export($commandObj->getExeCommand(), true),
- 'memo' => var_export($commandObj->getExeLog(), true),
- 'duration' => $duration,
- ];
- return $record->save();
- }
- }
|