patch: refactor delete worker invocation
This commit is contained in:
parent
4a47c59380
commit
1ecbf8bc5d
|
@ -253,7 +253,7 @@ App::delete('/v1/database/collections/:collectionId')
|
|||
|
||||
$deletes
|
||||
->setParam('document', $collection)
|
||||
->setParam('collection', Database::SYSTEM_COLLECTION_COLLECTIONS)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$events
|
||||
|
|
|
@ -366,7 +366,7 @@ App::delete('/v1/functions/:functionId')
|
|||
|
||||
$deletes
|
||||
->setParam('document', $function->getArrayCopy())
|
||||
->setParam('collection', Database::SYSTEM_COLLECTION_FUNCTIONS)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$response->noContent();
|
||||
|
|
|
@ -431,7 +431,7 @@ App::delete('/v1/projects/:projectId')
|
|||
|
||||
$deletes
|
||||
->setParam('document', $project->getArrayCopy())
|
||||
->setParam('collection', Database::SYSTEM_COLLECTION_PROJECTS)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
|
||||
|
|
|
@ -517,7 +517,7 @@ App::delete('/v1/users/:userId')
|
|||
|
||||
$deletes
|
||||
->setParam('document', $user)
|
||||
->setParam('collection', Database::SYSTEM_COLLECTION_USERS)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$events
|
||||
|
|
|
@ -9,6 +9,7 @@ use Appwrite\Database\Document;
|
|||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Swoole\FastCGI\Record\Data;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
|
@ -29,29 +30,32 @@ function getConsoleDB() {
|
|||
function notifyDeleteExecutionLogs(array $projectIds)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'type' => DeletesV1::TYPE_DOCUMENT,
|
||||
'document' => new Document([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'projectIds' => $projectIds
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAbuseLogs(array $projectIds)
|
||||
function notifyDeleteAbuseLogs(array $projectIds, int $timestamp)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'type' => DeletesV1::TYPE_ABUSE,
|
||||
'document' => new Document([
|
||||
'projectIds' => $projectIds
|
||||
'projectIds' => $projectIds,
|
||||
'timestamp' => $timestamp,
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAuditLogs(array $projectIds)
|
||||
function notifyDeleteAuditLogs(array $projectIds, int $timestamp)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'type' => DeletesV1::TYPE_AUDIT,
|
||||
'document' => new Document([
|
||||
'projectIds' => $projectIds
|
||||
'projectIds' => $projectIds,
|
||||
'timestamp' => $timestamp
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,12 @@ use Utopia\Audit\Adapters\MySQL as AuditAdapter;
|
|||
|
||||
class DeletesV1
|
||||
{
|
||||
|
||||
// Deletion Types
|
||||
const TYPE_DOCUMENT = 'document';
|
||||
const TYPE_AUDIT = 'audit';
|
||||
const TYPE_ABUSE = 'abuse';
|
||||
|
||||
public $args = [];
|
||||
|
||||
protected $consoleDB = null;
|
||||
|
@ -32,28 +38,39 @@ class DeletesV1
|
|||
$document = $this->args['document'];
|
||||
$document = new Document($document);
|
||||
$projectId = $this->args['projectId'];
|
||||
$collection = $this->args['collection'];
|
||||
$type = $this->args['type'];
|
||||
|
||||
switch (strval($collection)) {
|
||||
case Database::SYSTEM_COLLECTION_PROJECTS:
|
||||
$this->deleteProject($document);
|
||||
switch (strval($type)) {
|
||||
case DeletesV1::TYPE_DOCUMENT:
|
||||
switch (strval($document->getCollection())) {
|
||||
case Database::SYSTEM_COLLECTION_PROJECTS:
|
||||
$this->deleteProject($document);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_FUNCTIONS:
|
||||
$this->deleteFunction($document, $projectId);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_EXECUTIONS:
|
||||
$this->deleteExecutionLogs($document);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_USERS:
|
||||
$this->deleteUser($document, $projectId);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_COLLECTIONS:
|
||||
$this->deleteDocuments($document, $projectId);
|
||||
break;
|
||||
default:
|
||||
Console::error('No lazy delete operation available for document of type: '.$document->getCollection());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_FUNCTIONS:
|
||||
$this->deleteFunction($document, $projectId);
|
||||
case DeletesV1::TYPE_AUDIT:
|
||||
$this->deleteAuditLogs($document);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_EXECUTIONS:
|
||||
$this->deleteExecutionLogs($document);
|
||||
|
||||
case DeletesV1::TYPE_ABUSE:
|
||||
$this->deleteAbuseLogs($document);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_USERS:
|
||||
$this->deleteUser($document, $projectId);
|
||||
break;
|
||||
case Database::SYSTEM_COLLECTION_COLLECTIONS:
|
||||
$this->deleteDocuments($document, $projectId);
|
||||
break;
|
||||
default:
|
||||
Console::error('No lazy delete operation available for document of type: '.$document->getCollection());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
|
@ -136,6 +153,7 @@ class DeletesV1
|
|||
{
|
||||
global $register;
|
||||
$projectIds = $document->getAttribute('projectIds', []);
|
||||
$timestamp = $document->getAttribute('time', 0);
|
||||
|
||||
foreach ($projectIds as $projectId) {
|
||||
$adapter = new AuditAdapter($register->get('db'));
|
||||
|
|
Loading…
Reference in a new issue