2019-05-09 06:54:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-04-04 06:30:07 +00:00
|
|
|
use Appwrite\Event\Event;
|
2021-06-11 14:20:18 +00:00
|
|
|
use Appwrite\Resque\Worker;
|
2020-05-09 16:39:50 +00:00
|
|
|
use Utopia\Audit\Audit;
|
|
|
|
|
use Utopia\CLI\Console;
|
2022-04-04 06:30:07 +00:00
|
|
|
use Utopia\Database\Document;
|
2020-05-09 16:39:50 +00:00
|
|
|
|
2022-05-09 12:36:29 +00:00
|
|
|
require_once __DIR__ . '/../init.php';
|
2019-05-09 06:54:39 +00:00
|
|
|
|
2021-01-15 06:02:48 +00:00
|
|
|
Console::title('Audits V1 Worker');
|
2021-09-01 09:13:23 +00:00
|
|
|
Console::success(APP_NAME . ' audits worker v1 has started');
|
2019-12-29 09:47:55 +00:00
|
|
|
|
2021-06-11 14:20:18 +00:00
|
|
|
class AuditsV1 extends Worker
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
2022-05-09 12:36:29 +00:00
|
|
|
public function getName(): string
|
|
|
|
|
{
|
2021-11-23 14:24:25 +00:00
|
|
|
return "audits";
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 14:20:18 +00:00
|
|
|
public function init(): void
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 14:20:18 +00:00
|
|
|
public function run(): void
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
2022-09-04 08:45:53 +00:00
|
|
|
$event = $this->args['event'];
|
2022-04-13 12:39:31 +00:00
|
|
|
$payload = $this->args['payload'];
|
|
|
|
|
$mode = $this->args['mode'];
|
|
|
|
|
$resource = $this->args['resource'];
|
|
|
|
|
$userAgent = $this->args['userAgent'];
|
|
|
|
|
$ip = $this->args['ip'];
|
|
|
|
|
|
2022-04-04 06:30:07 +00:00
|
|
|
$user = new Document($this->args['user']);
|
|
|
|
|
$project = new Document($this->args['project']);
|
|
|
|
|
|
|
|
|
|
$userName = $user->getAttribute('name', '');
|
|
|
|
|
$userEmail = $user->getAttribute('email', '');
|
|
|
|
|
|
|
|
|
|
$dbForProject = $this->getProjectDB($project->getId());
|
2021-12-27 12:45:23 +00:00
|
|
|
$audit = new Audit($dbForProject);
|
2022-05-09 12:36:29 +00:00
|
|
|
$audit->log(
|
|
|
|
|
userId: $user->getId(),
|
|
|
|
|
// Pass first, most verbose event pattern
|
2022-09-04 08:45:53 +00:00
|
|
|
event: $event,
|
2022-05-09 12:36:29 +00:00
|
|
|
resource: $resource,
|
|
|
|
|
userAgent: $userAgent,
|
|
|
|
|
ip: $ip,
|
|
|
|
|
location: '',
|
|
|
|
|
data: [
|
|
|
|
|
'userName' => $userName,
|
|
|
|
|
'userEmail' => $userEmail,
|
|
|
|
|
'mode' => $mode,
|
|
|
|
|
'data' => $payload,
|
|
|
|
|
]
|
|
|
|
|
);
|
2019-05-09 06:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-11 14:20:18 +00:00
|
|
|
public function shutdown(): void
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
}
|
2021-09-01 09:13:23 +00:00
|
|
|
}
|