Skip to content

Commit

Permalink
Check dependencies when updating #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Riley committed Jun 29, 2022
1 parent 4536c6a commit 93250b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Update
- Updater now verifies changes to the AdminUI install dependencies before deciding whether to run a composer update.
11 changes: 10 additions & 1 deletion src/Controllers/BaseInstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -272,14 +273,16 @@ 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();

if ($process->isSuccessful()) {
$this->addOutput("Composer update complete", false, $process->getOutput());
} else {
$this->addOutput("Composer error:", false, $process->getErrorOutput());
return $this->sendFailed();
}
}

Expand Down Expand Up @@ -339,4 +342,10 @@ protected function sendFailed()
'log' => $this->output
]);
}

protected function hashLockFileContents(string $root)
{
$path = $root . "/composer.json";
return hash_file('sha256', $path);
}
}
24 changes: 23 additions & 1 deletion src/Controllers/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 93250b3

Please sign in to comment.