mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 16:32:45 +08:00
Change minor updating to update everything as is currently
This commit is contained in:
parent
71e812c386
commit
38cd56c351
1015
extensions/package-manager/js/dist/admin.js
vendored
1015
extensions/package-manager/js/dist/admin.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,4 @@
|
|||
import Mithril from "mithril";
|
||||
import app from 'flarum/admin/app';
|
||||
import Component from 'flarum/common/Component';
|
||||
import icon from 'flarum/common/helpers/icon';
|
||||
|
@ -9,6 +10,7 @@ import errorHandler from '../utils/errorHandler';
|
|||
import classList from 'flarum/common/utils/classList';
|
||||
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
|
||||
import MajorUpdater from './MajorUpdater';
|
||||
import {Extension} from "flarum/admin/AdminApplication";
|
||||
|
||||
export type UpdatedPackage = {
|
||||
name: string;
|
||||
|
@ -20,37 +22,44 @@ export type UpdatedPackage = {
|
|||
description: string;
|
||||
};
|
||||
|
||||
type ComposerUpdates = {
|
||||
export type ComposerUpdates = {
|
||||
installed: UpdatedPackage[];
|
||||
};
|
||||
|
||||
type LastUpdateCheck = {
|
||||
export type LastUpdateCheck = {
|
||||
checkedAt: Date;
|
||||
updates: ComposerUpdates;
|
||||
};
|
||||
|
||||
export default class Updater extends Component {
|
||||
export default class Updater<Attrs> extends Component<Attrs> {
|
||||
isLoading: string | null = null;
|
||||
lastUpdateCheck: LastUpdateCheck = app.data.lastUpdateCheck || {};
|
||||
lastUpdateCheck: LastUpdateCheck = (app.data.lastUpdateCheck as LastUpdateCheck) || {};
|
||||
packageUpdates: Record<string, UpdatedPackage> = {};
|
||||
|
||||
oninit(vnode) {
|
||||
oninit(vnode: Mithril.Vnode<Attrs, this>) {
|
||||
super.oninit(vnode);
|
||||
}
|
||||
|
||||
view() {
|
||||
const extensions: any = this.getExtensionUpdates();
|
||||
const coreUpdate: UpdatedPackage | undefined = this.getCoreUpdate();
|
||||
let core = null;
|
||||
let core: any = null;
|
||||
|
||||
if (coreUpdate) {
|
||||
core = {
|
||||
title: app.translator.trans('flarum-package-manager.admin.updater.flarum'),
|
||||
id: "flarum-core",
|
||||
version: app.data.settings.version,
|
||||
icon: {
|
||||
backgroundImage: `url(${app.forum.attribute('baseUrl')}/assets/extensions/flarum-package-manager/flarum.svg`,
|
||||
},
|
||||
newPackageUpdate: coreUpdate,
|
||||
extra: {
|
||||
'flarum-extension': {
|
||||
title: app.translator.trans('flarum-package-manager.admin.updater.flarum'),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.packageUpdates['flarum-core'] = coreUpdate;
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -102,7 +111,7 @@ export default class Updater extends Component {
|
|||
];
|
||||
}
|
||||
|
||||
extensionItem(extension: any, isCore: boolean = false) {
|
||||
extensionItem(extension: Extension, isCore: boolean = false) {
|
||||
return (
|
||||
<div
|
||||
className={classList({
|
||||
|
@ -114,17 +123,17 @@ export default class Updater extends Component {
|
|||
{extension.icon ? icon(extension.icon.name) : ''}
|
||||
</div>
|
||||
<div className="PackageManager-extension-info">
|
||||
<div className="PackageManager-extension-name">{extension.title || extension.extra['flarum-extension'].title}</div>
|
||||
<div className="PackageManager-extension-name">{extension.extra['flarum-extension'].title}</div>
|
||||
<div className="PackageManager-extension-version">
|
||||
<span className="PackageManager-extension-version-current">{this.version(extension.version)}</span>
|
||||
{extension.newPackageUpdate['latest-minor'] ? (
|
||||
{this.packageUpdates[extension.id]['latest-minor'] ? (
|
||||
<span className="PackageManager-extension-version-latest PackageManager-extension-version-latest--minor">
|
||||
{this.version(extension.newPackageUpdate['latest-minor'])}
|
||||
{this.version(this.packageUpdates[extension.id]['latest-minor']!)}
|
||||
</span>
|
||||
) : null}
|
||||
{extension.newPackageUpdate['latest-major'] && !isCore ? (
|
||||
{this.packageUpdates[extension.id]['latest-major'] && !isCore ? (
|
||||
<span className="PackageManager-extension-version-latest PackageManager-extension-version-latest--major">
|
||||
{this.version(extension.newPackageUpdate['latest-major'])}
|
||||
{this.version(this.packageUpdates[extension.id]['latest-major']!)}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
@ -153,13 +162,13 @@ export default class Updater extends Component {
|
|||
const safeToUpdate = ['semver-safe-update', 'update-possible'].includes(composerPackage['latest-status']);
|
||||
|
||||
if (extension && safeToUpdate) {
|
||||
extension.newPackageUpdate = composerPackage;
|
||||
this.packageUpdates[extension.id] = composerPackage;
|
||||
}
|
||||
|
||||
return extension && safeToUpdate;
|
||||
});
|
||||
|
||||
return Object.values(app.data.extensions).filter((extension: any) => extension.newPackageUpdate);
|
||||
return Object.values(app.data.extensions).filter((extension: any) => this.packageUpdates[extension.id]);
|
||||
}
|
||||
|
||||
getCoreUpdate(): UpdatedPackage | undefined {
|
||||
|
@ -185,23 +194,25 @@ export default class Updater extends Component {
|
|||
}
|
||||
|
||||
updateCoreMinor() {
|
||||
app.modal.show(LoadingModal);
|
||||
this.isLoading = 'minor-update';
|
||||
if (confirm(app.translator.trans('flarum-package-manager.admin.minor_update_confirmation.content'))) {
|
||||
app.modal.show(LoadingModal);
|
||||
this.isLoading = 'minor-update';
|
||||
|
||||
app
|
||||
.request({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/minor-update`,
|
||||
errorHandler,
|
||||
})
|
||||
.then(() => {
|
||||
app.alerts.show({ type: 'success' }, app.translator.trans('flarum-package-manager.admin.update_successful'));
|
||||
window.location.reload();
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = null;
|
||||
m.redraw();
|
||||
});
|
||||
/*app
|
||||
.request({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/minor-update`,
|
||||
errorHandler,
|
||||
})
|
||||
.then(() => {
|
||||
app.alerts.show({ type: 'success' }, app.translator.trans('flarum-package-manager.admin.update_successful'));
|
||||
window.location.reload();
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = null;
|
||||
m.redraw();
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
updateExtension(extension: any) {
|
||||
|
|
|
@ -7,7 +7,6 @@ import LoadingModal from 'flarum/admin/components/LoadingModal';
|
|||
import Installer from './components/Installer';
|
||||
import Updater from './components/Updater';
|
||||
import isExtensionEnabled from 'flarum/admin/utils/isExtensionEnabled';
|
||||
import MajorUpdater from './components/MajorUpdater';
|
||||
|
||||
app.initializers.add('flarum-package-manager', (app) => {
|
||||
app.extensionData
|
||||
|
@ -22,16 +21,22 @@ app.initializers.add('flarum-package-manager', (app) => {
|
|||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.registerSetting(() => {
|
||||
if (app.data.isRequiredDirectoriesWritable) {
|
||||
return <Installer />;
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.registerSetting(() => {
|
||||
if (app.data.isRequiredDirectoriesWritable) {
|
||||
return <Updater />;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
extend(ExtensionPage.prototype, 'topItems', function (items) {
|
|
@ -1,11 +1,16 @@
|
|||
{
|
||||
"extends": "flarum-tsconfig",
|
||||
"include": ["src/**/*"],
|
||||
"compilerOptions": {
|
||||
"declarationDir": "./dist-typings",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
||||
// Use Flarum's tsconfig as a starting point
|
||||
"extends": "flarum-tsconfig",
|
||||
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
|
||||
// and also tells your Typescript server to read core's global typings for
|
||||
// access to `dayjs` and `$` in the global namespace.
|
||||
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
|
||||
"compilerOptions": {
|
||||
// This will output typings to `dist-typings`
|
||||
"declarationDir": "./dist-typings",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,3 +119,12 @@
|
|||
grid-area: helpText;
|
||||
}
|
||||
}
|
||||
|
||||
.MinorUpdateWarningModal {
|
||||
.Modal-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ flarum-package-manager:
|
|||
title: Flarum {version} Major Update Available
|
||||
update: Update
|
||||
|
||||
minor_update_confirmation:
|
||||
content: This will also update any other extensions/packages with availabe updates.
|
||||
|
||||
updater:
|
||||
check_for_updates: Check for updates
|
||||
flarum: Flarum Core
|
||||
|
|
|
@ -83,7 +83,7 @@ class MajorUpdateHandler
|
|||
return true;
|
||||
}
|
||||
|
||||
$this->lastUpdateCheck->forget('flarum/*', true);
|
||||
$this->lastUpdateCheck->forgetAll();
|
||||
|
||||
$this->events->dispatch(
|
||||
new FlarumUpdated(FlarumUpdated::MAJOR)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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([]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user