From 93250b359c479785d86ecacd68cacb79521fc183 Mon Sep 17 00:00:00 2001 From: Craig Riley Date: Wed, 29 Jun 2022 19:10:34 +0100 Subject: [PATCH] Check dependencies when updating #patch --- changelog/next.md | 2 ++ src/Controllers/BaseInstallController.php | 11 ++++++++++- src/Controllers/UpdateController.php | 24 ++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/changelog/next.md b/changelog/next.md index e69de29..3ba32b3 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -0,0 +1,2 @@ +## Update +- Updater now verifies changes to the AdminUI install dependencies before deciding whether to run a composer update. \ No newline at end of file diff --git a/src/Controllers/BaseInstallController.php b/src/Controllers/BaseInstallController.php index edd17c6..c577183 100644 --- a/src/Controllers/BaseInstallController.php +++ b/src/Controllers/BaseInstallController.php @@ -163,6 +163,7 @@ protected function installArchive(ZipArchive $archive) File::move($absoluteSource, $absoluteDestination); $this->addOutput("Extracted size is " . $this->getDirectorySize($absoluteDestination)); $this->addOutput("Moved extracted files"); + return $absoluteDestination; } /** @@ -272,7 +273,8 @@ protected function runComposerUpdate() return $this->sendFailed(); } - $process = new Process([$phpBinaryPath, config('adminui-installer.base_path') . '/lib/composer.phar', "update"], null, ["PATH" => '$PATH:/usr/local/bin']); + $process = new Process([$phpBinaryPath, config('adminui-installer.base_path') . '/lib/composer.phar', "update", "--no-interaction", "--no-scripts"], null, ["PATH" => '$PATH:/usr/local/bin']); + $process->setTimeout(300); $process->setWorkingDirectory(base_path()); $process->run(); @@ -280,6 +282,7 @@ protected function runComposerUpdate() $this->addOutput("Composer update complete", false, $process->getOutput()); } else { $this->addOutput("Composer error:", false, $process->getErrorOutput()); + return $this->sendFailed(); } } @@ -339,4 +342,10 @@ protected function sendFailed() 'log' => $this->output ]); } + + protected function hashLockFileContents(string $root) + { + $path = $root . "/composer.json"; + return hash_file('sha256', $path); + } } diff --git a/src/Controllers/UpdateController.php b/src/Controllers/UpdateController.php index 955af68..c433f50 100644 --- a/src/Controllers/UpdateController.php +++ b/src/Controllers/UpdateController.php @@ -98,7 +98,9 @@ public function updateSystem(Request $request) if ($archive->open($zipPath) === true) { $this->addOutput("Extract complete"); - $this->installArchive($archive); + $absoluteDestination = $this->installArchive($archive); + $this->checkForComposerUpdate($absoluteDestination); + $this->migrateAndSeedUpdate(); Artisan::call('vendor:publish', [ '--provider' => 'AdminUI\AdminUI\Provider', @@ -166,4 +168,24 @@ public function refresh() Artisan::call('optimize'); return $this->sendSuccess("Site refreshed"); } + + private function checkForComposerUpdate($packageLocation) + { + $updateHash = $this->hashLockFileContents($packageLocation); + $installedHash = \AdminUI\AdminUI\Models\Configuration::where('name', 'installed_composer_hash')->firstOrCreate( + ['name' => 'installed_composer_hash'], + [ + 'label' => 'Composer JSON file hash', + 'value' => '', + 'section' => 'private', + 'type' => 'text' + ] + ); + + if ($updateHash !== $installedHash) { + $this->runComposerUpdate(); + $installedHash->value = $updateHash; + $installedHash->save(); + } + } }