diff --git a/phpmyfaq/admin/assets/src/configuration/upgrade.js b/phpmyfaq/admin/assets/src/configuration/upgrade.js index bc56189dad..c3743c2cfa 100644 --- a/phpmyfaq/admin/assets/src/configuration/upgrade.js +++ b/phpmyfaq/admin/assets/src/configuration/upgrade.js @@ -198,7 +198,7 @@ export const handleCheckForUpdates = () => { if (installButton) { installButton.addEventListener('click', (event) => { event.preventDefault(); - fetch(window.location.pathname + 'api/install-package', { + fetch(window.location.pathname + 'api/create-temporary-backup', { method: 'POST', headers: { Accept: 'application/json, text/plain, */*', diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php b/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php index 42cc7f525c..994fdcb950 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php @@ -39,6 +39,7 @@ class Upgrade extends Setup public const GITHUB_PATH = 'thorsten/phpMyFAQ/releases/download/development-nightly-%s/'; private const GITHUB_FILENAME = 'phpMyFAQ-nightly-%s.zip'; private const PHPMYFAQ_FILENAME = 'phpMyFAQ-%s.zip'; + private const PMF_UPGRADE_DIR = PMF_CONTENT_DIR . '/upgrades'; private bool $isNightly; public function __construct(protected System $system, private readonly Configuration $configuration) @@ -56,9 +57,9 @@ public function __construct(protected System $system, private readonly Configura */ public function checkFilesystem(): bool { - if (!is_dir(PMF_CONTENT_DIR . '/upgrades')) { - if (!mkdir(PMF_CONTENT_DIR . '/upgrades')) { - throw new Exception('The folder ' . PMF_CONTENT_DIR . '/upgrades is missing.'); + if (!is_dir(self::PMF_UPGRADE_DIR)) { + if (!mkdir(self::PMF_UPGRADE_DIR)) { + throw new Exception('The folder ' . self::PMF_UPGRADE_DIR . ' is missing.'); } } if ( @@ -123,9 +124,9 @@ public function downloadPackage(string $version): string|bool $package = $response->getContent(); - file_put_contents(PMF_CONTENT_DIR . '/upgrades/' . $this->getFilename($version), $package); + file_put_contents(self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR . $this->getFilename($version), $package); - return PMF_CONTENT_DIR . '/upgrades/' . $this->getFilename($version); + return self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR . $this->getFilename($version); } catch ( TransportExceptionInterface | ClientExceptionInterface | @@ -198,7 +199,7 @@ public function extractPackage(string $path, callable $progressCallback): bool }); if ($zipFile) { - $zip->extractTo(PMF_CONTENT_DIR . '/upgrades/'); + $zip->extractTo(self::PMF_UPGRADE_DIR . '/new/'); return $zip->close(); } else { throw new Exception('Cannot open zipped download package.'); @@ -215,7 +216,7 @@ public function extractPackage(string $path, callable $progressCallback): bool */ public function createTemporaryBackup(string $backupName, callable $progressCallback): bool { - $outputZipFile = PMF_CONTENT_DIR . '/upgrades/' . $backupName; + $outputZipFile = self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR . $backupName; if (file_exists($outputZipFile)) { throw new Exception('Backup file already exists.'); @@ -239,11 +240,11 @@ public function createTemporaryBackup(string $backupName, callable $progressCall foreach ($files as $file) { $file = realpath($file); - if (!str_contains($file, PMF_CONTENT_DIR . '/upgrades/')) { + if (!str_contains($file, self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR)) { if (is_dir($file)) { - $zip->addEmptyDir(str_replace($sourceDir . '/', '', $file . '/')); + $zip->addEmptyDir(str_replace($sourceDir . DIRECTORY_SEPARATOR, '', $file . DIRECTORY_SEPARATOR)); } elseif (is_file($file)) { - $zip->addFile($file, str_replace($sourceDir . '/', '', $file)); + $zip->addFile($file, str_replace($sourceDir . DIRECTORY_SEPARATOR, '', $file)); } } } @@ -261,8 +262,8 @@ public function createTemporaryBackup(string $backupName, callable $progressCall */ public function deleteTemporaryBackup(string $backupName): bool { - if (is_file(PMF_CONTENT_DIR . '/upgrades/' . $backupName)) { - return unlink(PMF_CONTENT_DIR . '/upgrades/' . $backupName); + if (is_file(self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR . $backupName)) { + return unlink(self::PMF_UPGRADE_DIR . DIRECTORY_SEPARATOR . $backupName); } else { return false; } @@ -285,7 +286,7 @@ public function restoreTemporaryBackup() */ public function installPackage(callable $progressCallback): bool { - $sourceDir = PMF_CONTENT_DIR . '/upgrades/'; + $sourceDir = self::PMF_UPGRADE_DIR . '/new/phpmyfaq/'; $destinationDir = PMF_ROOT_DIR; $sourceDirIterator = new RecursiveIteratorIterator(