From dbed0d0da7490477ea915de8aeeaec1555124633 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sun, 21 Jun 2026 17:53:52 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20address=20PR=20review=20=E2=80=94=20remo?= =?UTF-8?q?ve=20dead=20code,=20consistent=20warnings=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove dead checkRequiredExtensions() method (superseded by PreflightCheck) - Add 'warnings' key to ALL return paths in BackupEngine::run() and SteppedBackupEngine::init() to prevent undefined key access on PHP 8.x - Include preflight warnings in success, failure, and early-exit returns --- .../src/Engine/BackupEngine.php | 36 +++---------------- .../src/Engine/SteppedBackupEngine.php | 2 +- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/source/packages/com_mokosuitebackup/src/Engine/BackupEngine.php b/source/packages/com_mokosuitebackup/src/Engine/BackupEngine.php index cd82b3d..77fae79 100644 --- a/source/packages/com_mokosuitebackup/src/Engine/BackupEngine.php +++ b/source/packages/com_mokosuitebackup/src/Engine/BackupEngine.php @@ -58,7 +58,7 @@ class BackupEngine $profile = $db->loadObject(); if (!$profile) { - return ['success' => false, 'message' => 'Profile not found: ' . $profileId]; + return ['success' => false, 'message' => 'Profile not found: ' . $profileId, 'warnings' => []]; } // Log any preflight warnings @@ -78,7 +78,7 @@ class BackupEngine $this->backupDir = BackupDirectory::resolve($resolver->resolve($configuredDir)); if (!BackupDirectory::ensureReady($this->backupDir)) { - return ['success' => false, 'message' => 'Cannot create backup directory: ' . $this->backupDir, 'record_id' => 0]; + return ['success' => false, 'message' => 'Cannot create backup directory: ' . $this->backupDir, 'record_id' => 0, 'warnings' => $preflightResult['warnings']]; } // Create backup record @@ -310,6 +310,7 @@ class BackupEngine 'success' => true, 'message' => 'Backup complete: ' . $archiveName . ' (' . $sizeHuman . ')', 'record_id' => $recordId, + 'warnings' => $preflightResult['warnings'], ]; } catch (\Throwable $e) { $this->log('FATAL: ' . $e->getMessage()); @@ -338,7 +339,7 @@ class BackupEngine // Dispatch event for actionlog and other listeners $this->dispatchAfterRun(false, $recordId, $description, $profileId, $origin); - return ['success' => false, 'message' => 'Backup failed: ' . $e->getMessage(), 'record_id' => $recordId]; + return ['success' => false, 'message' => 'Backup failed: ' . $e->getMessage(), 'record_id' => $recordId, 'warnings' => $preflightResult['warnings'] ?? []]; } } @@ -393,35 +394,6 @@ class BackupEngine }; } - /** - * Verify required PHP extensions are loaded. - * - * @return true|string True if all ok, or error message string - */ - private function checkRequiredExtensions(): true|string - { - $required = [ - 'zip' => 'ext-zip (required for archive creation)', - 'pdo' => 'ext-pdo (required for database operations)', - 'pdo_mysql' => 'ext-pdo_mysql (required for MySQL database dumps)', - 'mbstring' => 'ext-mbstring (required for binary-safe operations)', - ]; - - $missing = []; - - foreach ($required as $ext => $label) { - if (!extension_loaded($ext)) { - $missing[] = $label; - } - } - - if (!empty($missing)) { - return 'Missing PHP extensions: ' . implode(', ', $missing); - } - - return true; - } - /** * Create the appropriate archiver based on the archive format. */ diff --git a/source/packages/com_mokosuitebackup/src/Engine/SteppedBackupEngine.php b/source/packages/com_mokosuitebackup/src/Engine/SteppedBackupEngine.php index 93effb9..6ba97ea 100644 --- a/source/packages/com_mokosuitebackup/src/Engine/SteppedBackupEngine.php +++ b/source/packages/com_mokosuitebackup/src/Engine/SteppedBackupEngine.php @@ -55,7 +55,7 @@ class SteppedBackupEngine $profile = $db->loadObject(); if (!$profile) { - return ['error' => true, 'message' => 'Profile not found: ' . $profileId]; + return ['error' => true, 'message' => 'Profile not found: ' . $profileId, 'warnings' => []]; } // Create session