tableName() public static method

public static tableName ( )
    /**
     * 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 #2
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 #3
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;
 }