|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * 2007-2020 PrestaShop. |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Academic Free License 3.0 (AFL-3.0) |
| 8 | + * that is bundled with this package in the file LICENSE.txt. |
| 9 | + * It is also available through the world-wide-web at this URL: |
| 10 | + * https://opensource.org/licenses/AFL-3.0 |
| 11 | + * If you did not receive a copy of the license and are unable to |
| 12 | + * obtain it through the world-wide-web, please send an email |
| 13 | + * to [email protected] so we can send you a copy immediately. |
| 14 | + * |
| 15 | + * DISCLAIMER |
| 16 | + * |
| 17 | + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer |
| 18 | + * versions in the future. If you wish to customize PrestaShop for your |
| 19 | + * needs please refer to http://www.prestashop.com for more information. |
| 20 | + * |
| 21 | + * @author PrestaShop SA <[email protected]> |
| 22 | + * @copyright 2007-2020 PrestaShop SA |
| 23 | + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) |
| 24 | + * International Registered Trademark & Property of PrestaShop SA |
| 25 | + */ |
| 26 | +if (!defined('_PS_VERSION_')) { |
| 27 | + exit; |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Removes files or directories. |
| 32 | + * |
| 33 | + * @param array $files An array of files to remove |
| 34 | + * |
| 35 | + * @return true|string True if everything goes fine, error details otherwise |
| 36 | + */ |
| 37 | +function removeFromFsDuringUpgrade(array $files) |
| 38 | +{ |
| 39 | + $files = array_reverse($files); |
| 40 | + foreach ($files as $file) { |
| 41 | + if (is_dir($file)) { |
| 42 | + $iterator = new FilesystemIterator($file, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); |
| 43 | + removeFromFsDuringUpgrade(iterator_to_array($iterator)); |
| 44 | + if (!rmdir($file) && file_exists($file)) { |
| 45 | + return 'Deletion of directory ' . $file . 'failed'; |
| 46 | + } |
| 47 | + } elseif (!unlink($file) && file_exists($file)) { |
| 48 | + return 'Deletion of file ' . $file . 'failed'; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return true; |
| 53 | +} |
| 54 | +/** |
| 55 | + * This upgrade file removes the folder vendor/phpunit, when added from a previous release installed on the shop. |
| 56 | + * |
| 57 | + * @return true|array |
| 58 | + */ |
| 59 | +function upgrade_module_4_10_1($module) |
| 60 | +{ |
| 61 | + $path = __DIR__ . '/../vendor/phpunit'; |
| 62 | + if (file_exists($path)) { |
| 63 | + $result = removeFromFsDuringUpgrade(array($path)); |
| 64 | + if ($result !== true) { |
| 65 | + PrestaShopLogger::addLog('Could not delete PHPUnit from module. ' . $result, 3); |
| 66 | + |
| 67 | + return false; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + return true; |
| 72 | +} |
0 commit comments