2019-05-09 18:54:39 +12:00
|
|
|
<?php
|
|
|
|
|
2021-06-12 02:20:18 +12:00
|
|
|
use Appwrite\Resque\Worker;
|
2020-05-10 04:39:50 +12:00
|
|
|
use Utopia\Audit\Audit;
|
2021-06-07 17:17:29 +12:00
|
|
|
use Utopia\Cache\Adapter\Redis;
|
|
|
|
use Utopia\Cache\Cache;
|
2020-05-10 04:39:50 +12:00
|
|
|
use Utopia\CLI\Console;
|
2021-06-07 17:17:29 +12:00
|
|
|
use Utopia\Database\Adapter\MariaDB;
|
|
|
|
use Utopia\Database\Database;
|
2020-05-10 04:39:50 +12:00
|
|
|
|
2021-06-12 04:09:46 +12:00
|
|
|
require_once __DIR__.'/../workers.php';
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2021-01-15 19:02:48 +13:00
|
|
|
Console::title('Audits V1 Worker');
|
2020-05-10 04:39:50 +12:00
|
|
|
Console::success(APP_NAME.' audits worker v1 has started');
|
2019-12-29 22:47:55 +13:00
|
|
|
|
2021-06-12 02:20:18 +12:00
|
|
|
class AuditsV1 extends Worker
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
public $args = [];
|
|
|
|
|
2021-06-12 02:20:18 +12:00
|
|
|
public function init(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-12 02:20:18 +12:00
|
|
|
public function run(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
global $register;
|
|
|
|
|
2019-09-07 05:08:48 +12:00
|
|
|
$projectId = $this->args['projectId'];
|
|
|
|
$userId = $this->args['userId'];
|
|
|
|
$event = $this->args['event'];
|
|
|
|
$resource = $this->args['resource'];
|
|
|
|
$userAgent = $this->args['userAgent'];
|
|
|
|
$ip = $this->args['ip'];
|
|
|
|
$data = $this->args['data'];
|
2020-07-06 07:19:14 +12:00
|
|
|
$db = $register->get('db', true);
|
2019-12-29 22:47:55 +13:00
|
|
|
|
2021-06-07 17:17:29 +12:00
|
|
|
$cache = new Cache(new Redis($register->get('cache')));
|
|
|
|
$dbForInternal = new Database(new MariaDB($db), $cache);
|
|
|
|
$dbForInternal->setNamespace('project_'.$projectId.'_internal');
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2021-06-07 17:17:29 +12:00
|
|
|
$audit = new Audit($dbForInternal);
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2019-12-29 22:47:55 +13:00
|
|
|
$audit->log($userId, $event, $resource, $userAgent, $ip, '', $data);
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
|
|
|
|
2021-06-12 02:20:18 +12:00
|
|
|
public function shutdown(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
// ... Remove environment for this job
|
|
|
|
}
|
2021-06-12 02:20:18 +12:00
|
|
|
}
|