Skip to content

Commit

Permalink
fix: corrected CS errors (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 12, 2023
1 parent c889393 commit 7aa1b1e
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* The Upgrade class used for upgrading/installing phpMyFAQ from a ZIP file.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
Expand All @@ -17,6 +16,7 @@

namespace phpMyFAQ\Setup;

use JsonException;
use Monolog\Level;
use phpMyFAQ\Configuration;
use phpMyFAQ\Setup;
Expand All @@ -26,6 +26,7 @@
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use ZipArchive;

class Upgrade extends Setup
{
Expand All @@ -40,22 +41,25 @@ public function __construct(protected System $system, private readonly Configura

/**
* Method to check if the filesystem is ready for the upgrade
*
* @return bool
*/
public function checkFilesystem()
public function checkFilesystem(): bool
{
if (!is_dir(PMF_CONTENT_DIR . '\upgrades')) {
if (!mkdir(PMF_CONTENT_DIR . '\upgrades')) {
return false;
}
}
if (
is_dir(PMF_CONTENT_DIR . '\user\attachments') && is_dir(PMF_CONTENT_DIR . '\user\images') &&
is_dir(PMF_CONTENT_DIR . '\core\data') && is_dir(PMF_ROOT_DIR . '\assets\themes')
is_dir(PMF_CONTENT_DIR . '\user\attachments') && is_dir(PMF_CONTENT_DIR . '\user\images') && is_dir(
PMF_CONTENT_DIR . '\core\data'
) && is_dir(PMF_ROOT_DIR . '\assets\themes')
) {
if (
is_file(PMF_CONTENT_DIR . '\core\config\constants.php') &&
is_file(PMF_CONTENT_DIR . '\core\config\database.php')
is_file(PMF_CONTENT_DIR . '\core\config\constants.php') && is_file(
PMF_CONTENT_DIR . '\core\config\database.php'
)
) {
if ($this->configuration->isElasticsearchActive()) {
if (!is_file(PMF_CONTENT_DIR . '\core\config\elasticsearch.php')) {
Expand All @@ -72,6 +76,7 @@ public function checkFilesystem()
return false;
}
}

return true;
} else {
return false;
Expand All @@ -84,10 +89,9 @@ public function checkFilesystem()
/**
* Method to download a phpMyFAQ package, returns false if it doesn't work
*
* @todo handle possible proxy servers
*
* @param string $version
* @return string|bool
* @todo handle possible proxy servers
*/
public function downloadPackage(string $version): string|bool
{
Expand Down Expand Up @@ -115,23 +119,25 @@ public function downloadPackage(string $version): string|bool
ServerExceptionInterface $e
) {
$this->configuration->getLogger()->log(Level::Error, $e->getMessage());

return false;
}
}

/**
* Method to verify the downloaded phpMyFAQ package
* @var string $path | Path to zip file
* @var string $version | Version to verify
*
* @return bool
* @throws Exception|TransportExceptionInterface|ClientExceptionInterface|RedirectExceptionInterface|ServerExceptionInterface|JsonException
* @throws TransportExceptionInterface|ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|JsonException
* @var string $path | Path to zip file
* @var string $version | Version to verify
*/
public function verifyPackage(string $path, string $version): bool
{
$client = HttpClient::create();
$response = $client->request(
'GET',
DOWNLOAD_URL_PRODUCTION . 'info/' . $version
self::DOWNLOAD_URL_PRODUCTION . 'info/' . $version
);

try {
Expand All @@ -142,39 +148,45 @@ public function verifyPackage(string $path, string $version): bool
return false;
}
} catch (
TransportExceptionInterface |
ClientExceptionInterface |
RedirectionExceptionInterface |
ServerExceptionInterface $e
TransportExceptionInterface |
ClientExceptionInterface |
RedirectionExceptionInterface |
ServerExceptionInterface $e
) {
$this->configuration->getLogger()->log(Level::Error, $e->getMessage());

return false;
}
}

/**
* Method to unpack the downloaded phpMyFAQ package
* @var string $path Path of the package
*
* @return bool
* @var string $path Path of the package
*/
public function unpackPackage(string $path): bool
{
$zip = new \ZipArchive();
$zip = new ZipArchive();
if (!$zip->open($path)) {
$this->configuration->getLogger()->log(Level::Error, $zip->getStatusString());

return false;
} else {
if (!$zip->extractTo(PMF_CONTENT_DIR . '/upgrades/')) {
$this->configuration->getLogger()->log(Level::Error, $zip->getStatusString());

return false;
}
$zip->close();

return true;
}
}

/**
* Method to create a temporary backup of the current files
*
* @return void
*/
public function createTemporaryBackup()
Expand All @@ -183,6 +195,7 @@ public function createTemporaryBackup()

/**
* Method to restore from the temporary backup
*
* @return void
*/
public function restoreTemporaryBackup()
Expand All @@ -191,6 +204,7 @@ public function restoreTemporaryBackup()

/**
* Method to install the package
*
* @return void
*/
public function installPackage()
Expand Down

0 comments on commit 7aa1b1e

Please sign in to comment.