From eb4f52434a8e9ae4361f261d6f2c8c39ca159233 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Sun, 15 Oct 2023 15:48:40 +0200 Subject: [PATCH] feat: added progress callback for installation (#2492) --- phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php b/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php index b1b56aff75..42cc7f525c 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php @@ -293,6 +293,9 @@ public function installPackage(callable $progressCallback): bool RecursiveIteratorIterator::SELF_FIRST ); + $totalFiles = iterator_count($sourceDirIterator); + $currentFile = 0; + foreach ($sourceDirIterator as $item) { $source = $item->getPathName(); $destination = $destinationDir . DIRECTORY_SEPARATOR . $sourceDirIterator->getSubPathName(); @@ -304,6 +307,10 @@ public function installPackage(callable $progressCallback): bool } else { copy($source, $destination); } + + $currentFile++; + $progress = $totalFiles > 0 ? sprintf('%d%%', ($currentFile / $totalFiles) * 100) : 100; + call_user_func($progressCallback, $progress); } return true; }