From c5e059c118e414d14c877e729dae308612594df9 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 20 Sep 2023 18:58:11 -0700 Subject: [PATCH] Fix delete function deployment Prior to this, deleting a VCS deployment would fail because the deployment path for VCS deployments are empty. Because an error gets thrown, the delete function would stop and not delete the build files. This change updates the worker to only delete the storage files if the path is set. --- app/workers/deletes.php | 45 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index f3968c07f2..51573a0267 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -679,12 +679,25 @@ class DeletesV1 extends Worker /** * Delete deployment files */ - Console::info("Deleting deployment files for deployment " . $deploymentId); - $storageFunctions = $this->getFunctionsDevice($projectId); - if ($storageFunctions->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted deployment files: ' . $document->getAttribute('path', '')); + $deploymentPath = $document->getAttribute('path', ''); + if (empty($deploymentPath)) { + Console::info("No deployment files for deployment " . $deploymentId); } else { - Console::error('Failed to delete deployment files: ' . $document->getAttribute('path', '')); + Console::info("Deleting deployment files for deployment " . $deploymentId); + $storageFunctions = $this->getFunctionsDevice($projectId); + try { + if ($storageFunctions->delete($deploymentPath, true)) { + Console::success('Deleted deployment files: ' . $deploymentPath); + } else { + Console::error('Failed to delete deployment files: ' . $deploymentPath); + } + } catch (\Throwable $th) { + Console::error('Failed to delete deployment files: ' . $deploymentPath); + Console::error('[Error] Type: ' . get_class($th)); + Console::error('[Error] Message: ' . $th->getMessage()); + Console::error('[Error] File: ' . $th->getFile()); + Console::error('[Error] Line: ' . $th->getLine()); + } } /** @@ -695,10 +708,24 @@ class DeletesV1 extends Worker $this->deleteByGroup('builds', [ Query::equal('deploymentInternalId', [$deploymentInternalId]) ], $dbForProject, function (Document $document) use ($storageBuilds) { - if ($storageBuilds->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted build files: ' . $document->getAttribute('path', '')); - } else { - Console::error('Failed to delete build files: ' . $document->getAttribute('path', '')); + $buildPath = $document->getAttribute('path', ''); + if (empty($buildPath)) { + Console::info("No build files for build " . $document->getId()); + return; + } + + try { + if ($storageBuilds->delete($buildPath, true)) { + Console::success('Deleted build files: ' . $buildPath); + } else { + Console::error('Failed to delete build files: ' . $buildPath); + } + } catch (\Throwable $th) { + Console::error('Failed to delete deployment files: ' . $buildPath); + Console::error('[Error] Type: ' . get_class($th)); + Console::error('[Error] Message: ' . $th->getMessage()); + Console::error('[Error] File: ' . $th->getFile()); + Console::error('[Error] Line: ' . $th->getLine()); } });