1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 20:04:24 +02:00

Change minor updating to update everything as is currently

This commit is contained in:
SychO9
2021-11-18 15:14:22 +01:00
parent 71e812c386
commit 38cd56c351
11 changed files with 1120 additions and 54 deletions

View File

@@ -83,7 +83,7 @@ class MajorUpdateHandler
return true;
}
$this->lastUpdateCheck->forget('flarum/*', true);
$this->lastUpdateCheck->forgetAll();
$this->events->dispatch(
new FlarumUpdated(FlarumUpdated::MAJOR)

View File

@@ -10,6 +10,7 @@
namespace Flarum\PackageManager\Command;
use Flarum\PackageManager\Composer\ComposerAdapter;
use Flarum\PackageManager\Composer\ComposerJson;
use Illuminate\Contracts\Events\Dispatcher;
use Flarum\PackageManager\Event\FlarumUpdated;
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
@@ -33,11 +34,17 @@ class MinorFlarumUpdateHandler
*/
protected $events;
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events)
/**
* @var ComposerJson
*/
protected $composerJson;
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, ComposerJson $composerJson)
{
$this->composer = $composer;
$this->lastUpdateCheck = $lastUpdateCheck;
$this->events = $events;
$this->composerJson = $composerJson;
}
/**
@@ -48,15 +55,20 @@ class MinorFlarumUpdateHandler
{
$command->actor->assertAdmin();
$coreRequirement = $this->composerJson->get()['require']['flarum/core'];
$this->composerJson->require('*', '*');
$this->composerJson->require('flarum/core', $coreRequirement);
$output = $this->composer->run(
new StringInput("update flarum/* --prefer-dist --no-dev -a --with-all-dependencies")
new StringInput("update --prefer-dist --no-dev -a --with-all-dependencies")
);
if ($output->getExitCode() !== 0) {
throw new ComposerUpdateFailedException('flarum/*', $output->getContents());
}
$this->lastUpdateCheck->forget('flarum/*', true);
$this->lastUpdateCheck->forgetAll();
$this->events->dispatch(
new FlarumUpdated(FlarumUpdated::MINOR)

View File

@@ -11,6 +11,7 @@ namespace Flarum\PackageManager\Composer;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
class ComposerJson
{
@@ -37,24 +38,26 @@ class ComposerJson
public function require(string $packageName, string $version): void
{
$composerJson = $this->getComposerJson();
$composerJson = $this->get();
if (strpos($packageName, '*') === false) {
$composerJson['require'][$packageName] = $version;
} else {
foreach ($composerJson['require'] as $p => $v) {
if (preg_match(preg_quote(str_replace('*', '.*', $packageName), '/'), $p, $matches)) {
$wildcardPackageName = str_replace('\*', '.*', preg_quote($packageName, '/'));
if (Str::of($p)->test("/($wildcardPackageName)/")) {
$composerJson['require'][$p] = $version;
}
}
}
$this->setComposerJson($composerJson);
$this->set($composerJson);
}
public function revert(): void
{
$this->setComposerJson($this->initialJson);
$this->set($this->initialJson);
}
protected function getComposerJsonPath(): string
@@ -65,7 +68,7 @@ class ComposerJson
/**
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function getComposerJson(): array
public function get(): array
{
$json = json_decode($this->filesystem->get($this->getComposerJsonPath()), true);
@@ -76,7 +79,7 @@ class ComposerJson
return $json;
}
protected function setComposerJson(array $json): void
protected function set(array $json): void
{
$this->filesystem->put($this->getComposerJsonPath(), json_encode($json, JSON_PRETTY_PRINT));
}

View File

@@ -60,7 +60,7 @@ class LastUpdateCheck
if (isset($lastUpdateCheck['updates']) && ! empty($lastUpdateCheck['updates']['installed'])) {
$updatesListChanged = false;
$pattern = preg_quote(str_replace('*', '.*', $name));
$pattern = str_replace('\*', '.*', preg_quote($name, '/'));
foreach ($lastUpdateCheck['updates']['installed'] as $k => $package) {
if (($wildcard && Str::of($package['name'])->test("/($pattern)/")) || $package['name'] === $name) {
@@ -79,4 +79,9 @@ class LastUpdateCheck
}
}
}
public function forgetAll(): void
{
$this->save([]);
}
}