/**
  * @return array
  */
 public static function methodFilter()
 {
     $methods = AuditEntry::getDb()->cache(function () {
         return AuditEntry::find()->distinct(true)->select('request_method')->where(['is not', 'request_method', null])->groupBy('request_method')->orderBy('request_method ASC')->column();
     }, 240);
     return array_combine($methods, $methods);
 }
 public static function routeFilter()
 {
     $routes = AuditEntry::getDb()->cache(function ($db) {
         return AuditEntry::find()->distinct(true)->select('route')->where(['is not', 'route', null])->groupBy('route')->orderBy('route ASC')->column();
     }, 30);
     return array_combine($routes, $routes);
 }
    /**
     * Clean up the audit data according to the settings.
     */
    public function actionCleanup()
    {
        /** @var Audit $audit */
        $audit = Yii::$app->getModule('audit');
        if ($audit->maxAge === null) {
            return;
        }
        $entry = AuditEntry::tableName();
        $errors = AuditError::tableName();
        $data = AuditData::tableName();
        $javascript = AuditJavascript::tableName();
        $threshold = time() - $audit->maxAge * 86400;
        AuditEntry::getDb()->createCommand(<<<SQL
DELETE FROM {$entry}, {$errors}, {$data}, {$javascript} USING {$entry}
  INNER JOIN {$errors} ON {$errors}.entry_id = {$entry}.id
  INNER JOIN {$data} ON {$data}.entry_id = {$entry}.id
  INNER JOIN {$javascript} ON {$javascript}.entry_id = {$entry}.id
  WHERE {$entry}.created < FROM_UNIXTIME({$threshold})
SQL
)->execute();
    }
Beispiel #4
0
    /**
     * Clean up the audit data according to the settings.
     * Can be handy if you are offloading the data somewhere and want to keep only the most recent entries readily available
     */
    public function truncate()
    {
        if ($this->maxAge === null) {
            return;
        }
        $entry = models\AuditEntry::tableName();
        $errors = models\AuditError::tableName();
        $data = models\AuditData::tableName();
        $javascript = models\AuditJavascript::tableName();
        $threshold = time() - $this->maxAge * 86400;
        models\AuditEntry::getDb()->createCommand(<<<SQL
DELETE FROM {$entry}, {$errors}, {$data}, {$javascript} USING {$entry}
  INNER JOIN {$errors} ON {$errors}.audit_id = {$entry}.id
  INNER JOIN {$data} ON {$data}.audit_id = {$entry}.id
  INNER JOIN {$javascript} ON {$javascript}.audit_id = {$entry}.id
  WHERE {$entry}.created < FROM_UNIXTIME({$threshold})
SQL
)->execute();
    }
Beispiel #5
0
 /**
  * @param bool $create
  * @param bool $new
  * @return AuditEntry|static
  */
 public function getEntry($create = false, $new = false)
 {
     $entry = new AuditEntry();
     $tableSchema = $entry->getDb()->schema->getTableSchema($entry->tableName());
     if ($tableSchema) {
         if (!$this->_entry && $create || $new) {
             $this->_entry = AuditEntry::create(true);
         }
     }
     return $this->_entry;
 }
 /**
  * @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);
 }