From db8304793177e604e24da2a87c7cd6be203c48cb Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 2 Aug 2024 09:54:23 +0200 Subject: [PATCH 1/2] refs #47512 declaration warning --- classes/API/HttpJsonResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/API/HttpJsonResponse.php b/classes/API/HttpJsonResponse.php index 75ae9a64..0b61d79e 100644 --- a/classes/API/HttpJsonResponse.php +++ b/classes/API/HttpJsonResponse.php @@ -45,7 +45,7 @@ public function getHeaders() return $this->response->getHeaders(); } - public function setHeaders($headers) + public function setHeaders(array $headers) { return $this->response->setHeaders($headers); } From 216a491247fb566045eeb75328ae6caa57a4e8c5 Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 2 Aug 2024 11:15:03 +0200 Subject: [PATCH 2/2] warning during upgrade --- services/Kit.php | 87 +++++++++++++++++++++++++++++++++++++++ upgrade/Upgrade-6.4.3.php | 13 ++---- 2 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 services/Kit.php diff --git a/services/Kit.php b/services/Kit.php new file mode 100644 index 00000000..9b94187c --- /dev/null +++ b/services/Kit.php @@ -0,0 +1,87 @@ + + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @copyright PayPal + * + */ + +namespace PaypalAddons\services; + +use Exception; +use Throwable; + +class Kit +{ + public function rrmdir($dir) + { + if (false === is_dir($dir)) { + return false; + } + + $objects = scandir($dir); + + foreach ($objects as $object) { + if ($object === '.' || $object === '..') { + continue; + } + if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . '/' . $object)) { + $this->rrmdir($dir . DIRECTORY_SEPARATOR . $object); + continue; + } + + $this->unlink($dir . DIRECTORY_SEPARATOR . $object); + } + + return $this->rmdir($dir); + } + + public function unlink($file) + { + if (false === is_file($file)) { + return false; + } + + try { + return unlink($file); + } catch (Exception $e) { + } catch (Throwable $e) { + } + + return false; + } + + public function rmdir($dir) + { + if (false === is_dir($dir)) { + return false; + } + + try { + return rmdir($dir); + } catch (Exception $e) { + } catch (Throwable $e) { + } + + return false; + } +} diff --git a/upgrade/Upgrade-6.4.3.php b/upgrade/Upgrade-6.4.3.php index dbc328fe..478fe13f 100644 --- a/upgrade/Upgrade-6.4.3.php +++ b/upgrade/Upgrade-6.4.3.php @@ -36,6 +36,7 @@ */ function upgrade_module_6_4_3($module) { + $kit = new \PaypalAddons\services\Kit(); $baseDir = _PS_ROOT_DIR_ . '/modules/paypal/'; $dirs = [ '_dev', @@ -74,18 +75,10 @@ function upgrade_module_6_4_3($module) ]; foreach ($dirs as $dir) { - if (file_exists($baseDir . $dir)) { - rmdir($baseDir . $dir); - } + $kit->rrmdir($baseDir . $dir); } foreach ($files as $file) { - if (file_exists($baseDir . $file)) { - try { - unlink($baseDir . $file); - } catch (Exception $e) { - } catch (Throwable $e) { - } - } + $kit->unlink($baseDir . $file); } return true;