diff --git a/core/ajax/repo.ajax.php b/core/ajax/repo.ajax.php index 8f36eff84a..64da2e6373 100644 --- a/core/ajax/repo.ajax.php +++ b/core/ajax/repo.ajax.php @@ -65,7 +65,23 @@ if ($update->getConfiguration('doNotUpdate') == 1) { throw new Exception(__('Mise à jour et réinstallation désactivées sur ', __FILE__) . ' ' . $repo->getLogicalId()); } - $update->setSource(init('repo')); + // Purge configuration keys not belonging to the new source to avoid orphaned data. + $newSource = init('repo'); + $allSourceKeys = [ + 'market' => ['market'], + 'github' => ['user', 'repository', 'token'], + 'url' => ['url'], + 'samba' => ['path'], + 'file' => ['path'], + ]; + $keysToKeep = $allSourceKeys[$newSource] ?? []; + foreach ($allSourceKeys as $source => $sourceKeys) { + if ($source === $newSource) continue; + foreach (array_diff($sourceKeys, $keysToKeep) as $key) { + $update->setConfiguration($key, null); + } + } + $update->setSource($newSource); $update->setLogicalId($repo->getLogicalId()); $update->setType($repo->getType()); $update->setLocalVersion($repo->getDatetime(init('version', 'stable'))); diff --git a/core/ajax/update.ajax.php b/core/ajax/update.ajax.php index db8bfa10f7..aebed360fe 100644 --- a/core/ajax/update.ajax.php +++ b/core/ajax/update.ajax.php @@ -149,6 +149,22 @@ } $old_update = $update; utils::a2o($update, $update_json); + // Purge configuration keys not belonging to the new source to avoid orphaned data. + $newSource = $update->getSource(); + $allSourceKeys = [ + 'market' => ['market'], + 'github' => ['user', 'repository', 'token'], + 'url' => ['url'], + 'samba' => ['path'], + 'file' => ['path'], + ]; + $keysToKeep = $allSourceKeys[$newSource] ?? []; + foreach ($allSourceKeys as $source => $sourceKeys) { + if ($source === $newSource) continue; + foreach (array_diff($sourceKeys, $keysToKeep) as $key) { + $update->setConfiguration($key, null); + } + } $update->save(); try { $update->doUpdate(); diff --git a/core/php/jeecli.php b/core/php/jeecli.php index 3bb4c84cce..958837b761 100644 --- a/core/php/jeecli.php +++ b/core/php/jeecli.php @@ -53,6 +53,10 @@ if (!is_object($update)) { $update = new update(); } + // Purge configuration keys not belonging to market source to avoid orphaned data. + foreach (['user', 'repository', 'token', 'url', 'path'] as $key) { + $update->setConfiguration($key, null); + } $update->setLogicalId($argv[3]); $update->setSource('market'); $update->setConfiguration('version', 'stable'); diff --git a/core/repo/market.repo.php b/core/repo/market.repo.php index d4a5de72bb..b46a1abdf8 100644 --- a/core/repo/market.repo.php +++ b/core/repo/market.repo.php @@ -139,12 +139,15 @@ public static function pullInstall() { if (!is_object($update)) { $update = new update(); } + // Purge configuration keys not belonging to market source to avoid orphaned data. + foreach (['user', 'repository', 'token', 'url', 'path'] as $key) { + $update->setConfiguration($key, null); + } $update->setSource('market'); $update->setLogicalId($repo->getLogicalId()); $update->setType($repo->getType()); $update->setLocalVersion($repo->getDatetime($plugin['version'])); $update->setConfiguration('version', $plugin['version']); - $update->setConfiguration('user', null); $update->save(); $update->doUpdate(); $nbInstall++; diff --git a/desktop/js/update.js b/desktop/js/update.js index 924b28bfbb..14459fd957 100644 --- a/desktop/js/update.js +++ b/desktop/js/update.js @@ -237,8 +237,8 @@ if (!jeeFrontEnd.update) { default: updClass = 'label-danger' } - if (typeof _update.configuration.user!== 'undefined'){ - tr += ' ' + _update.configuration.version +' - '+ _update.configuration.user + '' + if (typeof _update.configuration.user !== 'undefined' && _update.source !== 'market') { + tr += ' ' + _update.configuration.version + ' - ' + _update.configuration.user + '' } else { tr += ' ' + _update.configuration.version + '' }