Updated delete method to support recrusive deletes

This commit is contained in:
Eldad Fux
2020-05-26 20:11:20 +03:00
parent 41ecda5ea3
commit 419fabd80a
6 changed files with 103 additions and 7 deletions
+4 -2
View File
@@ -1,6 +1,6 @@
<?php
global $utopia, $request, $response, $register, $user, $consoleDB, $projectDB;
global $utopia, $request, $response, $register, $user, $consoleDB, $projectDB, $deletes;
use Utopia\Exception;
use Utopia\Response;
@@ -402,7 +402,7 @@ $utopia->delete('/v1/projects/:projectId')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->param('password', '', function () { return new UID(); }, 'Your user password for confirmation.')
->action(
function ($projectId, $password) use ($response, $consoleDB, $user) {
function ($projectId, $password) use ($response, $consoleDB, $user, $deletes) {
if (!Auth::passwordVerify($password, $user->getAttribute('password'))) { // Double check user password
throw new Exception('Invalid credentials', 401);
}
@@ -413,6 +413,8 @@ $utopia->delete('/v1/projects/:projectId')
throw new Exception('Project not found', 404);
}
$deletes->setParam('document', $project->getArrayCopy());
foreach(['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
$list = $project->getAttribute('webhooks', []);