public function actionLog()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $data = \yii\helpers\Json::decode(\Yii::$app->request->post('data'));
     $entry = null;
     if (isset($data['auditEntry'])) {
         $entry = models\AuditEntry::findOne($data['auditEntry']);
     } else {
         return ['result' => 'error', 'message' => 'No audit entry to attach to'];
     }
     // Convert data into the loggable object
     $javascript = new models\AuditJavascript();
     $map = ['auditEntry' => 'audit_id', 'message' => 'message', 'type' => 'type', 'file' => 'origin', 'line' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'col' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'data' => function ($value) use($javascript) {
         if (count($value)) {
             $javascript->data = $value;
         }
     }];
     foreach ($map as $key => $target) {
         if (isset($data[$key])) {
             if (is_callable($target)) {
                 $target($data[$key]);
             } else {
                 $javascript->{$target} = $data[$key];
             }
         }
     }
     if ($javascript->save()) {
         return ['result' => 'ok'];
     }
     return ['result' => 'error', 'errors' => $javascript->getErrors()];
 }
Пример #2
0
 /**
  * @return array
  */
 public function actionIndex()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $data = Json::decode(Yii::$app->request->post('data'));
     if (!isset($data['auditEntry'])) {
         $entry = Audit::getInstance()->getEntry(true);
         $data['auditEntry'] = $entry->id;
     }
     // Convert data into the loggable object
     $javascript = new models\AuditJavascript();
     $map = ['auditEntry' => 'entry_id', 'message' => 'message', 'type' => 'type', 'file' => 'origin', 'line' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'col' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'data' => function ($value) use($javascript) {
         if (count($value)) {
             $javascript->data = $value;
         }
     }];
     foreach ($map as $key => $target) {
         if (isset($data[$key])) {
             if (is_callable($target)) {
                 $target($data[$key]);
             } else {
                 $javascript->{$target} = $data[$key];
             }
         }
     }
     if ($javascript->save()) {
         return ['result' => 'ok', 'entry' => $data['auditEntry']];
     }
     return ['result' => 'error', 'errors' => $javascript->getErrors()];
 }