summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorJonas Meurer <jonas@freesources.org>2021-12-15 13:41:36 +0100
committerJonas Meurer <jonas@freesources.org>2021-12-20 11:40:10 +0100
commit7ec1317b1bb42bbbeaff3cf623a5dc6570a468c8 (patch)
treed603d357ac299c32ed0c528c0c25bb6868437e25 /lib/public
parente60ae8aaf274d318cb3678a3d70a27d2b1747034 (diff)
downloadnextcloud-server-7ec1317b1bb42bbbeaff3cf623a5dc6570a468c8.tar.gz
nextcloud-server-7ec1317b1bb42bbbeaff3cf623a5dc6570a468c8.zip
Sort app scripts by dependencies (Fixes: #30278)
Signed-off-by: Jonas Meurer <jonas@freesources.org>
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/Util.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/public/Util.php b/lib/public/Util.php
index d0b23ddd3e0..c22ee95563c 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -78,6 +78,9 @@ class Util {
/** @var array */
private static $scripts = [];
+ /** @var array */
+ private static $scriptDeps = [];
+
/**
* get the current installed version of Nextcloud
* @return array
@@ -216,13 +219,15 @@ class Util {
// ]
// ]
if (!empty($afterAppId)) {
- // init afterAppId app array if it doesn't exists
+ // init afterAppId app array if it doesn't exist
if (!array_key_exists($afterAppId, self::$scripts)) {
self::$scripts[$afterAppId] = ['first' => [], 'last' => []];
}
self::$scripts[$afterAppId]['last'][] = $path;
+ // store dependency
+ self::$scriptDeps[$application] = $afterAppId;
} else {
- // init app array if it doesn't exists
+ // init app array if it doesn't exist
if (!array_key_exists($application, self::$scripts)) {
self::$scripts[$application] = ['first' => [], 'last' => []];
}
@@ -237,12 +242,31 @@ class Util {
*/
public static function getScripts(): array {
// merging first and last data set
- $mapFunc = function (array $scriptsArray): array {
+ $mapFunc = static function (array $scriptsArray): array {
return array_merge(...array_values($scriptsArray));
};
$appScripts = array_map($mapFunc, self::$scripts);
+
+ // Sort by dependency if any
+ $sortedScripts = [];
+ foreach ($appScripts as $app => $scripts) {
+ if (array_key_exists($app, self::$scriptDeps)) {
+ $dep = self::$scriptDeps[$app];
+ if (!array_key_exists($dep, $sortedScripts)) {
+ $sortedScripts[$dep] = [];
+ }
+ array_push($sortedScripts[$dep], ...$scripts);
+ } else {
+ if (!array_key_exists($app, $sortedScripts)) {
+ $sortedScripts[$app] = [];
+ }
+ array_unshift($sortedScripts[$app], ...$scripts);
+ }
+ }
+
// sort core first
- $scripts = array_merge(isset($appScripts['core']) ? $appScripts['core'] : [], ...array_values($appScripts));
+ $scripts = array_merge(isset($sortedScripts['core']) ? $sortedScripts['core'] : [], ...array_values($sortedScripts));
+
// remove duplicates
return array_unique($scripts);
}