/**
  * Remove old log records
  */
 public function actionLog()
 {
     $days = 180;
     echo "    > delete old log records older then last {$days} days...";
     $rows = BackendLogRecord::deleteAll(['<', 'log_time', time() - 86400 * intval($days)]);
     echo " affected {$rows} rows\n";
 }
 /**
  * Finds the BackendLogRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BackendLogRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BackendLogRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BackendLogRecord::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['log_time' => SORT_DESC]], 'pagination' => ['pagesize' => 50]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if (!empty($this->dateRange)) {
         list($dateFrom, $dateTo) = preg_split('/\\s+-\\s+/', $this->dateRange);
         $formatter = Yii::$app->formatter;
         $dateFrom = $formatter->asTimestamp($dateFrom, 'yyyy-MM-dd HH:mm:ss');
         $dateTo = $formatter->asTimestamp($dateTo, 'yyyy-MM-dd HH:mm:ss');
         $query->andWhere(['and', ['>=', 'log_time', $dateFrom], ['<=', 'log_time', $dateTo]]);
     }
     $query->andFilterWhere(['id' => $this->id, 'level' => $this->level]);
     $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'prefix', $this->prefix])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }