+
+
+function findOnlyDirectory($topDir) {
+ // Ensure the directory exists and is indeed a directory
+ if (!is_dir($topDir)) {
+ die("The specified path is not a directory.");
+ }
+
+ // Open the directory
+ $dirHandle = opendir($topDir);
+ if ($dirHandle === false) {
+ die("Unable to open directory.");
+ }
+
+ $directories = [];
+
+ // Read through the directory contents
+ while (($entry = readdir($dirHandle)) !== false) {
+ $fullPath = $topDir . DIRECTORY_SEPARATOR . $entry;
+ // Check if the entry is a directory and not . or ..
+ if (is_dir($fullPath) && $entry !== '.' && $entry !== '..') {
+ $directories[] = $fullPath;
+ }
+ }
+
+ // Close the directory handle
+ closedir($dirHandle);
+
+ // Check if there is exactly one directory
+ if (count($directories) === 1) {
+ return $directories[0];
+ } elseif (count($directories) === 0) {
+ return "No directories found after extracting. Possibly missing php-zip extention. Aborting upgrade.";
+ } else {
+ return "Multiple directories found. Previous cleanup was unsuccessful for some reason, maybe a permissions error? Aborting upgrade.";
+ }
+}
\ No newline at end of file