+ function extractZip() {
+ $zip = new ZipArchive;
+ if ($zip->open($this->temp_dir."unrealircd-webpanel-upgrade.zip") === true)
+ {
+ $zip->extractTo("$this->temp_dir");
+ $zip->close();
+ self::$temp_extracted_dir = findOnlyDirectory($this->temp_dir);
+ error_log(self::$temp_extracted_dir);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ function cleanupOldFiles()
+ {
+ foreach ($this->compareAndGetFilesToDelete() as $file)
+ {
+ unlink("$this->web_dir$file");
+ error_log("Deleting: $file");
+ }
+ }
+ function compareAndGetFilesToDelete() : array
+ {
+ $currentFiles = $this->listFiles($this->web_dir);
+ $updateFiles = $this->listFiles(self::$temp_extracted_dir);
+ $filesToDelete = array_diff($currentFiles, $updateFiles);
+ $filesToActuallyDelete = [];
+ error_log("Comparing... Files to delete:");
+ foreach ($filesToDelete as $file)
+ {
+ // skip the relevant directories
+ if (str_starts_with($file, "panel_upgrade/")
+ || str_starts_with($file, "vendor/")
+ || str_starts_with($file, "config/")
+ || str_starts_with($file, "data/")
+ || str_starts_with($file, "plugins/"))
+ continue;
+ $filesToActuallyDelete[] = $file;
+ }
+ return $filesToActuallyDelete;
+ }
+
+ function extractToWebdir()
+ {
+ recurse_copy(self::$temp_extracted_dir, $this->web_dir);
+ }
+
+ /**
+ * Cleans up the extracted update files
+ * @return void
+ */
+ function cleanupDownloadFiles()
+ {
+ $ex_dir = self::$temp_extracted_dir ?? findOnlyDirectory($this->temp_dir);
+ deleteDirectoryContents($ex_dir);
+ rmdir($ex_dir);
+ }
+
+ function listFiles($dir) {
+ $files = [];
+ $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
+ foreach ($iterator as $file)
+ {
+ if ($file->isFile())
+ {
+ $f = substr($file->getPathname(), strlen($dir));
+ if ($f[0] == "/") $f = substr($f,1);
+
+ $files[] = $f;
+ }
+ }
+ return $files;
+ }