1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright(c) 2016 Webtools Ltd |
4
|
|
|
* @link https://github.com/thamtech/yii2-scheduler |
5
|
|
|
* @license https://opensource.org/licenses/MIT |
6
|
|
|
**/ |
7
|
|
|
|
8
|
|
|
namespace thamtech\scheduler\models\base; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
use yii\data\ActiveDataProvider; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This is the base-model class for table "scheduler_log". |
15
|
|
|
* |
16
|
|
|
* @property integer $id |
17
|
|
|
* @property integer $scheduler_task_id |
18
|
|
|
* @property string $started_at |
19
|
|
|
* @property string $ended_at |
20
|
|
|
* @property string $output |
21
|
|
|
* @property integer $error |
22
|
|
|
* |
23
|
|
|
* @property \thamtech\scheduler\models\SchedulerTask $schedulerTask |
24
|
|
|
*/ |
25
|
|
|
class SchedulerLog extends \yii\db\ActiveRecord |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
|
|
public static function tableName() |
31
|
|
|
{ |
32
|
|
|
return 'scheduler_log'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
public static function label($n = 1) |
39
|
|
|
{ |
40
|
|
|
return Yii::t('app', '{n, plural, =1{Scheduler Log} other{Scheduler Logs}}', ['n' => $n]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* |
45
|
|
|
*/ |
46
|
|
|
public function __toString() |
47
|
|
|
{ |
48
|
|
|
return (string) $this->id; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
*/ |
54
|
|
|
public function rules() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
[['scheduler_task_id', 'output'], 'required'], |
58
|
|
|
[['scheduler_task_id', 'error'], 'integer'], |
59
|
|
|
[['started_at', 'ended_at'], 'safe'], |
60
|
|
|
[['output'], 'string'] |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
|
|
public function attributeLabels() |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'id' => Yii::t('app', 'ID'), |
71
|
|
|
'scheduler_task_id' => Yii::t('app', 'Scheduler Task ID'), |
72
|
|
|
'started_at' => Yii::t('app', 'Started At'), |
73
|
|
|
'ended_at' => Yii::t('app', 'Ended At'), |
74
|
|
|
'output' => Yii::t('app', 'Output'), |
75
|
|
|
'error' => Yii::t('app', 'Error'), |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return \yii\db\ActiveQuery |
81
|
|
|
*/ |
82
|
|
|
public function getSchedulerTask() |
83
|
|
|
{ |
84
|
|
|
return $this->hasOne(\thamtech\scheduler\models\SchedulerTask::className(), ['id' => 'scheduler_task_id']); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Creates data provider instance with search query applied |
89
|
|
|
* |
90
|
|
|
* @param array $params |
91
|
|
|
* |
92
|
|
|
* @return ActiveDataProvider |
93
|
|
|
*/ |
94
|
|
|
public function search($params = null) |
95
|
|
|
{ |
96
|
|
|
$formName = $this->formName(); |
97
|
|
|
$params = !$params ? Yii::$app->request->get($formName, array()) : $params; |
98
|
|
|
$query = self::find(); |
99
|
|
|
|
100
|
|
|
$dataProvider = new ActiveDataProvider([ |
101
|
|
|
'query' => $query, |
102
|
|
|
'sort' => ['defaultOrder'=>['id'=>SORT_DESC]], |
103
|
|
|
]); |
104
|
|
|
|
105
|
|
|
$this->load($params, $formName); |
106
|
|
|
|
107
|
|
|
$query->andFilterWhere([ |
108
|
|
|
'id' => $this->id, |
109
|
|
|
'scheduler_task_id' => $this->scheduler_task_id, |
110
|
|
|
'error' => $this->error, |
111
|
|
|
]); |
112
|
|
|
|
113
|
|
|
$query->andFilterWhere(['like', 'started_at', $this->started_at]) |
114
|
|
|
->andFilterWhere(['like', 'ended_at', $this->ended_at]) |
115
|
|
|
->andFilterWhere(['like', 'output', $this->output]); |
116
|
|
|
|
117
|
|
|
return $dataProvider; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.