diff --git a/Stream/CHANGEDB.php b/Stream/CHANGEDB.php index c60457e..77651d1 100644 --- a/Stream/CHANGEDB.php +++ b/Stream/CHANGEDB.php @@ -92,3 +92,8 @@ ++$count; $sql[$count][0] = '1.3.00'; $sql[$count][1] = ""; + +//v1.3.01 +++$count; +$sql[$count][0] = '1.3.01'; +$sql[$count][1] = ""; diff --git a/Stream/CHANGELOG.txt b/Stream/CHANGELOG.txt index 849e682..3b769a6 100644 --- a/Stream/CHANGELOG.txt +++ b/Stream/CHANGELOG.txt @@ -1,6 +1,10 @@ CHANGELOG ========= +v1.3.01 +------- +Added file cleanup feature after a record is deleted + v1.3.00 ------- Added comprehensive file upload tracking system to monitor and manage all file uploads across the system diff --git a/Stream/manifest.php b/Stream/manifest.php index 4c3232a..be10816 100644 --- a/Stream/manifest.php +++ b/Stream/manifest.php @@ -27,7 +27,7 @@ $entryURL = 'stream.php'; $type = 'Additional'; $category = 'Other'; -$version = '1.3.00'; +$version = '1.3.01'; $author = "Gibbon Foundation"; $url = "https://gibbonedu.org"; diff --git a/Stream/posts_manage_deleteProcess.php b/Stream/posts_manage_deleteProcess.php index 179e646..e934992 100644 --- a/Stream/posts_manage_deleteProcess.php +++ b/Stream/posts_manage_deleteProcess.php @@ -19,7 +19,9 @@ along with this program. If not, see . */ +use Gibbon\Contracts\Filesystem\FileHandler; use Gibbon\Module\Stream\Domain\PostGateway; +use Gibbon\Module\Stream\Domain\PostAttachmentGateway; require_once '../../gibbon.php'; @@ -38,6 +40,8 @@ } else { // Proceed! $postGateway = $container->get(PostGateway::class); + $postAttachmentGateway = $container->get(PostAttachmentGateway::class); + $absolutePath = $session->get('absolutePath'); $values = $postGateway->getByID($streamPostID); if (empty($values)) { @@ -46,6 +50,17 @@ exit; } + $attachments = $postAttachmentGateway->selectBy(['streamPostID' => $streamPostID], ['streamPostAttachmentID', 'thumbnail'])->fetchAll(); + + foreach ($attachments as $attachment) { + $fileDeleted = $container->get(FileHandler::class)->deleteFile('streamPostAttachment', $attachment['streamPostAttachmentID'], 'attachment'); + if (!empty($attachment['thumbnail'])) { + @unlink($absolutePath.'/'.$attachment['thumbnail']); + } + } + + $deleted = $postAttachmentGateway->deleteWhere(['streamPostID' => $streamPostID]); + $deleted = $postGateway->delete($streamPostID); $URL .= !$deleted diff --git a/Stream/posts_manage_edit_deleteProcess.php b/Stream/posts_manage_edit_deleteProcess.php index a4ef666..9df0c2c 100644 --- a/Stream/posts_manage_edit_deleteProcess.php +++ b/Stream/posts_manage_edit_deleteProcess.php @@ -19,8 +19,7 @@ along with this program. If not, see . */ -use Gibbon\FileUploader; -use Gibbon\Domain\System\SettingGateway; +use Gibbon\Contracts\Filesystem\FileHandler; use Gibbon\Module\Stream\Domain\PostAttachmentGateway; $_POST['address'] = '/modules/Stream/posts_manage_edit.php'; @@ -39,7 +38,6 @@ // Proceed! $postAttachmentGateway = $container->get(PostAttachmentGateway::class); $absolutePath = $session->get('absolutePath'); - $partialFail = false; // Validate the required values are present if (empty($streamPostID) || empty($streamPostAttachmentID)) { @@ -56,19 +54,18 @@ exit; } - // Delete the image files - if (!empty($attachment['attachment'])) { - $partialFail &= !unlink($absolutePath.'/'.$attachment['attachment']); - } + // Delete the tracked attachment file via FileHandler + $deleted = $container->get(FileHandler::class)->deleteFile('streamPostAttachment', $streamPostAttachmentID, 'attachment'); + // Delete the thumbnail file directly (not tracked via FileHandler) if (!empty($attachment['thumbnail'])) { - $partialFail &= !unlink($absolutePath.'/'.$attachment['thumbnail']); + @unlink($absolutePath.'/'.$attachment['thumbnail']); } // Delete the record $deleted = $postAttachmentGateway->delete($streamPostAttachmentID); - $URL .= $partialFail || !$deleted + $URL .= !$deleted ? "&return=warning1" : "&return=success0"; diff --git a/Stream/version.php b/Stream/version.php index 3dda15a..0107e6a 100644 --- a/Stream/version.php +++ b/Stream/version.php @@ -22,5 +22,5 @@ /** * Sets version information. */ -$moduleVersion = '1.3.00'; +$moduleVersion = '1.3.01'; $coreVersion = '31.0.00';