diff --git a/src/library/FOSSBilling/Update.php b/src/library/FOSSBilling/Update.php index ac089a1c9..1f9a786dd 100644 --- a/src/library/FOSSBilling/Update.php +++ b/src/library/FOSSBilling/Update.php @@ -247,19 +247,28 @@ class Update implements InjectionAwareInterface throw new Exception('Failed to extract file, please check file and folder permissions. Further details are available in the error log.'); } - // Apply system patches and migrate configuration file. + // Create the update patcher $patcher = new UpdatePatcher(); $patcher->setDi($this->di); - $patcher->applyCorePatches(); - // Apply configuration file patches. + // Clear the cache folder to reduce chances of errors + try { + $filesystem = new Filesystem(); + $filesystem->remove(PATH_CACHE); + $filesystem->mkdir(PATH_CACHE, 0755); + } catch (\Exception) { + // This step is rarely important, we can safely ignore an error here + } + + // Now run the patches + $patcher->applyCorePatches(); $patcher->applyConfigPatches(); - // Clear cache and remove install folder. + // Clear cache and remove the install folder. try { $filesystem = new Filesystem(); $filesystem->remove([PATH_CACHE, PATH_ROOT . '/install']); - $filesystem->mkdir(PATH_CACHE, 0777); + $filesystem->mkdir(PATH_CACHE, 0755); } catch (IOException $e) { error_log($e->getMessage()); diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index 76c233c33..8b196f564 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -372,9 +372,12 @@ class UpdatePatcher implements InjectionAwareInterface }, 42 => function () { // This patch will migrate previous currency exchange rate data provider settings to the new ones + // @see https://github.com/FOSSBilling/FOSSBilling/pull/2189 $ext_service = $this->di['mod_service']('extension'); - $config = $ext_service->getConfig('mod_currency'); $pairs = $this->di['db']->getAssoc('SELECT `param`, `value` FROM setting'); + $config = $ext_service->getConfig('mod_currency'); + + $config['ext'] = 'mod_currency'; // This should automatically be set, but some appear to be having cache issues that causes it to not be // Migrate the old currency exchange rate sync settings $key = $pairs['currencylayer'] ?? ''; @@ -399,6 +402,11 @@ class UpdatePatcher implements InjectionAwareInterface return array_filter($patches, fn ($key) => $key > $patchLevel, ARRAY_FILTER_USE_KEY); } + /** + * If we end up needing a newly introduced package during the update process, composer's autoloader won't have it until the next load. + * As a workaround, we can register AntLoader and point it at the Vendor folder which will then act as fallback to find the needed classes. + * This isn't particularly fast though as it'll scan the entire vendor, so only use it if we know a needed class is missing. + */ private function registerFallbackAutoloader() { $loader = new \AntCMS\AntLoader([