PHP code example of webdna / auditor

1. Go to this page and download the library: Download webdna/auditor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webdna / auditor example snippets




return [
    '*' => [
        // A nightly import is noise in the log.
        'contexts' => ['cp', 'site', 'console'],
        'redact' => ['password', 'newPassword', 'verificationCode', 'authKey', 'taxNumber'],
        'retentionDays' => 180,
    ],
    'dev' => [
        'enabled' => false,
    ],
];

use webdna\auditor\events\DefineTrackedAttributesEvent;
use webdna\auditor\services\Differ;
use yii\base\Event;

Event::on(Differ::class, Differ::EVENT_DEFINE_TRACKED_ATTRIBUTES, function(DefineTrackedAttributesEvent $event) {
    if ($event->elementType === \craft\elements\Entry::class) {
        unset($event->attributes['postDate']);
    }
});

use webdna\auditor\events\DefineElementSnapshotEvent;

Event::on(Differ::class, Differ::EVENT_DEFINE_ELEMENT_SNAPSHOT, function(DefineElementSnapshotEvent $event) {
    if (!$event->element instanceof \craft\elements\Entry) {
        return;
    }
    $event->values['bookings'] = (int)(new \craft\db\Query())
        ->from('{{%my_bookings}}')
        ->where(['entryId' => $event->element->id])
        ->count();
});

use webdna\auditor\events\RecordEvent;
use webdna\auditor\services\Recorder;

Event::on(Recorder::class, Recorder::EVENT_BEFORE_RECORD, function(RecordEvent $event) {
    if ($event->row->contextDetail === 'my-plugin/sync/run') {
        $event->isValid = false;
    }
});

use webdna\auditor\Auditor;
use webdna\auditor\models\Event as AuditEvent;

Auditor::getInstance()->getRecorder()->record(new AuditEvent([
    'family' => AuditEvent::FAMILY_ACCESS,
    'event' => 'apiKeyIssued',
    'data' => ['key' => 'Mobile app'],
]));
bash
# Remove rows older than retentionDays now, instead of waiting for garbage collection
php craft auditor/prune

# Remove rows older than 30 days, once, whatever retentionDays says
php craft auditor/prune --days=30

# Count what would be removed, removing nothing
php craft auditor/prune --dry-run

# Anonymise a deleted user's rows (see Personal data)
php craft auditor/anonymise-actor --user=123