Skip to content

Commit

Permalink
feat: added route to install package (WIP) (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 14, 2023
1 parent 953beea commit 819b36d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ phpmyfaq/content/core/data/*
!phpmyfaq/content/core/data/.gitkeep
phpmyfaq/content/core/logs/*
!phpmyfaq/content/core/logs/.gitkeep
phpmyfaq/content/upgrades/*
!phpmyfaq/content/upgrades/.gitkeep
phpmyfaq/content/user/images/*
!phpmyfaq/content/user/images/.gitkeep
phpmyfaq/content/user/attachments/*
Expand Down
1 change: 1 addition & 0 deletions phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ RewriteRule admin/api/versions admin/api/index.php
RewriteRule admin/api/update-check admin/api/index.php
RewriteRule admin/api/download-package admin/api/index.php
RewriteRule admin/api/extract-package admin/api/index.php
RewriteRule admin/api/install-package admin/api/index.php

# REST API v2.0
# * http://[...]/api/v2.0/<ACTION>
Expand Down
5 changes: 3 additions & 2 deletions phpmyfaq/admin/assets/src/configuration/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export const handleCheckForUpdates = () => {
}
}
})
.catch((error) => {
console.error(error);
.catch(async (error) => {
const errorMessage = await error.cause.response.json();
console.error(errorMessage);
});
});
}
Expand Down
13 changes: 12 additions & 1 deletion phpmyfaq/src/admin-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$routes->add(
'admin.api.versions',
new Route('/versions', ['_controller' => [UpdateController::class, 'versions']])
new Route('/versions', ['_controller' => [UpdateController::class, 'versions', '_methods' => 'GET']])
);

$routes->add(
Expand Down Expand Up @@ -58,4 +58,15 @@
)
);

$routes->add(
'admin.api.install-package',
new Route(
'/install-package',
[
'_controller' => [UpdateController::class, 'installPackage'],
'_methods' => 'POST'
]
)
);

return $routes;
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function healthCheck(): JsonResponse
$dateLastChecked = $dateTime->format(DateTimeInterface::ATOM);
$upgrade = new Upgrade(new System(), $configuration);


try {
$upgrade->checkFilesystem();
$response->setStatusCode(Response::HTTP_OK);
Expand Down Expand Up @@ -178,7 +179,7 @@ public function downloadPackage(Request $request): JsonResponse
return $response;
}


#[Route('admin/api/extract-package')]
public function extractPackage(): JsonResponse
{
$response = new JsonResponse();
Expand All @@ -194,4 +195,23 @@ public function extractPackage(): JsonResponse

return $response;
}

#[Route('admin/api/install-package')]
public function installPackage(): JsonResponse
{
$response = new JsonResponse();
$configuration = Configuration::getConfigurationInstance();

$backupHash = md5(uniqid());

$upgrade = new Upgrade(new System(), $configuration);

$result = $upgrade->createTemporaryBackup($backupHash . '.zip');

//$result = $upgrade->installPackage();

$response->setData(['result' => $result]);

return $response;
}
}
5 changes: 3 additions & 2 deletions phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public function extractPackage(string $path): bool
public function createTemporaryBackup(string $backupName): bool
{
$outputZipFile = PMF_CONTENT_DIR . '/upgrades/' . $backupName;
if (!file_exists($outputZipFile)) {

if (file_exists($outputZipFile)) {
return false;
}

Expand All @@ -221,7 +222,7 @@ public function createTemporaryBackup(string $backupName): bool
return false;
}

$sourceDir = rtrim(PMF_ROOT_DIR, '/\\');
$sourceDir = PMF_ROOT_DIR;
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sourceDir),
RecursiveIteratorIterator::SELF_FIRST
Expand Down

0 comments on commit 819b36d

Please sign in to comment.