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); } 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;