diff --git a/src/foss-update.php b/src/foss-update.php index 1907cc520..c87518b78 100644 --- a/src/foss-update.php +++ b/src/foss-update.php @@ -14,6 +14,19 @@ * with this source code in the file LICENSE */ +const DIR_SEP = DIRECTORY_SEPARATOR; + +class FOSSPatch_29 extends FOSSPatchAbstract +{ + public function patch() + { + $fileActions = [ + __DIR__ . DIR_SEP . 'vendor' . DIR_SEP . 'guzzlehttp' => 'unlink', + ]; + $this->performFileActions($fileActions); + } +} + /** * Patch to remove .html from email templates action code, see https://github.com/FOSSBilling/FOSSBilling/issues/863 */ @@ -70,6 +83,7 @@ abstract class FOSSPatchAbstract protected mixed $pdo; private int $version; private string $k = 'last_patch'; + private array $fileActions = []; public function __construct($di) { @@ -134,6 +148,43 @@ abstract class FOSSPatchAbstract return $r; } + + protected function performFileActions(array $files) + { + foreach ($files as $file => $action) { + $relPath = str_replace(__DIR__, '', $file); + if ($action == 'unlink' && file_exists($file) && !is_dir($file)) { + @unlink($file); + $this->fileActions[] = "Deleted: $relPath"; + } elseif ($action == 'unlink' && is_dir($file)) { + @$this->emptyFolder($file); + @rmdir($file); + $this->fileActions[] = "Deleted: $relPath"; + } elseif (file_exists($file)) { + @rename($file, $action); + $this->fileActions[] = "Moved: $relPath to " . str_replace(__DIR__, '', $action . ""); + } + } + } + + public function getFileActions() + { + return (!$this->fileActions) ? ['None'] : $this->fileActions; + } + + private function emptyFolder($folder) + { + /* Original source for this lovely codesnippet: https://stackoverflow.com/a/24563703 + * With modification suggested from KeineMaster (replaced $file with$file->getRealPath()) + */ + if (file_exists($folder)) { + $di = new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS); + $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($ri as $file) { + $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); + } + } + } } $patches = []; @@ -145,43 +196,93 @@ foreach (get_declared_classes() as $class) { require_once __DIR__ . '/load.php'; $di = include __DIR__ . '/di.php'; - -error_log('Executing FOSSBilling update script'); natsort($patches); +?> -$html = -' -'; + + -$html .= -' + FOSSBilling Updater -'; + + - error_log($msg); - } else { - error_log('Skipped patch ' . $p->getVersion()); - } -} -error_log('FOSSBilling update completed'); + +
+

FOSSBilling Updater

+
+
+ + + + + + + + + + isPatched()) { + $p->patch(); + $p->donePatching(); -$html .= '

Update completed. You are using FOSSBilling ' . Box_Version::VERSION . '

'; -$html .= -' -'; -echo $html; -exit; + $version = $p->getVersion(); + $fileActions = $p->getFileActions(); + ?> + + + + + + + +
Patch NumberStatusFile Actions Performed
Executed +
    +

    ' . $action . '

    '; + } ?> +
+
+

Update completed. You are using FOSSBilling

+
+ + diff --git a/src/load.php b/src/load.php index 878f322a4..00aa9b508 100644 --- a/src/load.php +++ b/src/load.php @@ -28,16 +28,6 @@ const PATH_UPLOADS = PATH_ROOT . DIRECTORY_SEPARATOR. 'uploads'; const PATH_DATA = PATH_ROOT . DIRECTORY_SEPARATOR. 'data'; const isCLI = 'cli' === PHP_SAPI; -// Deprecated aliases -const BB_PATH_ROOT = PATH_ROOT; -const BB_PATH_VENDOR = PATH_VENDOR; -const BB_PATH_LIBRARY = PATH_LIBRARY; -const BB_PATH_THEMES = PATH_THEMES; -const BB_PATH_MODS = PATH_MODS; -const BB_PATH_LANGS = PATH_LANGS; -const BB_PATH_UPLOADS = PATH_UPLOADS; -const BB_PATH_DATA = PATH_DATA; - function handler_error(int $number, string $message, string $file, int $line) { if (E_RECOVERABLE_ERROR === $number) {