/** * @return array */ public static function fileFilter() { $files = AuditEntry::getDb()->cache(function () { return AuditError::find()->distinct(true)->select('file')->where(['is not', 'file', null])->groupBy('file')->orderBy('file ASC')->column(); }, 30); return array_combine($files, $files); }
public function search($params) { $query = AuditError::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); // load the search form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } // adjust the query by adding the filters $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'file', $this->file]); $query->andFilterWhere(['line' => $this->line]); return $dataProvider; }
/** * Email errors to support email. */ public function actionErrorEmail() { $email = Yii::$app->params['supportEmail']; // find all errors to email $batch = AuditError::find()->where(['emailed' => 0])->batch(); foreach ($batch as $auditErrors) { /** @var AuditError $model */ foreach ($auditErrors as $model) { // define params and message $url = ['audit/default/view', 'id' => $model->entry_id]; $params = ['entry_id' => $model->entry_id, 'message' => $model->message, 'file' => $model->file, 'line' => $model->line, 'url' => Url::to($url), 'link' => Html::a(Yii::t('audit', 'view audit entry'), $url)]; $message = ['subject' => Yii::t('audit', 'Audit Error in Audit Entry #{entry_id}', $params), 'text' => Yii::t('audit', '{message}' . "\n" . 'in {file} on line {line}.' . "\n" . '-- {url}', $params), 'html' => Yii::t('audit', '<b>{message}</b><br />in <i>{file}</i> on line <i>{line}</i>.<br/>-- {link}', $params)]; // send email Yii::$app->mailer->compose()->setFrom([$email => 'Audit :: ' . Yii::$app->name])->setTo($email)->setSubject($message['subject'])->setTextBody($message['text'])->setHtmlBody($message['html'])->send(); // mark as emailed $model->emailed = 1; $model->save(false, ['emailed']); } } }
/* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('audit', 'Audit Module'); $this->params['breadcrumbs'][] = $this->title; $this->registerCss('canvas {width: 100% !important;height: 400px;}'); $dataSet = ['fillColor' => "rgba(151,187,205,0.5)", 'strokeColor' => "rgba(151,187,205,1)", 'pointColor' => "rgba(151,187,205,1)", 'pointStrokeColor' => "#fff"]; $options = ['height' => 400, 'width' => 400]; $days = []; $count = ['entry' => [], 'trail' => [], 'javascript' => [], 'error' => []]; foreach (range(-6, 0) as $day) { $date = strtotime($day . 'days'); $days[] = date('D: Y-m-d', $date); $count['entry'][] = AuditEntry::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['trail'][] = AuditTrail::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['mail'][] = AuditMail::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['javascript'][] = AuditJavascript::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); $count['error'][] = AuditError::find()->where(['between', 'created', date('Y-m-d 00:00:00', $date), date('Y-m-d 23:59:59', $date)])->count(); } //fake data //foreach ($count as $type => $data) { // foreach ($data as $k => $v) { // if (!$v) { // $v = $type == 'entry' ? rand(100, 1000) : rand(0, 100); // $count[$type][$k] = $v; // } // } //} ?> <div class="audit-index"> <h1><?php echo Html::encode($this->title);
/** * @return mixed * @throws \Exception */ protected static function filterData() { return AuditEntry::getDb()->cache(function () { return AuditError::find()->distinct(true)->select(['hash', 'message', 'file'])->asArray()->all(); }, 30); }