Skip to content

Commit

Permalink
feat: renamed upgrade path in class (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 15, 2023
1 parent eb4f524 commit b97857a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion phpmyfaq/admin/assets/src/configuration/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, */*',
Expand Down
27 changes: 14 additions & 13 deletions phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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.');
Expand All @@ -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.');
Expand All @@ -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));
}
}
}
Expand All @@ -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;
}
Expand All @@ -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(
Expand Down

0 comments on commit b97857a

Please sign in to comment.