mirror of
https://github.com/flarum/core.git
synced 2025-08-13 20:04:24 +02:00
Compare commits
1 Commits
v1.8.5
...
dk/DISCUSS
Author | SHA1 | Date | |
---|---|---|---|
|
dff35c1046 |
4
.github/workflows/REUSABLE_backend.yml
vendored
4
.github/workflows/REUSABLE_backend.yml
vendored
@@ -25,7 +25,7 @@ on:
|
||||
description: Versions of PHP to test with. Should be array of strings encoded as JSON array
|
||||
type: string
|
||||
required: false
|
||||
default: '["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]'
|
||||
default: '["7.3", "7.4", "8.0", "8.1", "8.2"]'
|
||||
|
||||
php_extensions:
|
||||
description: PHP extensions to install.
|
||||
@@ -91,8 +91,6 @@ jobs:
|
||||
# Include testing PHP 8.2 with deprecation warnings disabled.
|
||||
- php: 8.2
|
||||
php_ini_values: error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED
|
||||
- php: 8.3
|
||||
php_ini_values: error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED
|
||||
|
||||
# To reduce number of actions, we exclude some PHP versions from running with some DB versions.
|
||||
exclude:
|
||||
|
2
.github/workflows/frontend.yml
vendored
2
.github/workflows/frontend.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
backend_directory: ./
|
||||
js_package_manager: yarn
|
||||
cache_dependency_path: ./yarn.lock
|
||||
main_git_branch: 1.x
|
||||
main_git_branch: main
|
||||
enable_tests: true
|
||||
# @TODO: fix bundlewatch
|
||||
enable_bundlewatch: false
|
||||
|
8
.github/workflows/prepare-release.yml
vendored
8
.github/workflows/prepare-release.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
- name: Prepare release
|
||||
uses: flarum/action-release@master
|
||||
with:
|
||||
next_tag: ${{ inputs.version }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
open_collective_token: ${{ secrets.OPEN_COLLECTIVE_TOKEN }}
|
||||
env:
|
||||
NEXT_TAG: ${{ inputs.version }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
OPEN_COLLECTIVE_TOKEN: ${{ secrets.OPEN_COLLECTIVE_TOKEN }}
|
||||
|
71
CHANGELOG.md
71
CHANGELOG.md
@@ -1,76 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## [v1.8.5](https://github.com/flarum/framework/compare/v1.8.4...v1.8.5)
|
||||
### Fixed
|
||||
* Logout controller allows open redirects [#3948]
|
||||
|
||||
## [v1.8.4](https://github.com/flarum/framework/compare/v1.8.3...v1.8.4)
|
||||
### Fixed
|
||||
* `s9e/textformatter` 2.15 has breaking changes [#3946]
|
||||
|
||||
## [v1.8.3](https://github.com/flarum/framework/compare/v1.8.2...v1.8.3)
|
||||
### Fixed
|
||||
* Console extender does not accept ::class [#3900]
|
||||
* Conditional extender instantiation [#3898]
|
||||
|
||||
## [v1.8.2](https://github.com/flarum/framework/compare/v1.8.1...v1.8.2)
|
||||
### Fixed
|
||||
* suspended users can abuse avatar upload [#3890]
|
||||
* missing compat exports [#3888]
|
||||
|
||||
## [v1.8.1](https://github.com/flarum/framework/compare/v1.8.0...v1.8.1)
|
||||
### Fixed
|
||||
* recover temporary solution for html entities in browser title (e72541e35de4f71f9d870bbd9bb46ddf586bdf1d)
|
||||
* custom contrast color affected by parents (577890d89c593ae5b6cb96083fab69e2f1ae600c)
|
||||
* reply placeholder wrong positioning (253a3d281dbf5ce3fa712b629b80587cf67e7dbe)
|
||||
* (mentions) missed post mentions UI changes with lazy loading [#3832]
|
||||
* (mentions) cannot use newly introduced mentionables extender [#3849]
|
||||
* (mentions) missing slug from post mention links ([5a4bb7c](5a4bb7ccf226f66dd44816cb69b3d7cfe4ad7f7c))
|
||||
|
||||
## [v1.8.0](https://github.com/flarum/framework/compare/v1.7.1...v1.8.0)
|
||||
### Fixed
|
||||
- (a11y) reply placeholder not accessible [#3793]
|
||||
- (bbcode) highlight.js does not work after changing post content [#3817]
|
||||
- (bbcode) localize quote `wrote` string [#3809]
|
||||
- (mentions) mentions XHR fired even after mentioning is done [#3806]
|
||||
- (package-manager) available core updates cause an error in the dashboard ([fab71f2](fab71f2d01fa20ce9b3002833339dc5ea3ea6301))
|
||||
- (tags) not all tags are loaded in the permission grid [#3804]
|
||||
- (tags) tag discussion modal filters with exact matches only after first index [#3786]
|
||||
- (testing) always clear cache in integration test's tearDown [#3818]
|
||||
- `UserSecurityPage` not exported ([232618a](232618aba604ab003425df38b895208c863d3260))
|
||||
- `isDark()` utility can receive null value [#3774]
|
||||
- approving a post does not bump user `comment_count` [#3790]
|
||||
- circular dependencies disable all involved extensions [#3785]
|
||||
- color input overflowing the input box [#3796]
|
||||
- deleting a discussion from the profile does not visually remove it [#3799]
|
||||
- discussion page showing horizontal scroll on iOS [#3821]
|
||||
- empty string displayed as SelectDropdown title [#3773]
|
||||
- filter values are not validated [#3795]
|
||||
- infinite scroll not initialized for notifications on big screens [#3733]
|
||||
- notification subject discussion eager loading fails [#3788]
|
||||
- null as 2nd param in `preg_match` is deprecated [#3801]
|
||||
- unread count in post stream not visible [#3791]
|
||||
- unreadable badge icon on certain colors [#3810]
|
||||
- integrity constraint violation [#3772]
|
||||
### Changed
|
||||
- (core,mentions) limit `mentionedBy` post relation results [#3780]
|
||||
- (likes) limit `likes` relationship results [#3781]
|
||||
- Change some methods from private to protected, to be able to extend the affected classes [#3802]
|
||||
- Do not catch exceptions when testing Console commands [#3813]
|
||||
- drop usage of jquery in `install` and `update` interfaces [#3797]
|
||||
- extensibility improvements [#3729]
|
||||
- major frontend JS cleanup [#3609]
|
||||
- revert ineffective code for encoding of page title [#3768]
|
||||
- speed up post creation time [#3808]
|
||||
### Added
|
||||
- (mentions,tags) tag mentions [#3769]
|
||||
- add delete own posts permission [#3784]
|
||||
- add a trait to flush the formatter cache in tests [#3811]
|
||||
- add user creation to users list page [#3744]
|
||||
- cli command for enabling or disabling an extension [#3816]
|
||||
- conditional extenders [#3759]
|
||||
- provide old content to `Revised` event [#3789]
|
||||
|
||||
## [v1.7.1](https://github.com/flarum/framework/compare/v1.7.0...v1.7.1)
|
||||
### Fixed
|
||||
- (tags) composer tag selection modal using wrong primary max & min numbers (abc9670659426b765274376945b818b70d84848c)
|
||||
|
@@ -127,7 +127,7 @@
|
||||
"psr/http-server-handler": "^1.0",
|
||||
"psr/http-server-middleware": "^1.0",
|
||||
"pusher/pusher-php-server": "^2.2",
|
||||
"s9e/text-formatter": ">=2.3.6 <2.15",
|
||||
"s9e/text-formatter": "^2.3.6",
|
||||
"staudenmeir/eloquent-eager-limit": "^1.0",
|
||||
"sycho/json-api": "^0.5.0",
|
||||
"sycho/sourcemap": "^2.0.0",
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8",
|
||||
"flarum/core": "^1.7",
|
||||
"flarum/approval": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8",
|
||||
"flarum/core": "^1.7",
|
||||
"flarum/flags": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
|
@@ -11,7 +11,6 @@ namespace Flarum\Approval\Listener;
|
||||
|
||||
use Flarum\Approval\Event\PostWasApproved;
|
||||
use Flarum\Post\Event\Saving;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class ApproveContent
|
||||
@@ -24,42 +23,23 @@ class ApproveContent
|
||||
$events->listen(Saving::class, [$this, 'approvePost']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
public function approvePost(Saving $event)
|
||||
{
|
||||
$attributes = $event->data['attributes'];
|
||||
$post = $event->post;
|
||||
|
||||
// Nothing to do if it is already approved.
|
||||
if ($post->is_approved) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We approve a post in one of two cases:
|
||||
* - The post was unapproved and the allowed action is approving it. We trigger an event.
|
||||
* - The post was unapproved and the allowed actor is hiding or un-hiding it.
|
||||
* We approve it silently if the action is unhiding.
|
||||
*/
|
||||
$approvingSilently = false;
|
||||
|
||||
if (isset($attributes['isApproved'])) {
|
||||
$event->actor->assertCan('approve', $post);
|
||||
|
||||
$isApproved = (bool) $attributes['isApproved'];
|
||||
} elseif (isset($attributes['isHidden']) && $event->actor->can('approve', $post)) {
|
||||
} elseif (! empty($attributes['isHidden']) && $event->actor->can('approve', $post)) {
|
||||
$isApproved = true;
|
||||
$approvingSilently = $attributes['isHidden'];
|
||||
}
|
||||
|
||||
if (! empty($isApproved)) {
|
||||
$post->is_approved = true;
|
||||
|
||||
if (! $approvingSilently) {
|
||||
$post->raise(new PostWasApproved($post, $event->actor));
|
||||
}
|
||||
$post->raise(new PostWasApproved($post, $event->actor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -44,6 +44,7 @@ class LoadLikesRelationship
|
||||
$loadable = null;
|
||||
|
||||
if ($data instanceof Discussion) {
|
||||
// @phpstan-ignore-next-line
|
||||
$loadable = $data->newCollection($data->posts)->filter(function ($post) {
|
||||
return $post instanceof Post;
|
||||
});
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -78,17 +78,15 @@ return [
|
||||
->addInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion'])
|
||||
->load([
|
||||
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user',
|
||||
'posts.mentionsPosts.discussion', 'posts.mentionsGroups'
|
||||
'posts.mentionsGroups'
|
||||
])
|
||||
->loadWhere('posts.mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
|
||||
(new Extend\ApiController(Controller\ListDiscussionsController::class))
|
||||
->load([
|
||||
'firstPost.mentionsUsers', 'firstPost.mentionsPosts',
|
||||
'firstPost.mentionsPosts.user', 'firstPost.mentionsPosts.discussion', 'firstPost.mentionsGroups',
|
||||
'lastPost.mentionsUsers', 'lastPost.mentionsPosts',
|
||||
'lastPost.mentionsPosts.user', 'lastPost.mentionsPosts.discussion', 'lastPost.mentionsGroups',
|
||||
'firstPost.mentionsUsers', 'firstPost.mentionsPosts', 'firstPost.mentionsPosts.user', 'firstPost.mentionsGroups',
|
||||
'lastPost.mentionsUsers', 'lastPost.mentionsPosts', 'lastPost.mentionsPosts.user', 'lastPost.mentionsGroups',
|
||||
]),
|
||||
|
||||
(new Extend\ApiController(Controller\ShowPostController::class))
|
||||
@@ -100,7 +98,7 @@ return [
|
||||
|
||||
(new Extend\ApiController(Controller\ListPostsController::class))
|
||||
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
||||
->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsPosts.discussion', 'mentionsGroups'])
|
||||
->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsGroups'])
|
||||
->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
|
||||
|
2
extensions/mentions/js/dist/forum.js
generated
vendored
2
extensions/mentions/js/dist/forum.js
generated
vendored
File diff suppressed because one or more lines are too long
2
extensions/mentions/js/dist/forum.js.map
generated
vendored
2
extensions/mentions/js/dist/forum.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -5,9 +5,12 @@ import TextEditorButton from 'flarum/common/components/TextEditorButton';
|
||||
import KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable';
|
||||
|
||||
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
||||
import MentionFormats from './mentionables/formats/MentionFormats';
|
||||
import MentionableModels from './mentionables/MentionableModels';
|
||||
|
||||
export default function addComposerAutocomplete() {
|
||||
app.mentionFormats = new MentionFormats();
|
||||
|
||||
const $container = $('<div class="ComposerBody-mentionsDropdownContainer"></div>');
|
||||
const dropdown = new AutocompleteDropdown();
|
||||
|
||||
|
@@ -118,7 +118,7 @@ export default function addMentionedByList() {
|
||||
});
|
||||
|
||||
const limit = 4;
|
||||
const overLimit = post.mentionedByCount() > limit;
|
||||
const overLimit = repliers.length > limit;
|
||||
|
||||
// Create a list of unique users who have replied. So even if a user has
|
||||
// replied twice, they will only be in this array once.
|
||||
@@ -136,7 +136,7 @@ export default function addMentionedByList() {
|
||||
// others" name to the end of the list. Clicking on it will display a modal
|
||||
// with a full list of names.
|
||||
if (overLimit) {
|
||||
const count = post.mentionedByCount() - names.length;
|
||||
const count = repliers.length - names.length;
|
||||
|
||||
names.push(app.translator.trans('flarum-mentions.forum.post.others_text', { count }));
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import type MentionFormat from '../mentionables/formats/MentionFormat';
|
||||
|
||||
export default class Mentionables implements IExtender<ForumApplication> {
|
||||
protected formats: (new () => MentionFormat)[] = [];
|
||||
protected mentionables: Record<string, (new (...args: any[]) => MentionableModel)[]> = {};
|
||||
protected mentionables: Record<string, (new () => MentionableModel)[]> = {};
|
||||
|
||||
/**
|
||||
* Register a new mention format.
|
||||
@@ -26,7 +26,7 @@ export default class Mentionables implements IExtender<ForumApplication> {
|
||||
* @param mentionable The mentionable instance to register.
|
||||
* Must extend MentionableModel.
|
||||
*/
|
||||
mentionable(symbol: string, mentionable: new (...args: any[]) => MentionableModel): this {
|
||||
mentionable(symbol: string, mentionable: new () => MentionableModel): this {
|
||||
if (!this.mentionables[symbol]) {
|
||||
this.mentionables[symbol] = [];
|
||||
}
|
||||
|
@@ -13,14 +13,11 @@ import addComposerAutocomplete from './addComposerAutocomplete';
|
||||
import PostMentionedNotification from './components/PostMentionedNotification';
|
||||
import UserMentionedNotification from './components/UserMentionedNotification';
|
||||
import GroupMentionedNotification from './components/GroupMentionedNotification';
|
||||
import MentionFormats from './mentionables/formats/MentionFormats';
|
||||
import UserPage from 'flarum/forum/components/UserPage';
|
||||
import LinkButton from 'flarum/common/components/LinkButton';
|
||||
import User from 'flarum/common/models/User';
|
||||
import Model from 'flarum/common/Model';
|
||||
|
||||
app.mentionFormats = new MentionFormats();
|
||||
|
||||
export { default as extend } from './extend';
|
||||
|
||||
app.initializers.add('flarum-mentions', function () {
|
||||
|
@@ -4,7 +4,7 @@ import TagMention from '../TagMention';
|
||||
|
||||
export default class HashMentionFormat extends MentionFormat {
|
||||
public mentionables: (new (...args: any[]) => MentionableModel)[] = [TagMention];
|
||||
protected extendable: boolean = true;
|
||||
protected extendable: boolean = false;
|
||||
|
||||
public trigger(): string {
|
||||
return '#';
|
||||
|
@@ -29,7 +29,7 @@ class LoadMentionedByRelationship
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
||||
return $query
|
||||
->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsPosts.discussion', 'mentionsUsers'])
|
||||
->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsUsers'])
|
||||
->whereVisibleTo($actor)
|
||||
->oldest()
|
||||
// Limiting a relationship results is only possible because
|
||||
@@ -47,19 +47,10 @@ class LoadMentionedByRelationship
|
||||
$loadable = null;
|
||||
|
||||
if ($data instanceof Discussion) {
|
||||
$loadable = $data->newCollection($data->posts)->filter(function ($post) {
|
||||
// @phpstan-ignore-next-line
|
||||
$loadable = $data->newCollection((array) $data->posts)->filter(function ($post) {
|
||||
return $post instanceof Post;
|
||||
});
|
||||
|
||||
// firstPost and lastPost might have been included in the API response,
|
||||
// so we have to make sure counts are also loaded for them.
|
||||
if ($data->firstPost) {
|
||||
$loadable->push($data->firstPost);
|
||||
}
|
||||
|
||||
if ($data->lastPost) {
|
||||
$loadable->push($data->lastPost);
|
||||
}
|
||||
} elseif ($data instanceof Collection) {
|
||||
$loadable = $data;
|
||||
} elseif ($data instanceof Post) {
|
||||
|
0
extensions/mentions/src/FilterVisiblePosts.php
Executable file
0
extensions/mentions/src/FilterVisiblePosts.php
Executable file
@@ -9,8 +9,6 @@
|
||||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\SlugManager;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
@@ -23,15 +21,9 @@ class FormatPostMentions
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var SlugManager
|
||||
*/
|
||||
private $slugManager;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, SlugManager $slugManager)
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->slugManager = $slugManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,12 +56,6 @@ class FormatPostMentions
|
||||
$attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text');
|
||||
}
|
||||
|
||||
if ($post) {
|
||||
$attributes['discussionid'] = $this->slugManager
|
||||
->forResource(Discussion::class)
|
||||
->toSlug($post->discussion);
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
});
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.8"
|
||||
"flarum/core": "^1.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -1,18 +1,5 @@
|
||||
# Package Manager
|
||||
|
||||
The package manager is a tool that allows you to easily install and manage extensions. It runs [composer](https://getcomposer.org/) under the hood.
|
||||
*An Experiment.*
|
||||
|
||||
## Security
|
||||
|
||||
If admin access is given to untrustworthy users, they can install malicious extensions. Please be careful.
|
||||
|
||||
This extension is optional and can be removed for those who prefer to manually manage installs and updates through the command line interface.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you have many extensions installed, you may run into memory issues when using the package manager. If this happens, you can use an asynchronous queue that will run the package manager in the background.
|
||||
|
||||
* Simple database queue guide: https://discuss.flarum.org/d/28151-database-queue-the-simplest-queue-even-for-shared-hosting
|
||||
* (Advanced) Redis queue: https://discuss.flarum.org/d/21873-redis-sessions-cache-queues
|
||||
|
||||
You can find detailed logs on the package manager operations in the `storage/logs/composer` directory. Please include the latest log file when reporting issues in the [Flarum support forum](https://discuss.flarum.org/t/support).
|
||||
Read: https://github.com/flarum/package-manager/wiki
|
||||
|
@@ -22,7 +22,7 @@
|
||||
"source": "https://github.com/flarum/package-manager"
|
||||
},
|
||||
"require": {
|
||||
"flarum/core": "^1.8",
|
||||
"flarum/core": "^1.5.0",
|
||||
"composer/composer": "^2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@@ -12,6 +12,13 @@ namespace Flarum\PackageManager;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Frontend\Document;
|
||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
|
||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use Flarum\PackageManager\Exception\ExceptionHandler;
|
||||
use Flarum\PackageManager\Exception\MajorUpdateFailedException;
|
||||
use Flarum\PackageManager\Settings\LastUpdateCheck;
|
||||
use Flarum\PackageManager\Settings\LastUpdateRun;
|
||||
use Illuminate\Contracts\Queue\Queue;
|
||||
use Illuminate\Queue\SyncQueue;
|
||||
|
||||
@@ -25,8 +32,7 @@ return [
|
||||
->post('/package-manager/minor-update', 'package-manager.minor-update', Api\Controller\MinorUpdateController::class)
|
||||
->post('/package-manager/major-update', 'package-manager.major-update', Api\Controller\MajorUpdateController::class)
|
||||
->post('/package-manager/global-update', 'package-manager.global-update', Api\Controller\GlobalUpdateController::class)
|
||||
->get('/package-manager-tasks', 'package-manager.tasks.index', Api\Controller\ListTasksController::class)
|
||||
->post('/package-manager/composer', 'package-manager.composer', Api\Controller\ConfigureComposerController::class),
|
||||
->get('/package-manager-tasks', 'package-manager.tasks.index', Api\Controller\ListTasksController::class),
|
||||
|
||||
(new Extend\Frontend('admin'))
|
||||
->css(__DIR__.'/less/admin.less')
|
||||
@@ -46,22 +52,19 @@ return [
|
||||
new Extend\Locales(__DIR__.'/locale'),
|
||||
|
||||
(new Extend\Settings())
|
||||
->default(Settings\LastUpdateCheck::key(), json_encode(Settings\LastUpdateCheck::default()))
|
||||
->default(Settings\LastUpdateRun::key(), json_encode(Settings\LastUpdateRun::default()))
|
||||
->default('flarum-package-manager.queue_jobs', false)
|
||||
->default('flarum-package-manager.minimum_stability', 'stable')
|
||||
->default('flarum-package-manager.task_retention_days', 7),
|
||||
->default(LastUpdateCheck::key(), json_encode(LastUpdateCheck::default()))
|
||||
->default(LastUpdateRun::key(), json_encode(LastUpdateRun::default()))
|
||||
->default('flarum-package-manager.queue_jobs', false),
|
||||
|
||||
(new Extend\ServiceProvider)
|
||||
->register(PackageManagerServiceProvider::class),
|
||||
|
||||
(new Extend\ErrorHandling)
|
||||
->handler(Exception\ComposerCommandFailedException::class, Exception\ExceptionHandler::class)
|
||||
->handler(Exception\ComposerRequireFailedException::class, Exception\ExceptionHandler::class)
|
||||
->handler(Exception\ComposerUpdateFailedException::class, Exception\ExceptionHandler::class)
|
||||
->handler(Exception\MajorUpdateFailedException::class, Exception\ExceptionHandler::class)
|
||||
->handler(ComposerCommandFailedException::class, ExceptionHandler::class)
|
||||
->handler(ComposerRequireFailedException::class, ExceptionHandler::class)
|
||||
->handler(ComposerUpdateFailedException::class, ExceptionHandler::class)
|
||||
->handler(MajorUpdateFailedException::class, ExceptionHandler::class)
|
||||
->status('extension_already_installed', 409)
|
||||
->status('extension_not_installed', 409)
|
||||
->status('no_new_major_version', 409)
|
||||
->status('extension_not_directly_dependency', 409),
|
||||
->status('no_new_major_version', 409),
|
||||
];
|
||||
|
19
extensions/package-manager/js/dist-typings/components/AuthMethodModal.d.ts
generated
vendored
19
extensions/package-manager/js/dist-typings/components/AuthMethodModal.d.ts
generated
vendored
@@ -1,19 +0,0 @@
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
import Mithril from 'mithril';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
export interface IAuthMethodModalAttrs extends IInternalModalAttrs {
|
||||
onsubmit: (type: string, host: string, token: string) => void;
|
||||
type?: string;
|
||||
host?: string;
|
||||
token?: string;
|
||||
}
|
||||
export default class AuthMethodModal<CustomAttrs extends IAuthMethodModalAttrs = IAuthMethodModalAttrs> extends Modal<CustomAttrs> {
|
||||
protected type: Stream<string>;
|
||||
protected host: Stream<string>;
|
||||
protected token: Stream<string>;
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>): void;
|
||||
className(): string;
|
||||
title(): Mithril.Children;
|
||||
content(): Mithril.Children;
|
||||
submit(): void;
|
||||
}
|
10
extensions/package-manager/js/dist-typings/components/ConfigureAuth.d.ts
generated
vendored
10
extensions/package-manager/js/dist-typings/components/ConfigureAuth.d.ts
generated
vendored
@@ -1,10 +0,0 @@
|
||||
import type Mithril from 'mithril';
|
||||
import ConfigureJson, { IConfigureJson } from './ConfigureJson';
|
||||
export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {
|
||||
protected type: string;
|
||||
title(): Mithril.Children;
|
||||
className(): string;
|
||||
content(): Mithril.Children;
|
||||
submitButton(): Mithril.Children[];
|
||||
onchange(type: string, host: string, token: string): void;
|
||||
}
|
14
extensions/package-manager/js/dist-typings/components/ConfigureComposer.d.ts
generated
vendored
14
extensions/package-manager/js/dist-typings/components/ConfigureComposer.d.ts
generated
vendored
@@ -1,14 +0,0 @@
|
||||
import type Mithril from 'mithril';
|
||||
import ConfigureJson, { type IConfigureJson } from './ConfigureJson';
|
||||
export declare type Repository = {
|
||||
type: 'composer' | 'vcs' | 'path';
|
||||
url: string;
|
||||
};
|
||||
export default class ConfigureComposer extends ConfigureJson<IConfigureJson> {
|
||||
protected type: string;
|
||||
title(): Mithril.Children;
|
||||
className(): string;
|
||||
content(): Mithril.Children;
|
||||
submitButton(): Mithril.Children[];
|
||||
onchange(repository: Repository, name: string): void;
|
||||
}
|
24
extensions/package-manager/js/dist-typings/components/ConfigureJson.d.ts
generated
vendored
24
extensions/package-manager/js/dist-typings/components/ConfigureJson.d.ts
generated
vendored
@@ -1,24 +0,0 @@
|
||||
import type Mithril from 'mithril';
|
||||
import Component, { type ComponentAttrs } from 'flarum/common/Component';
|
||||
import { CommonSettingsItemOptions, type SettingsComponentOptions } from '@flarum/core/src/admin/components/AdminPage';
|
||||
import type ItemList from 'flarum/common/utils/ItemList';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
export interface IConfigureJson extends ComponentAttrs {
|
||||
buildSettingComponent: (entry: ((this: this) => Mithril.Children) | SettingsComponentOptions) => Mithril.Children;
|
||||
}
|
||||
export default abstract class ConfigureJson<CustomAttrs extends IConfigureJson = IConfigureJson> extends Component<CustomAttrs> {
|
||||
protected settings: Record<string, Stream<any>>;
|
||||
protected initialSettings: Record<string, any> | null;
|
||||
protected loading: boolean;
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>): void;
|
||||
protected abstract type: string;
|
||||
abstract title(): Mithril.Children;
|
||||
abstract content(): Mithril.Children;
|
||||
className(): string;
|
||||
view(): Mithril.Children;
|
||||
submitButton(): Mithril.Children[];
|
||||
customSettingComponents(): ItemList<(attributes: CommonSettingsItemOptions) => Mithril.Children>;
|
||||
setting(key: string): Stream<any>;
|
||||
submit(readOnly: boolean): void;
|
||||
isDirty(): boolean;
|
||||
}
|
5
extensions/package-manager/js/dist-typings/components/ExtensionItem.d.ts
generated
vendored
5
extensions/package-manager/js/dist-typings/components/ExtensionItem.d.ts
generated
vendored
@@ -5,10 +5,7 @@ import { UpdatedPackage } from '../states/ControlSectionState';
|
||||
export interface ExtensionItemAttrs extends ComponentAttrs {
|
||||
extension: Extension;
|
||||
updates: UpdatedPackage;
|
||||
onClickUpdate: CallableFunction | {
|
||||
soft: CallableFunction;
|
||||
hard: CallableFunction;
|
||||
};
|
||||
onClickUpdate: CallableFunction;
|
||||
whyNotWarning?: boolean;
|
||||
isCore?: boolean;
|
||||
updatable?: boolean;
|
||||
|
18
extensions/package-manager/js/dist-typings/components/RepositoryModal.d.ts
generated
vendored
18
extensions/package-manager/js/dist-typings/components/RepositoryModal.d.ts
generated
vendored
@@ -1,18 +0,0 @@
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
import Mithril from 'mithril';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import { type Repository } from './ConfigureComposer';
|
||||
export interface IRepositoryModalAttrs extends IInternalModalAttrs {
|
||||
onsubmit: (repository: Repository, key: string) => void;
|
||||
name?: string;
|
||||
repository?: Repository;
|
||||
}
|
||||
export default class RepositoryModal<CustomAttrs extends IRepositoryModalAttrs = IRepositoryModalAttrs> extends Modal<CustomAttrs> {
|
||||
protected name: Stream<string>;
|
||||
protected repository: Stream<Repository>;
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>): void;
|
||||
className(): string;
|
||||
title(): Mithril.Children;
|
||||
content(): Mithril.Children;
|
||||
submit(): void;
|
||||
}
|
2
extensions/package-manager/js/dist-typings/components/SettingsPage.d.ts
generated
vendored
2
extensions/package-manager/js/dist-typings/components/SettingsPage.d.ts
generated
vendored
@@ -2,7 +2,5 @@ import type Mithril from 'mithril';
|
||||
import ExtensionPage, { ExtensionPageAttrs } from 'flarum/admin/components/ExtensionPage';
|
||||
import ItemList from 'flarum/common/utils/ItemList';
|
||||
export default class SettingsPage extends ExtensionPage {
|
||||
content(): JSX.Element;
|
||||
sections(vnode: Mithril.VnodeDOM<ExtensionPageAttrs, this>): ItemList<unknown>;
|
||||
onsaved(): void;
|
||||
}
|
||||
|
2
extensions/package-manager/js/dist-typings/components/TaskOutputModal.d.ts
generated
vendored
2
extensions/package-manager/js/dist-typings/components/TaskOutputModal.d.ts
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/// <reference types="mithril" />
|
||||
/// <reference types="@flarum/core/dist-typings/@types/translator-icu-rich" />
|
||||
/// <reference types="flarum/@types/translator-icu-rich" />
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
import Task from '../models/Task';
|
||||
interface TaskOutputModalAttrs extends IInternalModalAttrs {
|
||||
|
2
extensions/package-manager/js/dist-typings/components/WhyNotModal.d.ts
generated
vendored
2
extensions/package-manager/js/dist-typings/components/WhyNotModal.d.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
/// <reference types="@flarum/core/dist-typings/@types/translator-icu-rich" />
|
||||
/// <reference types="flarum/@types/translator-icu-rich" />
|
||||
import type Mithril from 'mithril';
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
export interface WhyNotModalAttrs extends IInternalModalAttrs {
|
||||
|
1
extensions/package-manager/js/dist-typings/models/Task.d.ts
generated
vendored
1
extensions/package-manager/js/dist-typings/models/Task.d.ts
generated
vendored
@@ -6,7 +6,6 @@ export default class Task extends Model {
|
||||
command(): string;
|
||||
package(): string;
|
||||
output(): string;
|
||||
guessedCause(): string;
|
||||
createdAt(): Date | null | undefined;
|
||||
startedAt(): Date;
|
||||
finishedAt(): Date;
|
||||
|
11
extensions/package-manager/js/dist-typings/states/ControlSectionState.d.ts
generated
vendored
11
extensions/package-manager/js/dist-typings/states/ControlSectionState.d.ts
generated
vendored
@@ -9,8 +9,6 @@ export declare type UpdatedPackage = {
|
||||
'latest-minor': string | null;
|
||||
'latest-major': string | null;
|
||||
'latest-status': string;
|
||||
'required-as': string;
|
||||
'direct-dependency': boolean;
|
||||
description: string;
|
||||
};
|
||||
export declare type ComposerUpdates = {
|
||||
@@ -33,7 +31,7 @@ export declare type LastUpdateRun = {
|
||||
} & {
|
||||
limitedPackages: () => string[];
|
||||
};
|
||||
export declare type LoadingTypes = UpdaterLoadingTypes | InstallerLoadingTypes | MajorUpdaterLoadingTypes | 'queued-action';
|
||||
export declare type LoadingTypes = UpdaterLoadingTypes | InstallerLoadingTypes | MajorUpdaterLoadingTypes;
|
||||
export declare type CoreUpdate = {
|
||||
package: UpdatedPackage;
|
||||
extension: Extension;
|
||||
@@ -47,16 +45,13 @@ export default class ControlSectionState {
|
||||
get lastUpdateRun(): LastUpdateRun;
|
||||
constructor();
|
||||
isLoading(name?: LoadingTypes): boolean;
|
||||
isLoadingOtherThan(name: LoadingTypes): boolean;
|
||||
setLoading(name: LoadingTypes): void;
|
||||
requirePackage(data: any): void;
|
||||
checkForUpdates(): void;
|
||||
updateCoreMinor(): void;
|
||||
updateExtension(extension: Extension, updateMode: 'soft' | 'hard'): void;
|
||||
updateExtension(extension: Extension): void;
|
||||
updateGlobally(): void;
|
||||
formatExtensionUpdates(lastUpdateCheck: LastUpdateCheck): Extension[];
|
||||
formatCoreUpdate(lastUpdateCheck: LastUpdateCheck): CoreUpdate | null;
|
||||
majorUpdate({ dryRun }: {
|
||||
dryRun: boolean;
|
||||
}): void;
|
||||
}
|
||||
export {};
|
||||
|
4
extensions/package-manager/js/dist-typings/states/QueueState.d.ts
generated
vendored
4
extensions/package-manager/js/dist-typings/states/QueueState.d.ts
generated
vendored
@@ -1,12 +1,11 @@
|
||||
import Task from '../models/Task';
|
||||
import { ApiQueryParamsPlural } from 'flarum/common/Store';
|
||||
export default class QueueState {
|
||||
private polling;
|
||||
private tasks;
|
||||
private limit;
|
||||
private offset;
|
||||
private total;
|
||||
load(params?: ApiQueryParamsPlural, actionTaken?: boolean): Promise<Task[]>;
|
||||
load(params?: ApiQueryParamsPlural): Promise<import("flarum/common/Store").ApiResponsePlural<Task>>;
|
||||
getItems(): Task[] | null;
|
||||
getTotalPages(): number;
|
||||
pageNumber(): number;
|
||||
@@ -14,5 +13,4 @@ export default class QueueState {
|
||||
hasNext(): boolean;
|
||||
prev(): void;
|
||||
next(): void;
|
||||
pollQueue(actionTaken?: boolean): void;
|
||||
}
|
||||
|
2
extensions/package-manager/js/dist/admin.js
generated
vendored
2
extensions/package-manager/js/dist/admin.js
generated
vendored
File diff suppressed because one or more lines are too long
2
extensions/package-manager/js/dist/admin.js.map
generated
vendored
2
extensions/package-manager/js/dist/admin.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -1,88 +0,0 @@
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
import Mithril from 'mithril';
|
||||
import app from 'flarum/admin/app';
|
||||
import Select from 'flarum/common/components/Select';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
|
||||
export interface IAuthMethodModalAttrs extends IInternalModalAttrs {
|
||||
onsubmit: (type: string, host: string, token: string) => void;
|
||||
type?: string;
|
||||
host?: string;
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export default class AuthMethodModal<CustomAttrs extends IAuthMethodModalAttrs = IAuthMethodModalAttrs> extends Modal<CustomAttrs> {
|
||||
protected type!: Stream<string>;
|
||||
protected host!: Stream<string>;
|
||||
protected token!: Stream<string>;
|
||||
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
|
||||
super.oninit(vnode);
|
||||
|
||||
this.type = Stream(this.attrs.type || 'bearer');
|
||||
this.host = Stream(this.attrs.host || '');
|
||||
this.token = Stream(this.attrs.token || '');
|
||||
}
|
||||
|
||||
className(): string {
|
||||
return 'AuthMethodModal Modal--small';
|
||||
}
|
||||
|
||||
title(): Mithril.Children {
|
||||
const context = this.attrs.host ? 'edit' : 'add';
|
||||
return app.translator.trans(`flarum-package-manager.admin.auth_config.${context}_label`);
|
||||
}
|
||||
|
||||
content(): Mithril.Children {
|
||||
const types = {
|
||||
'github-oauth': app.translator.trans('flarum-package-manager.admin.auth_config.types.github-oauth'),
|
||||
'gitlab-oauth': app.translator.trans('flarum-package-manager.admin.auth_config.types.gitlab-oauth'),
|
||||
'gitlab-token': app.translator.trans('flarum-package-manager.admin.auth_config.types.gitlab-token'),
|
||||
bearer: app.translator.trans('flarum-package-manager.admin.auth_config.types.bearer'),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="Modal-body">
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.type_label')}</label>
|
||||
<Select options={types} value={this.type()} onchange={this.type} />
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.host_label')}</label>
|
||||
<input
|
||||
className="FormControl"
|
||||
bidi={this.host}
|
||||
placeholder={app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.host_placeholder')}
|
||||
/>
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.token_label')}</label>
|
||||
<textarea
|
||||
className="FormControl"
|
||||
oninput={(e: InputEvent) => this.token((e.target as HTMLTextAreaElement).value)}
|
||||
rows="6"
|
||||
placeholder={
|
||||
this.token() === '***'
|
||||
? extractText(app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.unchanged_token_placeholder'))
|
||||
: ''
|
||||
}
|
||||
>
|
||||
{this.token() === '***' ? '' : this.token()}
|
||||
</textarea>
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<Button className="Button Button--primary" onclick={this.submit.bind(this)}>
|
||||
{app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.submit_button')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.attrs.onsubmit(this.type(), this.host(), this.token());
|
||||
this.hide();
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
import app from 'flarum/admin/app';
|
||||
import type Mithril from 'mithril';
|
||||
import ConfigureJson, { IConfigureJson } from './ConfigureJson';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import AuthMethodModal from './AuthMethodModal';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
|
||||
export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {
|
||||
protected type = 'auth';
|
||||
|
||||
title(): Mithril.Children {
|
||||
return app.translator.trans('flarum-package-manager.admin.auth_config.title');
|
||||
}
|
||||
|
||||
className(): string {
|
||||
return 'ConfigureAuth';
|
||||
}
|
||||
|
||||
content(): Mithril.Children {
|
||||
const authSettings = Object.keys(this.settings);
|
||||
|
||||
return (
|
||||
<div className="SettingsGroups-content">
|
||||
{authSettings.length ? (
|
||||
authSettings.map((type) => {
|
||||
const hosts = this.settings[type]();
|
||||
|
||||
return (
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans(`flarum-package-manager.admin.auth_config.types.${type}`)}</label>
|
||||
<div className="ConfigureAuth-hosts">
|
||||
{Object.keys(hosts).map((host) => {
|
||||
const data = hosts[host] as string | Record<string, string>;
|
||||
|
||||
return (
|
||||
<div className="ButtonGroup ButtonGroup--full">
|
||||
<Button
|
||||
className="Button"
|
||||
icon="fas fa-key"
|
||||
onclick={() =>
|
||||
app.modal.show(AuthMethodModal, {
|
||||
type,
|
||||
host,
|
||||
token: data,
|
||||
onsubmit: this.onchange.bind(this),
|
||||
})
|
||||
}
|
||||
>
|
||||
{host}
|
||||
</Button>
|
||||
<Button
|
||||
className="Button Button--icon"
|
||||
icon="fas fa-trash"
|
||||
aria-label={app.translator.trans('flarum-package-manager.admin.auth_config.delete_label')}
|
||||
onclick={() => {
|
||||
if (confirm(extractText(app.translator.trans('flarum-package-manager.admin.auth_config.delete_confirmation')))) {
|
||||
const newType = { ...this.setting(type)() };
|
||||
delete newType[host];
|
||||
|
||||
if (Object.keys(newType).length) {
|
||||
this.setting(type)(newType);
|
||||
} else {
|
||||
delete this.settings[type];
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<span className="helpText">{app.translator.trans('flarum-package-manager.admin.auth_config.no_auth_methods_configured')}</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
submitButton(): Mithril.Children[] {
|
||||
const items = super.submitButton();
|
||||
|
||||
items.push(
|
||||
<Button
|
||||
className="Button"
|
||||
loading={this.loading}
|
||||
onclick={() =>
|
||||
app.modal.show(AuthMethodModal, {
|
||||
onsubmit: this.onchange.bind(this),
|
||||
})
|
||||
}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.auth_config.add_label')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
onchange(type: string, host: string, token: string) {
|
||||
this.setting(type)({ ...this.setting(type)(), [host]: token });
|
||||
}
|
||||
}
|
@@ -1,108 +0,0 @@
|
||||
import app from 'flarum/admin/app';
|
||||
import type Mithril from 'mithril';
|
||||
import ConfigureJson, { type IConfigureJson } from './ConfigureJson';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
import RepositoryModal from './RepositoryModal';
|
||||
|
||||
export type Repository = {
|
||||
type: 'composer' | 'vcs' | 'path';
|
||||
url: string;
|
||||
};
|
||||
|
||||
export default class ConfigureComposer extends ConfigureJson<IConfigureJson> {
|
||||
protected type = 'composer';
|
||||
|
||||
title(): Mithril.Children {
|
||||
return app.translator.trans('flarum-package-manager.admin.composer.title');
|
||||
}
|
||||
|
||||
className(): string {
|
||||
return 'ConfigureComposer';
|
||||
}
|
||||
|
||||
content(): Mithril.Children {
|
||||
return (
|
||||
<div className="SettingsGroups-content">
|
||||
{this.attrs.buildSettingComponent.call(this, {
|
||||
setting: 'minimum-stability',
|
||||
label: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.label'),
|
||||
help: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.help'),
|
||||
type: 'select',
|
||||
options: {
|
||||
stable: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.options.stable'),
|
||||
RC: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.options.rc'),
|
||||
beta: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.options.beta'),
|
||||
alpha: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.options.alpha'),
|
||||
dev: app.translator.trans('flarum-package-manager.admin.composer.minimum_stability.options.dev'),
|
||||
},
|
||||
})}
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.composer.repositories.label')}</label>
|
||||
<div className="helpText">{app.translator.trans('flarum-package-manager.admin.composer.repositories.help')}</div>
|
||||
<div className="ConfigureComposer-repositories">
|
||||
{Object.keys(this.setting('repositories')() || {}).map((name) => {
|
||||
const repository = this.setting('repositories')()[name] as Repository;
|
||||
|
||||
return (
|
||||
<div className="ButtonGroup ButtonGroup--full">
|
||||
<Button
|
||||
className="Button"
|
||||
icon={
|
||||
{
|
||||
composer: 'fas fa-cubes',
|
||||
vcs: 'fas fa-code-branch',
|
||||
path: 'fas fa-folder',
|
||||
}[repository.type]
|
||||
}
|
||||
onclick={() =>
|
||||
app.modal.show(RepositoryModal, {
|
||||
name,
|
||||
repository,
|
||||
onsubmit: this.onchange.bind(this),
|
||||
})
|
||||
}
|
||||
>
|
||||
{name} ({repository.type})
|
||||
</Button>
|
||||
<Button
|
||||
className="Button Button--icon"
|
||||
icon="fas fa-trash"
|
||||
aria-label={app.translator.trans('flarum-package-manager.admin.composer.delete_repository_label')}
|
||||
onclick={() => {
|
||||
if (confirm(extractText(app.translator.trans('flarum-package-manager.admin.composer.delete_repository_confirmation')))) {
|
||||
const repositories = { ...this.setting('repositories')() };
|
||||
delete repositories[name];
|
||||
|
||||
this.setting('repositories')(repositories);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
submitButton(): Mithril.Children[] {
|
||||
const items = super.submitButton();
|
||||
|
||||
items.push(
|
||||
<Button className="Button" onclick={() => app.modal.show(RepositoryModal, { onsubmit: this.onchange.bind(this) })}>
|
||||
{app.translator.trans('flarum-package-manager.admin.composer.add_repository_label')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
onchange(repository: Repository, name: string) {
|
||||
this.setting('repositories')({
|
||||
...this.setting('repositories')(),
|
||||
[name]: repository,
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
import app from 'flarum/admin/app';
|
||||
import type Mithril from 'mithril';
|
||||
import Component, { type ComponentAttrs } from 'flarum/common/Component';
|
||||
import { CommonSettingsItemOptions, type SettingsComponentOptions } from '@flarum/core/src/admin/components/AdminPage';
|
||||
import AdminPage from 'flarum/admin/components/AdminPage';
|
||||
import type ItemList from 'flarum/common/utils/ItemList';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import classList from 'flarum/common/utils/classList';
|
||||
|
||||
export interface IConfigureJson extends ComponentAttrs {
|
||||
buildSettingComponent: (entry: ((this: this) => Mithril.Children) | SettingsComponentOptions) => Mithril.Children;
|
||||
}
|
||||
|
||||
export default abstract class ConfigureJson<CustomAttrs extends IConfigureJson = IConfigureJson> extends Component<CustomAttrs> {
|
||||
protected settings: Record<string, Stream<any>> = {};
|
||||
protected initialSettings: Record<string, any> | null = null;
|
||||
protected loading: boolean = false;
|
||||
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
|
||||
super.oninit(vnode);
|
||||
|
||||
this.submit(true);
|
||||
}
|
||||
|
||||
protected abstract type: string;
|
||||
abstract title(): Mithril.Children;
|
||||
abstract content(): Mithril.Children;
|
||||
|
||||
className(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
view(): Mithril.Children {
|
||||
return (
|
||||
<div className={classList('Form', this.className())}>
|
||||
<label>{this.title()}</label>
|
||||
{this.content()}
|
||||
<div className="Form-group Form--controls">{this.submitButton()}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
submitButton(): Mithril.Children[] {
|
||||
return [
|
||||
<Button className="Button Button--primary" loading={this.loading} onclick={() => this.submit(false)} disabled={!this.isDirty()}>
|
||||
{app.translator.trans('core.admin.settings.submit_button')}
|
||||
</Button>,
|
||||
];
|
||||
}
|
||||
|
||||
customSettingComponents(): ItemList<(attributes: CommonSettingsItemOptions) => Mithril.Children> {
|
||||
return AdminPage.prototype.customSettingComponents();
|
||||
}
|
||||
|
||||
setting(key: string) {
|
||||
return this.settings[key] ?? (this.settings[key] = Stream());
|
||||
}
|
||||
|
||||
submit(readOnly: boolean) {
|
||||
this.loading = true;
|
||||
|
||||
const configuration: any = {};
|
||||
|
||||
Object.keys(this.settings).forEach((key) => {
|
||||
configuration[key] = this.settings[key]();
|
||||
});
|
||||
|
||||
app
|
||||
.request({
|
||||
method: 'POST',
|
||||
url: app.forum.attribute('apiUrl') + '/package-manager/composer',
|
||||
body: {
|
||||
type: this.type,
|
||||
data: readOnly ? null : configuration,
|
||||
},
|
||||
})
|
||||
.then(({ data }: any) => {
|
||||
Object.keys(data).forEach((key) => {
|
||||
this.settings[key] = Stream(data[key]);
|
||||
});
|
||||
|
||||
this.initialSettings = Array.isArray(data) ? {} : data;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
|
||||
isDirty() {
|
||||
return JSON.stringify(this.initialSettings) !== JSON.stringify(this.settings);
|
||||
}
|
||||
}
|
@@ -10,17 +10,11 @@ import { Extension } from 'flarum/admin/AdminApplication';
|
||||
import { UpdatedPackage } from '../states/ControlSectionState';
|
||||
import WhyNotModal from './WhyNotModal';
|
||||
import Label from './Label';
|
||||
import Dropdown from 'flarum/common/components/Dropdown';
|
||||
|
||||
export interface ExtensionItemAttrs extends ComponentAttrs {
|
||||
extension: Extension;
|
||||
updates: UpdatedPackage;
|
||||
onClickUpdate:
|
||||
| CallableFunction
|
||||
| {
|
||||
soft: CallableFunction;
|
||||
hard: CallableFunction;
|
||||
};
|
||||
onClickUpdate: CallableFunction;
|
||||
whyNotWarning?: boolean;
|
||||
isCore?: boolean;
|
||||
updatable?: boolean;
|
||||
@@ -55,7 +49,7 @@ export default class ExtensionItem<Attrs extends ExtensionItemAttrs = ExtensionI
|
||||
</div>
|
||||
</div>
|
||||
<div className="PackageManager-extension-controls">
|
||||
{onClickUpdate && typeof onClickUpdate === 'function' ? (
|
||||
{onClickUpdate ? (
|
||||
<Tooltip text={app.translator.trans('flarum-package-manager.admin.extensions.update')}>
|
||||
<Button
|
||||
icon="fas fa-arrow-alt-circle-up"
|
||||
@@ -64,19 +58,6 @@ export default class ExtensionItem<Attrs extends ExtensionItemAttrs = ExtensionI
|
||||
aria-label={app.translator.trans('flarum-package-manager.admin.extensions.update')}
|
||||
/>
|
||||
</Tooltip>
|
||||
) : onClickUpdate ? (
|
||||
<Dropdown
|
||||
buttonClassName="Button Button--icon Button--flat"
|
||||
icon="fas fa-arrow-alt-circle-up"
|
||||
label={app.translator.trans('flarum-package-manager.admin.extensions.update')}
|
||||
>
|
||||
<Button icon="fas fa-arrow-alt-circle-up" className="Button" onclick={onClickUpdate.soft}>
|
||||
{app.translator.trans('flarum-package-manager.admin.extensions.update_soft_label')}
|
||||
</Button>
|
||||
<Button icon="fas fa-arrow-alt-circle-up" className="Button" onclick={onClickUpdate.hard} disabled={!updates['direct-dependency']}>
|
||||
{app.translator.trans('flarum-package-manager.admin.extensions.update_hard_label')}
|
||||
</Button>
|
||||
</Dropdown>
|
||||
) : null}
|
||||
{whyNotWarning ? (
|
||||
<Tooltip text={app.translator.trans('flarum-package-manager.admin.extensions.check_why_it_failed_updating')}>
|
||||
@@ -94,6 +75,6 @@ export default class ExtensionItem<Attrs extends ExtensionItemAttrs = ExtensionI
|
||||
}
|
||||
|
||||
version(v: string): string {
|
||||
return v.charAt(0) === 'v' ? v.substring(1) : v;
|
||||
return 'v' + v.replace('v', '');
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,11 @@ import app from 'flarum/admin/app';
|
||||
import Component, { ComponentAttrs } from 'flarum/common/Component';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import LoadingModal from 'flarum/admin/components/LoadingModal';
|
||||
|
||||
import errorHandler from '../utils/errorHandler';
|
||||
import jumpToQueue from '../utils/jumpToQueue';
|
||||
import { AsyncBackendResponse } from '../shims';
|
||||
|
||||
export interface InstallerAttrs extends ComponentAttrs {}
|
||||
|
||||
@@ -24,8 +29,6 @@ export default class Installer extends Component<InstallerAttrs> {
|
||||
<p className="helpText">
|
||||
{app.translator.trans('flarum-package-manager.admin.extensions.install_help', {
|
||||
extiverse: <a href="https://extiverse.com">extiverse.com</a>,
|
||||
semantic_link: <a href="https://devhints.io/semver" />,
|
||||
code: <code />,
|
||||
})}
|
||||
</p>
|
||||
<div className="FormControl-container">
|
||||
@@ -35,7 +38,7 @@ export default class Installer extends Component<InstallerAttrs> {
|
||||
icon="fas fa-download"
|
||||
onclick={this.onsubmit.bind(this)}
|
||||
loading={app.packageManager.control.isLoading('extension-install')}
|
||||
disabled={app.packageManager.control.isLoading()}
|
||||
disabled={app.packageManager.control.isLoadingOtherThan('extension-install')}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.extensions.proceed')}
|
||||
</Button>
|
||||
@@ -51,6 +54,35 @@ export default class Installer extends Component<InstallerAttrs> {
|
||||
}
|
||||
|
||||
onsubmit(): void {
|
||||
app.packageManager.control.requirePackage(this.data());
|
||||
app.packageManager.control.setLoading('extension-install');
|
||||
app.modal.show(LoadingModal);
|
||||
|
||||
app
|
||||
.request<AsyncBackendResponse & { id: number }>({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/extensions`,
|
||||
body: {
|
||||
data: this.data(),
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.processing) {
|
||||
jumpToQueue();
|
||||
} else {
|
||||
const extensionId = response.id;
|
||||
app.alerts.show(
|
||||
{ type: 'success' },
|
||||
app.translator.trans('flarum-package-manager.admin.extensions.successful_install', { extension: extensionId })
|
||||
);
|
||||
window.location.href = `${app.forum.attribute('adminUrl')}#/extension/${extensionId}`;
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
app.packageManager.control.setLoading(null);
|
||||
app.modal.close();
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -3,12 +3,16 @@ import app from 'flarum/admin/app';
|
||||
import Component, { ComponentAttrs } from 'flarum/common/Component';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import Tooltip from 'flarum/common/components/Tooltip';
|
||||
import LoadingModal from 'flarum/admin/components/LoadingModal';
|
||||
import Alert from 'flarum/common/components/Alert';
|
||||
import RequestError from 'flarum/common/utils/RequestError';
|
||||
|
||||
import { UpdatedPackage, UpdateState } from '../states/ControlSectionState';
|
||||
import errorHandler from '../utils/errorHandler';
|
||||
import WhyNotModal from './WhyNotModal';
|
||||
import ExtensionItem from './ExtensionItem';
|
||||
import classList from 'flarum/common/utils/classList';
|
||||
import { AsyncBackendResponse } from '../shims';
|
||||
import jumpToQueue from '../utils/jumpToQueue';
|
||||
|
||||
export interface MajorUpdaterAttrs extends ComponentAttrs {
|
||||
coreUpdate: UpdatedPackage;
|
||||
@@ -29,18 +33,18 @@ export default class MajorUpdater<T extends MajorUpdaterAttrs = MajorUpdaterAttr
|
||||
view(): Mithril.Children {
|
||||
// @todo move Form-group--danger class to core for reuse
|
||||
return (
|
||||
<div
|
||||
className={classList('Form-group Form-group--danger PackageManager-majorUpdate', {
|
||||
'PackageManager-majorUpdate--failed': this.updateState.status === 'failure',
|
||||
'PackageManager-majorUpdate--incompatibleExtensions': this.updateState.incompatibleExtensions.length,
|
||||
})}
|
||||
>
|
||||
<div className="Form-group Form-group--danger PackageManager-majorUpdate">
|
||||
<img alt="flarum logo" src={app.forum.attribute('baseUrl') + '/assets/extensions/flarum-package-manager/flarum.svg'} />
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.major_updater.title', { version: this.attrs.coreUpdate['latest-major'] })}</label>
|
||||
<p className="helpText">{app.translator.trans('flarum-package-manager.admin.major_updater.description')}</p>
|
||||
<div className="PackageManager-updaterControls">
|
||||
<Tooltip text={app.translator.trans('flarum-package-manager.admin.major_updater.dry_run_help')}>
|
||||
<Button className="Button" icon="fas fa-vial" onclick={this.update.bind(this, true)} disabled={app.packageManager.control.isLoading()}>
|
||||
<Button
|
||||
className="Button"
|
||||
icon="fas fa-vial"
|
||||
onclick={this.update.bind(this, true)}
|
||||
disabled={app.packageManager.control.isLoadingOtherThan('major-update-dry-run')}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.major_updater.dry_run')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
@@ -48,7 +52,7 @@ export default class MajorUpdater<T extends MajorUpdaterAttrs = MajorUpdaterAttr
|
||||
className="Button Button--danger"
|
||||
icon="fas fa-play"
|
||||
onclick={this.update.bind(this, false)}
|
||||
disabled={app.packageManager.control.isLoading()}
|
||||
disabled={app.packageManager.control.isLoadingOtherThan('major-update')}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.major_updater.update')}
|
||||
</Button>
|
||||
@@ -90,6 +94,34 @@ export default class MajorUpdater<T extends MajorUpdaterAttrs = MajorUpdaterAttr
|
||||
}
|
||||
|
||||
update(dryRun: boolean) {
|
||||
app.packageManager.control.majorUpdate({ dryRun });
|
||||
app.packageManager.control.setLoading(dryRun ? 'major-update-dry-run' : 'major-update');
|
||||
app.modal.show(LoadingModal);
|
||||
|
||||
app
|
||||
.request<AsyncBackendResponse | null>({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/major-update`,
|
||||
body: {
|
||||
data: { dryRun },
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response?.processing) {
|
||||
jumpToQueue();
|
||||
} else {
|
||||
app.alerts.show({ type: 'success' }, app.translator.trans('flarum-package-manager.admin.update_successful'));
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.catch((e: RequestError) => {
|
||||
app.modal.close();
|
||||
this.updateState.status = 'failure';
|
||||
this.updateState.incompatibleExtensions = e.response?.errors?.pop()?.incompatible_extensions as string[];
|
||||
})
|
||||
.finally(() => {
|
||||
app.packageManager.control.setLoading(null);
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import { Extension } from 'flarum/admin/AdminApplication';
|
||||
import icon from 'flarum/common/helpers/icon';
|
||||
import ItemList from 'flarum/common/utils/ItemList';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
import Link from 'flarum/common/components/Link';
|
||||
|
||||
import Label from './Label';
|
||||
import TaskOutputModal from './TaskOutputModal';
|
||||
@@ -74,7 +73,7 @@ export default class QueueSection extends Component<{}> {
|
||||
const extension: Extension | null = app.data.extensions[task.package()?.replace(/(\/flarum-|\/flarum-ext-|\/)/g, '-')];
|
||||
|
||||
return extension ? (
|
||||
<Link className="PackageManager-queueTable-package" href={app.route('extension', { id: extension.id })}>
|
||||
<div className="PackageManager-queueTable-package">
|
||||
<div className="PackageManager-queueTable-package-icon ExtensionIcon" style={extension.icon}>
|
||||
{!!extension.icon && icon(extension.icon.name)}
|
||||
</div>
|
||||
@@ -82,7 +81,7 @@ export default class QueueSection extends Component<{}> {
|
||||
<span className="PackageManager-queueTable-package-title">{extension.extra['flarum-extension'].title}</span>
|
||||
<span className="PackageManager-queueTable-package-name">{task.package()}</span>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
task.package()
|
||||
);
|
||||
@@ -96,15 +95,12 @@ export default class QueueSection extends Component<{}> {
|
||||
{
|
||||
label: extractText(app.translator.trans('flarum-package-manager.admin.sections.queue.columns.status')),
|
||||
content: (task) => (
|
||||
<>
|
||||
<Label
|
||||
className="PackageManager-queueTable-status"
|
||||
type={{ running: 'neutral', failure: 'error', pending: 'warning', success: 'success' }[task.status()]}
|
||||
>
|
||||
{app.translator.trans(`flarum-package-manager.admin.sections.queue.statuses.${task.status()}`)}
|
||||
</Label>
|
||||
{['pending', 'running'].includes(task.status()) && <LoadingIndicator size="small" display="inline" />}
|
||||
</>
|
||||
<Label
|
||||
className="PackageManager-queueTable-status"
|
||||
type={{ running: 'neutral', failure: 'error', pending: 'warning', success: 'success' }[task.status()]}
|
||||
>
|
||||
{app.translator.trans(`flarum-package-manager.admin.sections.queue.statuses.${task.status()}`)}
|
||||
</Label>
|
||||
),
|
||||
},
|
||||
70
|
||||
@@ -115,7 +111,7 @@ export default class QueueSection extends Component<{}> {
|
||||
{
|
||||
label: extractText(app.translator.trans('flarum-package-manager.admin.sections.queue.columns.elapsed_time')),
|
||||
content: (task) =>
|
||||
!task.startedAt() || !task.finishedAt() ? (
|
||||
!task.startedAt() ? (
|
||||
app.translator.trans('flarum-package-manager.admin.sections.queue.task_just_started')
|
||||
) : (
|
||||
<Tooltip text={`${dayjs(task.startedAt()).format('LL LTS')} ${dayjs(task.finishedAt()).format('LL LTS')}`}>
|
||||
|
@@ -1,77 +0,0 @@
|
||||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal';
|
||||
import Mithril from 'mithril';
|
||||
import app from 'flarum/admin/app';
|
||||
import Select from 'flarum/common/components/Select';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import { type Repository } from './ConfigureComposer';
|
||||
|
||||
export interface IRepositoryModalAttrs extends IInternalModalAttrs {
|
||||
onsubmit: (repository: Repository, key: string) => void;
|
||||
name?: string;
|
||||
repository?: Repository;
|
||||
}
|
||||
|
||||
export default class RepositoryModal<CustomAttrs extends IRepositoryModalAttrs = IRepositoryModalAttrs> extends Modal<CustomAttrs> {
|
||||
protected name!: Stream<string>;
|
||||
protected repository!: Stream<Repository>;
|
||||
|
||||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
|
||||
super.oninit(vnode);
|
||||
|
||||
this.name = Stream(this.attrs.name || '');
|
||||
this.repository = Stream(this.attrs.repository || { type: 'composer', url: '' });
|
||||
}
|
||||
|
||||
className(): string {
|
||||
return 'RepositoryModal Modal--small';
|
||||
}
|
||||
|
||||
title(): Mithril.Children {
|
||||
const context = this.attrs.repository ? 'edit' : 'add';
|
||||
return app.translator.trans(`flarum-package-manager.admin.composer.${context}_repository_label`);
|
||||
}
|
||||
|
||||
content(): Mithril.Children {
|
||||
const types = {
|
||||
composer: app.translator.trans('flarum-package-manager.admin.composer.repositories.types.composer'),
|
||||
vcs: app.translator.trans('flarum-package-manager.admin.composer.repositories.types.vcs'),
|
||||
path: app.translator.trans('flarum-package-manager.admin.composer.repositories.types.path'),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="Modal-body">
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.composer.repositories.add_modal.name_label')}</label>
|
||||
<input className="FormControl" bidi={this.name} />
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.composer.repositories.add_modal.type_label')}</label>
|
||||
<Select
|
||||
options={types}
|
||||
value={this.repository().type}
|
||||
onchange={(value: 'composer' | 'vcs' | 'path') => this.repository({ ...this.repository(), type: value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.composer.repositories.add_modal.url')}</label>
|
||||
<input
|
||||
className="FormControl"
|
||||
onchange={(e: Event) => this.repository({ ...this.repository(), url: (e.target as HTMLInputElement).value })}
|
||||
value={this.repository().url}
|
||||
/>
|
||||
</div>
|
||||
<div className="Form-group">
|
||||
<Button className="Button Button--primary" onclick={this.submit.bind(this)}>
|
||||
{app.translator.trans('flarum-package-manager.admin.composer.repositories.add_modal.submit_button')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.attrs.onsubmit(this.repository(), this.name());
|
||||
this.hide();
|
||||
}
|
||||
}
|
@@ -5,45 +5,8 @@ import ItemList from 'flarum/common/utils/ItemList';
|
||||
|
||||
import QueueSection from './QueueSection';
|
||||
import ControlSection from './ControlSection';
|
||||
import ConfigureComposer from './ConfigureComposer';
|
||||
import Alert from 'flarum/common/components/Alert';
|
||||
import listItems from 'flarum/common/helpers/listItems';
|
||||
import ConfigureAuth from './ConfigureAuth';
|
||||
|
||||
export default class SettingsPage extends ExtensionPage {
|
||||
content() {
|
||||
const settings = app.extensionData.getSettings(this.extension.id);
|
||||
|
||||
const warnings = [app.translator.trans('flarum-package-manager.admin.settings.access_warning')];
|
||||
|
||||
if (app.data.debugEnabled) warnings.push(app.translator.trans('flarum-package-manager.admin.settings.debug_mode_warning'));
|
||||
|
||||
return (
|
||||
<div className="ExtensionPage-settings">
|
||||
<div className="container">
|
||||
<div className="Form-group">
|
||||
<Alert className="PackageManager-primaryWarning" type="warning" dismissible={false}>
|
||||
<ul>{listItems(warnings)}</ul>
|
||||
</Alert>
|
||||
</div>
|
||||
{settings ? (
|
||||
<div className="SettingsGroups">
|
||||
<div className="Form">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.settings.title')}</label>
|
||||
<div className="SettingsGroups-content">{settings.map(this.buildSettingComponent.bind(this))}</div>
|
||||
<div className="Form-group Form--controls">{this.submitButton()}</div>
|
||||
</div>
|
||||
<ConfigureComposer buildSettingComponent={this.buildSettingComponent} />
|
||||
<ConfigureAuth buildSettingComponent={this.buildSettingComponent} />
|
||||
</div>
|
||||
) : (
|
||||
<h3 className="ExtensionPage-subHeader">{app.translator.trans('core.admin.extension.no_settings')}</h3>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
sections(vnode: Mithril.VnodeDOM<ExtensionPageAttrs, this>): ItemList<unknown> {
|
||||
const items = super.sections(vnode);
|
||||
|
||||
@@ -51,17 +14,12 @@ export default class SettingsPage extends ExtensionPage {
|
||||
|
||||
items.add('control', <ControlSection />, 8);
|
||||
|
||||
if (app.data.settings['flarum-package-manager.queue_jobs'] !== '0' && app.data.settings['flarum-package-manager.queue_jobs']) {
|
||||
if (parseInt(app.data.settings['flarum-package-manager.queue_jobs'])) {
|
||||
items.add('queue', <QueueSection />, 5);
|
||||
}
|
||||
|
||||
items.remove('permissions');
|
||||
items.setPriority('permissions', 0);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
onsaved() {
|
||||
super.onsaved();
|
||||
m.redraw();
|
||||
}
|
||||
}
|
||||
|
@@ -19,22 +19,12 @@ export default class TaskOutputModal<CustomAttrs extends TaskOutputModalAttrs =
|
||||
return (
|
||||
<div className="Modal-body">
|
||||
<div className="TaskOutputModal-data">
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.guessed_cause')}</label>
|
||||
<div className="FormControl TaskOutputModal-data-guessed-cause">
|
||||
{(this.attrs.task.guessedCause() &&
|
||||
app.translator.trans('flarum-package-manager.admin.exceptions.guessed_cause.' + this.attrs.task.guessedCause())) ||
|
||||
app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.cause_unknown')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.command')}</label>
|
||||
<div className="FormControl TaskOutputModal-data-command">
|
||||
<code>$ composer {this.attrs.task.command()}</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="Form-group">
|
||||
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.output')}</label>
|
||||
<div className="FormControl TaskOutputModal-data-output">
|
||||
|
@@ -6,6 +6,7 @@ import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
|
||||
import MajorUpdater from './MajorUpdater';
|
||||
import ExtensionItem from './ExtensionItem';
|
||||
import { Extension } from 'flarum/admin/AdminApplication';
|
||||
import Alert from 'flarum/common/components/Alert';
|
||||
import ItemList from 'flarum/common/utils/ItemList';
|
||||
|
||||
export interface IUpdaterAttrs extends ComponentAttrs {}
|
||||
@@ -47,7 +48,7 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
availableUpdatesView() {
|
||||
const state = app.packageManager.control;
|
||||
|
||||
if (app.packageManager.control.isLoading('check') || app.packageManager.control.isLoading('global-update')) {
|
||||
if (app.packageManager.control.isLoading()) {
|
||||
return (
|
||||
<div className="PackageManager-extensions">
|
||||
<LoadingIndicator />
|
||||
@@ -55,12 +56,12 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
);
|
||||
}
|
||||
|
||||
const hasMinorCoreUpdate = state.coreUpdate && state.coreUpdate.package['latest-minor'];
|
||||
|
||||
if (!(state.extensionUpdates.length || hasMinorCoreUpdate)) {
|
||||
if (!(state.extensionUpdates.length || state.coreUpdate)) {
|
||||
return (
|
||||
<div className="PackageManager-extensions">
|
||||
<span className="helpText">{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}</span>
|
||||
<Alert type="success" dismissible={false}>
|
||||
{app.translator.trans('flarum-package-manager.admin.updater.up_to_date')}
|
||||
</Alert>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -68,10 +69,10 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
return (
|
||||
<div className="PackageManager-extensions">
|
||||
<div className="PackageManager-extensions-grid">
|
||||
{hasMinorCoreUpdate ? (
|
||||
{state.coreUpdate ? (
|
||||
<ExtensionItem
|
||||
extension={state.coreUpdate!.extension}
|
||||
updates={state.coreUpdate!.package}
|
||||
extension={state.coreUpdate.extension}
|
||||
updates={state.coreUpdate.package}
|
||||
isCore={true}
|
||||
onClickUpdate={() => state.updateCoreMinor()}
|
||||
whyNotWarning={state.lastUpdateRun.limitedPackages().includes('flarum/core')}
|
||||
@@ -81,10 +82,7 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
<ExtensionItem
|
||||
extension={extension}
|
||||
updates={state.packageUpdates[extension.id]}
|
||||
onClickUpdate={{
|
||||
soft: () => state.updateExtension(extension, 'soft'),
|
||||
hard: () => state.updateExtension(extension, 'hard'),
|
||||
}}
|
||||
onClickUpdate={() => state.updateExtension(extension)}
|
||||
whyNotWarning={state.lastUpdateRun.limitedPackages().includes(extension.name)}
|
||||
/>
|
||||
))}
|
||||
@@ -103,7 +101,7 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
icon="fas fa-sync-alt"
|
||||
onclick={() => app.packageManager.control.checkForUpdates()}
|
||||
loading={app.packageManager.control.isLoading('check')}
|
||||
disabled={app.packageManager.control.isLoading()}
|
||||
disabled={app.packageManager.control.isLoadingOtherThan('check')}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.updater.check_for_updates')}
|
||||
</Button>,
|
||||
@@ -117,7 +115,7 @@ export default class Updater extends Component<IUpdaterAttrs> {
|
||||
icon="fas fa-play"
|
||||
onclick={() => app.packageManager.control.updateGlobally()}
|
||||
loading={app.packageManager.control.isLoading('global-update')}
|
||||
disabled={app.packageManager.control.isLoading()}
|
||||
disabled={app.packageManager.control.isLoadingOtherThan('global-update')}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.updater.run_global_update')}
|
||||
</Button>
|
||||
|
@@ -18,12 +18,15 @@ app.initializers.add('flarum-package-manager', (app) => {
|
||||
|
||||
app.packageManager = new PackageManagerState();
|
||||
|
||||
if (app.data['flarum-package-manager.using_sync_queue']) {
|
||||
app.data.settings['flarum-package-manager.queue_jobs'] = '0';
|
||||
}
|
||||
|
||||
app.extensionData
|
||||
.for('flarum-package-manager')
|
||||
.registerSetting(() => (
|
||||
<div className="Form-group">
|
||||
<Alert type="warning" dismissible={false}>
|
||||
{app.translator.trans('flarum-package-manager.admin.settings.access_warning')}
|
||||
</Alert>
|
||||
</div>
|
||||
))
|
||||
.registerSetting({
|
||||
setting: 'flarum-package-manager.queue_jobs',
|
||||
label: app.translator.trans('flarum-package-manager.admin.settings.queue_jobs'),
|
||||
@@ -37,15 +40,10 @@ app.initializers.add('flarum-package-manager', (app) => {
|
||||
})
|
||||
)
|
||||
),
|
||||
default: false,
|
||||
type: 'boolean',
|
||||
disabled: app.data['flarum-package-manager.using_sync_queue'],
|
||||
})
|
||||
.registerSetting({
|
||||
setting: 'flarum-package-manager.task_retention_days',
|
||||
label: app.translator.trans('flarum-package-manager.admin.settings.task_retention_days'),
|
||||
help: app.translator.trans('flarum-package-manager.admin.settings.task_retention_days_help'),
|
||||
type: 'number',
|
||||
})
|
||||
.registerPage(SettingsPage);
|
||||
|
||||
extend(ExtensionPage.prototype, 'topItems', function (items) {
|
||||
@@ -79,7 +77,7 @@ app.initializers.add('flarum-package-manager', (app) => {
|
||||
});
|
||||
}}
|
||||
>
|
||||
{app.translator.trans('flarum-package-manager.admin.extensions.remove')}
|
||||
Remove
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
|
@@ -32,10 +32,6 @@ export default class Task extends Model {
|
||||
return Model.attribute<string>('output').call(this);
|
||||
}
|
||||
|
||||
guessedCause() {
|
||||
return Model.attribute<string>('guessedCause').call(this);
|
||||
}
|
||||
|
||||
createdAt() {
|
||||
return Model.attribute('createdAt', Model.transformDate).call(this);
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import 'dayjs/plugin/relativeTime';
|
||||
import PackageManagerState from './states/PackageManagerState';
|
||||
|
||||
export interface AsyncBackendResponse {
|
||||
|
@@ -8,7 +8,6 @@ import errorHandler from '../utils/errorHandler';
|
||||
import jumpToQueue from '../utils/jumpToQueue';
|
||||
import { Extension } from 'flarum/admin/AdminApplication';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
import RequestError from 'flarum/common/utils/RequestError';
|
||||
|
||||
export type UpdatedPackage = {
|
||||
name: string;
|
||||
@@ -17,8 +16,6 @@ export type UpdatedPackage = {
|
||||
'latest-minor': string | null;
|
||||
'latest-major': string | null;
|
||||
'latest-status': string;
|
||||
'required-as': string;
|
||||
'direct-dependency': boolean;
|
||||
description: string;
|
||||
};
|
||||
|
||||
@@ -46,7 +43,7 @@ export type LastUpdateRun = {
|
||||
limitedPackages: () => string[];
|
||||
};
|
||||
|
||||
export type LoadingTypes = UpdaterLoadingTypes | InstallerLoadingTypes | MajorUpdaterLoadingTypes | 'queued-action';
|
||||
export type LoadingTypes = UpdaterLoadingTypes | InstallerLoadingTypes | MajorUpdaterLoadingTypes;
|
||||
|
||||
export type CoreUpdate = {
|
||||
package: UpdatedPackage;
|
||||
@@ -82,40 +79,12 @@ export default class ControlSectionState {
|
||||
return (name && this.loading === name) || (!name && this.loading !== null);
|
||||
}
|
||||
|
||||
setLoading(name: LoadingTypes): void {
|
||||
this.loading = name;
|
||||
isLoadingOtherThan(name: LoadingTypes): boolean {
|
||||
return this.loading !== null && this.loading !== name;
|
||||
}
|
||||
|
||||
requirePackage(data: any) {
|
||||
app.packageManager.control.setLoading('extension-install');
|
||||
app.modal.show(LoadingModal);
|
||||
|
||||
app
|
||||
.request<AsyncBackendResponse & { id: number }>({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/extensions`,
|
||||
body: {
|
||||
data,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.processing) {
|
||||
jumpToQueue();
|
||||
} else {
|
||||
const extensionId = response.id;
|
||||
app.alerts.show(
|
||||
{ type: 'success' },
|
||||
app.translator.trans('flarum-package-manager.admin.extensions.successful_install', { extension: extensionId })
|
||||
);
|
||||
window.location.href = `${app.forum.attribute('adminUrl')}#/extension/${extensionId}`;
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
app.modal.close();
|
||||
m.redraw();
|
||||
});
|
||||
setLoading(name: LoadingTypes): void {
|
||||
this.loading = name;
|
||||
}
|
||||
|
||||
checkForUpdates() {
|
||||
@@ -133,12 +102,12 @@ export default class ControlSectionState {
|
||||
this.lastUpdateCheck = response as LastUpdateCheck;
|
||||
this.extensionUpdates = this.formatExtensionUpdates(response as LastUpdateCheck);
|
||||
this.coreUpdate = this.formatCoreUpdate(response as LastUpdateCheck);
|
||||
this.setLoading(null);
|
||||
m.redraw();
|
||||
}
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
this.setLoading(null);
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
@@ -163,13 +132,14 @@ export default class ControlSectionState {
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
this.setLoading(null);
|
||||
app.modal.close();
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateExtension(extension: Extension, updateMode: 'soft' | 'hard') {
|
||||
updateExtension(extension: Extension) {
|
||||
app.modal.show(LoadingModal);
|
||||
this.setLoading('extension-update');
|
||||
|
||||
@@ -177,11 +147,6 @@ export default class ControlSectionState {
|
||||
.request<AsyncBackendResponse | null>({
|
||||
method: 'PATCH',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/extensions/${extension.id}`,
|
||||
body: {
|
||||
data: {
|
||||
updateMode,
|
||||
},
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response?.processing) {
|
||||
@@ -198,6 +163,7 @@ export default class ControlSectionState {
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
this.setLoading(null);
|
||||
app.modal.close();
|
||||
m.redraw();
|
||||
});
|
||||
@@ -222,6 +188,7 @@ export default class ControlSectionState {
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.finally(() => {
|
||||
this.setLoading(null);
|
||||
app.modal.close();
|
||||
m.redraw();
|
||||
});
|
||||
@@ -269,36 +236,4 @@ export default class ControlSectionState {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
majorUpdate({ dryRun }: { dryRun: boolean }) {
|
||||
app.packageManager.control.setLoading(dryRun ? 'major-update-dry-run' : 'major-update');
|
||||
app.modal.show(LoadingModal);
|
||||
const updateState = this.lastUpdateRun.major;
|
||||
|
||||
app
|
||||
.request<AsyncBackendResponse | null>({
|
||||
method: 'POST',
|
||||
url: `${app.forum.attribute('apiUrl')}/package-manager/major-update`,
|
||||
body: {
|
||||
data: { dryRun },
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response?.processing) {
|
||||
jumpToQueue();
|
||||
} else {
|
||||
app.alerts.show({ type: 'success' }, app.translator.trans('flarum-package-manager.admin.update_successful'));
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
.catch(errorHandler)
|
||||
.catch((e: RequestError) => {
|
||||
app.modal.close();
|
||||
updateState.status = 'failure';
|
||||
updateState.incompatibleExtensions = e.response?.errors?.pop()?.incompatible_extensions as string[];
|
||||
})
|
||||
.finally(() => {
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,12 @@ import Task from '../models/Task';
|
||||
import { ApiQueryParamsPlural } from 'flarum/common/Store';
|
||||
|
||||
export default class QueueState {
|
||||
private polling: any = null;
|
||||
private tasks: Task[] | null = null;
|
||||
private limit = 20;
|
||||
private offset = 0;
|
||||
private total = 0;
|
||||
|
||||
load(params?: ApiQueryParamsPlural, actionTaken = false): Promise<Task[]> {
|
||||
load(params?: ApiQueryParamsPlural) {
|
||||
this.tasks = null;
|
||||
params = {
|
||||
page: {
|
||||
@@ -26,18 +25,6 @@ export default class QueueState {
|
||||
|
||||
m.redraw();
|
||||
|
||||
// Check if there is a pending or running task
|
||||
const pendingTask = data?.find((task) => task.status() === 'pending' || task.status() === 'running');
|
||||
|
||||
if (pendingTask) {
|
||||
this.pollQueue(actionTaken);
|
||||
} else if (actionTaken) {
|
||||
app.packageManager.control.setLoading(null);
|
||||
|
||||
// Refresh the page
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
@@ -75,14 +62,4 @@ export default class QueueState {
|
||||
this.load();
|
||||
}
|
||||
}
|
||||
|
||||
pollQueue(actionTaken = false): void {
|
||||
if (this.polling) {
|
||||
clearTimeout(this.polling);
|
||||
}
|
||||
|
||||
this.polling = setTimeout(() => {
|
||||
this.load({}, actionTaken);
|
||||
}, 6000);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,12 @@
|
||||
import app from 'flarum/admin/app';
|
||||
|
||||
export default function (e: any) {
|
||||
app.packageManager.control.setLoading(null);
|
||||
|
||||
const error = e.response.errors[0];
|
||||
|
||||
if (!['composer_command_failure', 'extension_already_installed', 'extension_not_installed'].includes(error.code)) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.alerts.clear();
|
||||
|
||||
switch (error.code) {
|
||||
case 'composer_command_failure':
|
||||
if (error.guessed_cause) {
|
||||
|
@@ -5,11 +5,8 @@ window.jumpToQueue = jumpToQueue;
|
||||
|
||||
export default function jumpToQueue(): void {
|
||||
app.modal.close();
|
||||
|
||||
m.route.set(app.route('extension', { id: 'flarum-package-manager' }));
|
||||
|
||||
app.packageManager.queue.load({}, true);
|
||||
|
||||
app.packageManager.queue.load();
|
||||
setTimeout(() => {
|
||||
document.getElementById('PackageManager-queueSection')?.scrollIntoView({ block: 'nearest' });
|
||||
}, 200);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
@import "admin/QueueSection";
|
||||
@import "admin/ControlSection";
|
||||
|
||||
.PackageManager-controlSection {
|
||||
.PackageManager-controlSection, .PackageManager-queueSection {
|
||||
> .container {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
@@ -27,32 +27,3 @@
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.Form--controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: auto;
|
||||
padding-top: 16px;
|
||||
}
|
||||
|
||||
.ButtonGroup--full {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
> .Button:first-child {
|
||||
flex-grow: 1;
|
||||
text-align: start;
|
||||
}
|
||||
}
|
||||
|
||||
.ConfigureAuth-hosts, .ConfigureComposer-repositories {
|
||||
> .ButtonGroup {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.flarum-package-manager-Page .SettingsGroups .Form {
|
||||
max-height: unset;
|
||||
}
|
||||
|
@@ -15,12 +15,10 @@
|
||||
}
|
||||
|
||||
.PackageManager-extensions {
|
||||
width: 100%;
|
||||
|
||||
&-grid {
|
||||
--gap: 12px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, 310px);
|
||||
grid-template-columns: repeat(auto-fit, calc(~"100% / 3 - var(--gap)"));
|
||||
gap: var(--gap);
|
||||
}
|
||||
}
|
||||
@@ -88,35 +86,12 @@
|
||||
grid-template-areas:
|
||||
"title logo"
|
||||
"helpText logo"
|
||||
"controls logo";
|
||||
column-gap: 0 var(--space);
|
||||
"controls logo"
|
||||
"extensions extensions"
|
||||
"failure failure";
|
||||
grid-gap: 0 var(--space);
|
||||
align-items: center;
|
||||
|
||||
&--failed&--incompatibleExtensions {
|
||||
grid-template-areas:
|
||||
"title logo"
|
||||
"helpText logo"
|
||||
"controls logo"
|
||||
"extensions extensions"
|
||||
"failure failure";
|
||||
}
|
||||
|
||||
&--failed {
|
||||
grid-template-areas:
|
||||
"title logo"
|
||||
"helpText logo"
|
||||
"controls logo"
|
||||
"failure failure";
|
||||
}
|
||||
|
||||
&--incompatibleExtensions {
|
||||
grid-template-areas:
|
||||
"title logo"
|
||||
"helpText logo"
|
||||
"controls logo"
|
||||
"extensions extensions";
|
||||
}
|
||||
|
||||
> img {
|
||||
grid-area: logo;
|
||||
}
|
||||
@@ -141,10 +116,6 @@
|
||||
padding-top: var(--space);
|
||||
border-top: 1px solid var(--control-bg);
|
||||
}
|
||||
|
||||
.PackageManager-updaterControls {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.WhyNotModal {
|
||||
@@ -154,18 +125,9 @@
|
||||
}
|
||||
|
||||
.PackageManager-installer .FormControl-container {
|
||||
max-width: 450px;
|
||||
max-width: 400px;
|
||||
|
||||
.FormControl {
|
||||
width: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.PackageManager-controlSection .container {
|
||||
max-width: 1030px;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.PackageManager-primaryWarning ul {
|
||||
margin: 0;
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@
|
||||
|
||||
.Label {
|
||||
text-transform: uppercase;
|
||||
margin-inline-end: 8px;
|
||||
}
|
||||
|
||||
.Table {
|
||||
|
@@ -1,66 +1,12 @@
|
||||
flarum-package-manager:
|
||||
admin:
|
||||
auth_config:
|
||||
add_label: New authentication method
|
||||
add_modal:
|
||||
host_label: Host
|
||||
host_placeholder: "example: extiverse.com"
|
||||
submit_button: Submit
|
||||
token_label: Token
|
||||
type_label: Type
|
||||
unchanged_token_placeholder: "(unchanged)"
|
||||
delete_confirmation: Are you sure you want to delete this authentication method?
|
||||
delete_label: Delete authentication method
|
||||
edit_label: Edit authentication method
|
||||
fields:
|
||||
host: Host
|
||||
token: Token
|
||||
no_auth_methods_configured: No authentication methods configured. This is an optional advanced feature to allow installing from private repositories.
|
||||
remove_button_label: Remove authentication method
|
||||
title: Authentication Methods
|
||||
types:
|
||||
github-oauth: GitHub OAuth
|
||||
gitlab-oauth: GitLab OAuth
|
||||
gitlab-token: GitLab Token
|
||||
bearer: HTTP Bearer
|
||||
composer:
|
||||
add_repository_label: Add Repository
|
||||
delete_repository_confirmation: Are you sure you want to delete this repository? All extensions installed from this repository will be removed.
|
||||
delete_repository_label: Delete repository
|
||||
edit_repository_label: Edit repository
|
||||
title: Composer
|
||||
minimum_stability:
|
||||
label: Minimum Stability
|
||||
help: The type of packages allowed to be installed. Do not change this unless you know what you are doing.
|
||||
options:
|
||||
stable: Stable (Recommended)
|
||||
rc: Release Candidate
|
||||
beta: Beta
|
||||
alpha: Alpha
|
||||
dev: Dev
|
||||
repositories:
|
||||
label: Repositories
|
||||
help: >
|
||||
Add additional repositories to install packages from. This is an advanced feature, do not add repositories that are not trusted, as they can be used to execute malicious code on your server.
|
||||
types:
|
||||
composer: composer
|
||||
vcs: vcs
|
||||
path: path
|
||||
add_modal:
|
||||
name_label: Name
|
||||
type_label: Type
|
||||
url: URL
|
||||
submit_button: Submit
|
||||
|
||||
exceptions:
|
||||
composer_command_failure: Failed to execute. Check the composer logs in storage/logs/composer.
|
||||
extension_already_installed: Extension is already installed.
|
||||
extension_not_directly_dependency: Extension is installed as a dependency of another extension, it cannot be directly removed.
|
||||
extension_not_installed: Extension not found.
|
||||
|
||||
guessed_cause:
|
||||
extension_incompatible_with_instance: The extension is most likely incompatible with your current Flarum instance.
|
||||
extension_not_found: The extension was not found or does not exist.
|
||||
extensions_incompatible_with_new_major: >
|
||||
Some installed extensions are not compatible with the newest major release.
|
||||
Please wait until the extensions are updated to be compatible by the authors, or remove them before proceeding.
|
||||
@@ -68,25 +14,18 @@ flarum-package-manager:
|
||||
extensions:
|
||||
check_why_it_failed_updating: Show why it did not update to the latest.
|
||||
install: Install a new extension
|
||||
install_help: >
|
||||
Fill in the extension package name to proceed. You can specify a <semantic_link>semantic version</semantic_link> using the format <code>vendor/package-name:version</code>.
|
||||
Visit {extiverse} to browse extensions.
|
||||
install_help: Fill in the extension package name to proceed. Visit {extiverse} to browse extensions.
|
||||
proceed: Proceed
|
||||
remove: Uninstall
|
||||
successful_install: "{extension} was installed successfully, redirecting.."
|
||||
successful_remove: Extension removed successfully.
|
||||
successful_update: "{extension} was updated successfully, redirecting.."
|
||||
update: Update
|
||||
update_soft_label: Soft update
|
||||
update_hard_label: Hard update
|
||||
|
||||
file_permissions: >
|
||||
The package manager requires read and write permissions on the following files and directories: composer.json, composer.lock, vendor, storage, storage/.composer
|
||||
|
||||
major_updater:
|
||||
description: >
|
||||
Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
|
||||
Please make sure to make a backup of your database and files before proceeding.
|
||||
description: Major Flarum updates are not backwards compatible, meaning that some of your currently installed extensions, and manually made modifications might not work with this new version.
|
||||
dry_run: Dry Run
|
||||
dry_run_help: A dry run emulates the update to see if your current setup can safely update, this does not mean that your manual made custom modifications will work in the newer version.
|
||||
failure:
|
||||
@@ -106,7 +45,7 @@ flarum-package-manager:
|
||||
columns:
|
||||
details: Details
|
||||
elapsed_time: Completed in
|
||||
peak_memory_used: Peak Memory Usage
|
||||
peak_memory_used: Maximum Memory Used
|
||||
operation: Operation
|
||||
package: Package
|
||||
status: Status
|
||||
@@ -121,9 +60,7 @@ flarum-package-manager:
|
||||
update_minor: Minor update
|
||||
why_not: Analyze why a package cannot be updated
|
||||
output_modal:
|
||||
cause_unknown: Unknown
|
||||
command: Composer Command
|
||||
guessed_cause: Cause
|
||||
output: Output
|
||||
refresh: Refresh tasks list
|
||||
statuses:
|
||||
@@ -135,17 +72,11 @@ flarum-package-manager:
|
||||
title: Queue
|
||||
|
||||
settings:
|
||||
title: => core.ref.settings
|
||||
access_warning: Please be careful to who you give access to the admin area, the package manager could be misused by bad actors to install packages that can lead to security breaches.
|
||||
debug_mode_warning: You are running in debug mode, the package manager cannot properly install and update local development packages. Please use the command line interface instead for such purposes.
|
||||
queue_jobs: Run operations in the background queue
|
||||
queue_jobs_help: >
|
||||
You can read about a <a href='{basic_impl_link}'>basic queue</a> implementation or a <a href='{adv_impl_link}'>more advanced</a> one.
|
||||
Make sure the PHP version used for the queue is {php_version}. Make sure <a href='{folder_perms_link}'>folder permissions</a> are correctly configured.
|
||||
task_retention_days: Task retention days
|
||||
task_retention_days_help: >
|
||||
The number of days to keep completed tasks in the database. Tasks older than this will be deleted.
|
||||
Set to 0 to keep all tasks.
|
||||
|
||||
updater:
|
||||
up_to_date: Everything is up to date!
|
||||
|
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
|
||||
return Migration::addColumns('package_manager_tasks', [
|
||||
'guessed_cause' => ['type' => 'string', 'length' => 255, 'nullable' => true, 'after' => 'output'],
|
||||
]);
|
@@ -38,6 +38,10 @@ class CheckForUpdatesController implements RequestHandlerInterface
|
||||
|
||||
$actor->assertAdmin();
|
||||
|
||||
/**
|
||||
* @TODO somewhere, if we're queuing, check that a similar composer command isn't already running,
|
||||
* to avoid duplicate jobs.
|
||||
*/
|
||||
$response = $this->bus->dispatch(
|
||||
new CheckForUpdates($actor)
|
||||
);
|
||||
|
@@ -1,142 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Api\Controller;
|
||||
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\PackageManager\Composer\ComposerJson;
|
||||
use Flarum\PackageManager\ConfigureComposerValidator;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
/**
|
||||
* Used to both set and read the composer.json configuration.
|
||||
* And other composer local configuration such as auth.json.
|
||||
*/
|
||||
class ConfigureComposerController implements RequestHandlerInterface
|
||||
{
|
||||
protected $configurable = [
|
||||
'minimum-stability',
|
||||
'repositories',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ConfigureComposerValidator
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @var Paths
|
||||
*/
|
||||
protected $paths;
|
||||
|
||||
/**
|
||||
* @var ComposerJson
|
||||
*/
|
||||
protected $composerJson;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
public function __construct(ConfigureComposerValidator $validator, Paths $paths, ComposerJson $composerJson, Filesystem $filesystem)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
$this->paths = $paths;
|
||||
$this->composerJson = $composerJson;
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$type = Arr::get($request->getParsedBody(), 'type');
|
||||
|
||||
$actor->assertAdmin();
|
||||
|
||||
if (! in_array($type, ['composer', 'auth'])) {
|
||||
return new JsonResponse([
|
||||
'data' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($type === 'composer') {
|
||||
$data = $this->composerConfig($request);
|
||||
} else {
|
||||
$data = $this->authConfig($request);
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function composerConfig(ServerRequestInterface $request): array
|
||||
{
|
||||
$data = Arr::only(Arr::get($request->getParsedBody(), 'data') ?? [], $this->configurable);
|
||||
|
||||
$this->validator->assertValid(['composer' => $data]);
|
||||
$composerJson = $this->composerJson->get();
|
||||
|
||||
if (! empty($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
Arr::set($composerJson, $key, $value);
|
||||
}
|
||||
|
||||
// Always prefer stable releases.
|
||||
$composerJson['prefer-stable'] = true;
|
||||
|
||||
$this->composerJson->set($composerJson);
|
||||
}
|
||||
|
||||
return Arr::only($composerJson, $this->configurable);
|
||||
}
|
||||
|
||||
protected function authConfig(ServerRequestInterface $request): array
|
||||
{
|
||||
$data = Arr::get($request->getParsedBody(), 'data');
|
||||
|
||||
$this->validator->assertValid(['auth' => $data]);
|
||||
|
||||
$authJson = json_decode($this->filesystem->get($this->paths->base.'/auth.json'), true);
|
||||
|
||||
if (! is_null($data)) {
|
||||
foreach ($data as $type => $hosts) {
|
||||
foreach ($hosts as $host => $token) {
|
||||
if (empty($token)) {
|
||||
unset($authJson[$type][$host]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$type][$host] = $token === '***'
|
||||
? $authJson[$type][$host]
|
||||
: $token;
|
||||
}
|
||||
}
|
||||
|
||||
$this->filesystem->put($this->paths->base.'/auth.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
$authJson = $data;
|
||||
}
|
||||
|
||||
// Remove tokens from response.
|
||||
foreach ($authJson as $type => $hosts) {
|
||||
foreach ($hosts as $host => $token) {
|
||||
$authJson[$type][$host] = '***';
|
||||
}
|
||||
}
|
||||
|
||||
return $authJson;
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ use Flarum\Api\Controller\AbstractListController;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\PackageManager\Api\Serializer\TaskSerializer;
|
||||
use Flarum\PackageManager\Task\Task;
|
||||
use Flarum\PackageManager\Task\TaskRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
@@ -29,9 +29,15 @@ class ListTasksController extends AbstractListController
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
public function __construct(UrlGenerator $url)
|
||||
/**
|
||||
* @var TaskRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
public function __construct(UrlGenerator $url, TaskRepository $repository)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
@@ -43,13 +49,14 @@ class ListTasksController extends AbstractListController
|
||||
$limit = $this->extractLimit($request);
|
||||
$offset = $this->extractOffset($request);
|
||||
|
||||
$results = Task::query()
|
||||
$results = $this->repository
|
||||
->query()
|
||||
->latest()
|
||||
->offset($offset)
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
$total = Task::query()->count();
|
||||
$total = $this->repository->query()->count();
|
||||
|
||||
$document->addMeta('total', (string) $total);
|
||||
|
||||
|
@@ -35,10 +35,9 @@ class UpdateExtensionController implements RequestHandlerInterface
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$extensionId = Arr::get($request->getQueryParams(), 'id');
|
||||
$updateMode = Arr::get($request->getParsedBody(), 'data.updateMode');
|
||||
|
||||
$response = $this->bus->dispatch(
|
||||
new UpdateExtension($actor, $extensionId, $updateMode)
|
||||
new UpdateExtension($actor, $extensionId)
|
||||
);
|
||||
|
||||
return $response->queueJobs
|
||||
|
@@ -40,7 +40,6 @@ class TaskSerializer extends AbstractSerializer
|
||||
'command' => $model->command,
|
||||
'package' => $model->package,
|
||||
'output' => $model->output,
|
||||
'guessedCause' => $model->guessed_cause,
|
||||
'createdAt' => $model->created_at,
|
||||
'startedAt' => $model->started_at,
|
||||
'finishedAt' => $model->finished_at,
|
||||
|
@@ -23,10 +23,5 @@ abstract class AbstractActionCommand
|
||||
*/
|
||||
public $package = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $extensionId = null;
|
||||
|
||||
abstract public function getOperationName(): string;
|
||||
}
|
||||
|
@@ -9,13 +9,9 @@
|
||||
|
||||
namespace Flarum\PackageManager\Command;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Composer\ComposerJson;
|
||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||
use Flarum\PackageManager\Settings\LastUpdateCheck;
|
||||
use Flarum\PackageManager\Support\Util;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
||||
class CheckForUpdatesHandler
|
||||
@@ -30,22 +26,10 @@ class CheckForUpdatesHandler
|
||||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var ComposerJson
|
||||
*/
|
||||
protected $composerJson;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, ExtensionManager $extensions, ComposerJson $composerJson)
|
||||
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->extensions = $extensions;
|
||||
$this->composerJson = $composerJson;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,10 +55,14 @@ class CheckForUpdatesHandler
|
||||
$firstOutput = $this->runComposerCommand(false, $command);
|
||||
$firstOutput = json_decode($this->cleanJson($firstOutput), true);
|
||||
|
||||
$installed = new Collection($firstOutput['installed'] ?? []);
|
||||
$majorUpdates = $installed->contains(function (array $package) {
|
||||
return isset($package['latest-status']) && $package['latest-status'] === 'update-possible' && Util::isMajorUpdate($package['version'], $package['latest']);
|
||||
});
|
||||
$majorUpdates = false;
|
||||
|
||||
foreach ($firstOutput['installed'] as $package) {
|
||||
if (isset($package['latest-status']) && $package['latest-status'] === 'update-possible') {
|
||||
$majorUpdates = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($majorUpdates) {
|
||||
$secondOutput = $this->runComposerCommand(true, $command);
|
||||
@@ -85,22 +73,10 @@ class CheckForUpdatesHandler
|
||||
$secondOutput = ['installed' => []];
|
||||
}
|
||||
|
||||
$updates = new Collection();
|
||||
$composerJson = $this->composerJson->get();
|
||||
|
||||
foreach ($installed as $mainPackageUpdate) {
|
||||
// Skip if not an extension
|
||||
if (! $this->extensions->getExtension(Util::nameToId($mainPackageUpdate['name']))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($firstOutput['installed'] as &$mainPackageUpdate) {
|
||||
$mainPackageUpdate['latest-minor'] = $mainPackageUpdate['latest-major'] = null;
|
||||
|
||||
if ($mainPackageUpdate['latest-status'] === 'up-to-date' && Util::isMajorUpdate($mainPackageUpdate['version'], $mainPackageUpdate['latest'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($mainPackageUpdate['latest-status']) && $mainPackageUpdate['latest-status'] === 'update-possible' && Util::isMajorUpdate($mainPackageUpdate['version'], $mainPackageUpdate['latest'])) {
|
||||
if (isset($mainPackageUpdate['latest-status']) && $mainPackageUpdate['latest-status'] === 'update-possible') {
|
||||
$mainPackageUpdate['latest-major'] = $mainPackageUpdate['latest'];
|
||||
|
||||
$minorPackageUpdate = array_filter($secondOutput['installed'], function ($package) use ($mainPackageUpdate) {
|
||||
@@ -113,14 +89,10 @@ class CheckForUpdatesHandler
|
||||
} else {
|
||||
$mainPackageUpdate['latest-minor'] = $mainPackageUpdate['latest'] ?? null;
|
||||
}
|
||||
|
||||
$mainPackageUpdate['required-as'] = $composerJson['require'][$mainPackageUpdate['name']] ?? null;
|
||||
|
||||
$updates->push($mainPackageUpdate);
|
||||
}
|
||||
|
||||
return $this->lastUpdateCheck
|
||||
->with('installed', $updates->values()->toArray())
|
||||
->with('installed', $firstOutput['installed'])
|
||||
->save();
|
||||
}
|
||||
|
||||
@@ -140,6 +112,7 @@ class CheckForUpdatesHandler
|
||||
{
|
||||
$input = [
|
||||
'command' => 'outdated',
|
||||
'-D' => true,
|
||||
'--format' => 'json',
|
||||
];
|
||||
|
||||
|
@@ -10,12 +10,11 @@
|
||||
namespace Flarum\PackageManager\Command;
|
||||
|
||||
use Flarum\Bus\Dispatcher as FlarumDispatcher;
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Event\FlarumUpdated;
|
||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
|
||||
class GlobalUpdateHandler
|
||||
{
|
||||
@@ -34,17 +33,11 @@ class GlobalUpdateHandler
|
||||
*/
|
||||
protected $commandDispatcher;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, Dispatcher $events, FlarumDispatcher $commandDispatcher, Config $config)
|
||||
public function __construct(ComposerAdapter $composer, Dispatcher $events, FlarumDispatcher $commandDispatcher)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->events = $events;
|
||||
$this->commandDispatcher = $commandDispatcher;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,16 +47,8 @@ class GlobalUpdateHandler
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
$input = [
|
||||
'command' => 'update',
|
||||
'--prefer-dist' => true,
|
||||
'--no-dev' => ! $this->config->inDebugMode(),
|
||||
'-a' => true,
|
||||
'--with-all-dependencies' => true,
|
||||
];
|
||||
|
||||
$output = $this->composer->run(
|
||||
new ArrayInput($input),
|
||||
new StringInput('update --prefer-dist --no-dev -a --with-all-dependencies'),
|
||||
$command->task ?? null
|
||||
);
|
||||
|
||||
|
@@ -89,6 +89,9 @@ class MajorUpdateHandler
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo change minimum stability to 'stable' and any other similar params
|
||||
*/
|
||||
protected function updateComposerJson(string $majorVersion): void
|
||||
{
|
||||
$versionNumber = str_replace('v', '', $majorVersion);
|
||||
|
@@ -55,8 +55,10 @@ class MinorUpdateHandler
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
// Set all extensions to * versioning.
|
||||
$coreRequirement = $this->composerJson->get()['require']['flarum/core'];
|
||||
|
||||
$this->composerJson->require('*', '*');
|
||||
$this->composerJson->require('flarum/core', $coreRequirement);
|
||||
|
||||
$output = $this->composer->run(
|
||||
new StringInput('update --prefer-dist --no-dev -a --with-all-dependencies'),
|
||||
|
@@ -19,6 +19,11 @@ class RemoveExtension extends AbstractActionCommand
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $extensionId;
|
||||
|
||||
public function __construct(User $actor, string $extensionId)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
|
@@ -11,10 +11,8 @@ namespace Flarum\PackageManager\Command;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Composer\ComposerJson;
|
||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
||||
use Flarum\PackageManager\Exception\IndirectExtensionDependencyCannotBeRemovedException;
|
||||
use Flarum\PackageManager\Extension\Event\Removed;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
@@ -36,17 +34,11 @@ class RemoveExtensionHandler
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var ComposerJson
|
||||
*/
|
||||
protected $composerJson;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, ExtensionManager $extensions, Dispatcher $events, ComposerJson $composerJson)
|
||||
public function __construct(ComposerAdapter $composer, ExtensionManager $extensions, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->events = $events;
|
||||
$this->composerJson = $composerJson;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,13 +59,6 @@ class RemoveExtensionHandler
|
||||
$command->task->package = $extension->name;
|
||||
}
|
||||
|
||||
$json = $this->composerJson->get();
|
||||
|
||||
// If this extension is not a direct dependency, we can't actually remove it.
|
||||
if (! isset($json['require'][$extension->name]) && ! isset($json['require-dev'][$extension->name])) {
|
||||
throw new IndirectExtensionDependencyCannotBeRemovedException($command->extensionId);
|
||||
}
|
||||
|
||||
$output = $this->composer->run(
|
||||
new StringInput("remove $extension->name"),
|
||||
$command->task ?? null
|
||||
|
@@ -14,8 +14,8 @@ use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
|
||||
use Flarum\PackageManager\Exception\ExtensionAlreadyInstalledException;
|
||||
use Flarum\PackageManager\Extension\Event\Installed;
|
||||
use Flarum\PackageManager\Extension\ExtensionUtils;
|
||||
use Flarum\PackageManager\RequirePackageValidator;
|
||||
use Flarum\PackageManager\Support\Util;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
|
||||
@@ -59,7 +59,7 @@ class RequireExtensionHandler
|
||||
|
||||
$this->validator->assertValid(['package' => $command->package]);
|
||||
|
||||
$extensionId = Util::nameToId($command->package);
|
||||
$extensionId = ExtensionUtils::nameToId($command->package);
|
||||
$extension = $this->extensions->getExtension($extensionId);
|
||||
|
||||
if (! empty($extension)) {
|
||||
@@ -74,7 +74,7 @@ class RequireExtensionHandler
|
||||
}
|
||||
|
||||
$output = $this->composer->run(
|
||||
new StringInput("require $packageName -W"),
|
||||
new StringInput("require $packageName"),
|
||||
$command->task ?? null
|
||||
);
|
||||
|
||||
|
@@ -22,13 +22,12 @@ class UpdateExtension extends AbstractActionCommand
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $updateMode;
|
||||
public $extensionId;
|
||||
|
||||
public function __construct(User $actor, string $extensionId, string $updateMode)
|
||||
public function __construct(User $actor, string $extensionId)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->extensionId = $extensionId;
|
||||
$this->updateMode = $updateMode;
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
@@ -10,6 +10,8 @@
|
||||
namespace Flarum\PackageManager\Command;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Foundation\ValidationException;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use Flarum\PackageManager\Exception\ExtensionNotInstalledException;
|
||||
@@ -46,18 +48,25 @@ class UpdateExtensionHandler
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var Paths
|
||||
*/
|
||||
protected $paths;
|
||||
|
||||
public function __construct(
|
||||
ComposerAdapter $composer,
|
||||
ExtensionManager $extensions,
|
||||
UpdateExtensionValidator $validator,
|
||||
LastUpdateCheck $lastUpdateCheck,
|
||||
Dispatcher $events
|
||||
Dispatcher $events,
|
||||
Paths $paths
|
||||
) {
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->validator = $validator;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->events = $events;
|
||||
$this->paths = $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +77,7 @@ class UpdateExtensionHandler
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
$this->validator->assertValid([
|
||||
'extensionId' => $command->extensionId,
|
||||
'updateMode' => $command->updateMode,
|
||||
]);
|
||||
$this->validator->assertValid(['extensionId' => $command->extensionId]);
|
||||
|
||||
$extension = $this->extensions->getExtension($command->extensionId);
|
||||
|
||||
@@ -79,19 +85,19 @@ class UpdateExtensionHandler
|
||||
throw new ExtensionNotInstalledException($command->extensionId);
|
||||
}
|
||||
|
||||
// In situations where an extension was locked to a specific version,
|
||||
// a hard update mode is useful to allow removing the locked version and
|
||||
// instead requiring the latest version.
|
||||
// Another scenario could be when requiring a specific version range, for example 0.1.*,
|
||||
// the admin might either want to update to the latest version in that range, or to the latest version overall (0.2.0).
|
||||
if ($command->updateMode === 'soft') {
|
||||
$input = "update $extension->name";
|
||||
} else {
|
||||
$input = "require $extension->name:*";
|
||||
$rootComposer = json_decode(file_get_contents("{$this->paths->base}/composer.json"), true);
|
||||
|
||||
// If this was installed as a requirement for another extension,
|
||||
// don't update it directly.
|
||||
// @TODO communicate this in the UI.
|
||||
if (! isset($rootComposer['require'][$extension->name]) && ! empty($extension->getExtensionDependencyIds())) {
|
||||
throw new ValidationException([
|
||||
'message' => "Cannot update $extension->name. It was installed as a requirement for other extensions: ".implode(', ', $extension->getExtensionDependencyIds()).'. Update those extensions instead.'
|
||||
]);
|
||||
}
|
||||
|
||||
$output = $this->composer->run(
|
||||
new StringInput($input),
|
||||
new StringInput("require $extension->name:*"),
|
||||
$command->task ?? null
|
||||
);
|
||||
|
||||
|
@@ -13,7 +13,6 @@ use Composer\Config;
|
||||
use Composer\Console\Application;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\PackageManager\OutputLogger;
|
||||
use Flarum\PackageManager\Support\Util;
|
||||
use Flarum\PackageManager\Task\Task;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
@@ -33,6 +32,11 @@ class ComposerAdapter
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var BufferedOutput
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* @var Paths
|
||||
*/
|
||||
@@ -43,22 +47,22 @@ class ComposerAdapter
|
||||
$this->application = $application;
|
||||
$this->logger = $logger;
|
||||
$this->paths = $paths;
|
||||
$this->output = new BufferedOutput();
|
||||
}
|
||||
|
||||
public function run(InputInterface $input, ?Task $task = null): ComposerOutput
|
||||
{
|
||||
$this->application->resetComposer();
|
||||
|
||||
$output = new BufferedOutput();
|
||||
|
||||
// This hack is necessary so that relative path repositories are resolved properly.
|
||||
$currDir = getcwd();
|
||||
chdir($this->paths->base);
|
||||
$exitCode = $this->application->run($input, $output);
|
||||
$exitCode = $this->application->run($input, $this->output);
|
||||
chdir($currDir);
|
||||
|
||||
$command = Util::readableConsoleInput($input);
|
||||
$output = $output->fetch();
|
||||
// @phpstan-ignore-next-line
|
||||
$command = $input->__toString();
|
||||
$output = $this->output->fetch();
|
||||
|
||||
if ($task) {
|
||||
$task->update(compact('command', 'output'));
|
||||
|
@@ -9,9 +9,7 @@
|
||||
|
||||
namespace Flarum\PackageManager\Composer;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\PackageManager\Support\Util;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -32,16 +30,10 @@ class ComposerJson
|
||||
*/
|
||||
protected $initialJson;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(Paths $paths, Filesystem $filesystem, ExtensionManager $extensions)
|
||||
public function __construct(Paths $paths, Filesystem $filesystem)
|
||||
{
|
||||
$this->paths = $paths;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
public function require(string $packageName, string $version): void
|
||||
@@ -56,11 +48,6 @@ class ComposerJson
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only extensions can all be set to * versioning.
|
||||
if (! $this->extensions->getExtension(Util::nameToId($packageName))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wildcardPackageName = str_replace('\*', '.*', preg_quote($packageName, '/'));
|
||||
|
||||
if (Str::of($p)->test("/($wildcardPackageName)/")) {
|
||||
@@ -96,7 +83,7 @@ class ComposerJson
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function set(array $json): void
|
||||
protected function set(array $json): void
|
||||
{
|
||||
$this->filesystem->put($this->getComposerJsonPath(), json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager;
|
||||
|
||||
use Flarum\Foundation\AbstractValidator;
|
||||
|
||||
class ConfigureComposerValidator extends AbstractValidator
|
||||
{
|
||||
protected $rules = [
|
||||
'composer' => [
|
||||
'minimum-stability' => ['sometimes', 'in:stable,RC,beta,alpha,dev'],
|
||||
'repositories' => ['sometimes', 'array'],
|
||||
'repositories.*.type' => ['sometimes', 'in:composer,vcs,path'],
|
||||
'repositories.*.url' => ['sometimes', 'string'],
|
||||
],
|
||||
'auth' => [
|
||||
'github-oauth' => ['sometimes', 'array'],
|
||||
'github-oauth.*' => ['sometimes', 'string'],
|
||||
'gitlab-oauth' => ['sometimes', 'array'],
|
||||
'gitlab-oauth.*' => ['sometimes', 'string'],
|
||||
'gitlab-token' => ['sometimes', 'array'],
|
||||
'gitlab-token.*' => ['sometimes', 'string'],
|
||||
'bearer' => ['sometimes', 'array'],
|
||||
'bearer.*' => ['sometimes', 'string'],
|
||||
],
|
||||
];
|
||||
}
|
@@ -11,31 +11,20 @@ namespace Flarum\PackageManager\Exception;
|
||||
|
||||
class ComposerRequireFailedException extends ComposerCommandFailedException
|
||||
{
|
||||
protected const INCOMPATIBLE_REGEX = '/(?:(?: +- {PACKAGE_NAME}(?: v[0-9A-z.-]+ requires|\[[^\[\]]+\] require) flarum\/core)|(?:Could not find a version of package {PACKAGE_NAME} matching your minim)|(?: +- Root composer\.json requires {PACKAGE_NAME} [^,]+, found {PACKAGE_NAME}\[[^\[\]]+\]+ but it does not match your minimum-stability))/m';
|
||||
protected const NOT_FOUND_REGEX = '/(?:(?: +- Root composer\.json requires {PACKAGE_NAME}, it could not be found in any version, there may be a typo in the package name.))/m';
|
||||
protected const INCOMPATIBLE_REGEX = '/(?:(?: +- {PACKAGE_NAME}(?: v[0-9A-z.-]+ requires|\[[^\[\]]+\] require) flarum\/core)|(?:Could not find a version of package {PACKAGE_NAME} matching your minim)|(?: +- Root composer.json requires {PACKAGE_NAME} [^,]+, found {PACKAGE_NAME}\[[^\[\]]+\]+ but it does not match your minimum-stability))/m';
|
||||
|
||||
public function guessCause(): ?string
|
||||
{
|
||||
$hasIncompatibleMatches = preg_match(
|
||||
$hasMatches = preg_match(
|
||||
str_replace('{PACKAGE_NAME}', preg_quote($this->getRawPackageName(), '/'), self::INCOMPATIBLE_REGEX),
|
||||
$this->getMessage(),
|
||||
$matches
|
||||
);
|
||||
|
||||
if ($hasIncompatibleMatches) {
|
||||
if ($hasMatches) {
|
||||
return 'extension_incompatible_with_instance';
|
||||
}
|
||||
|
||||
$hasNotFoundMatches = preg_match(
|
||||
str_replace('{PACKAGE_NAME}', preg_quote($this->getRawPackageName(), '/'), self::NOT_FOUND_REGEX),
|
||||
$this->getMessage(),
|
||||
$matches
|
||||
);
|
||||
|
||||
if ($hasNotFoundMatches) {
|
||||
return 'extension_not_found';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Exception;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Foundation\KnownError;
|
||||
|
||||
class IndirectExtensionDependencyCannotBeRemovedException extends Exception implements KnownError
|
||||
{
|
||||
public function __construct(string $extensionId)
|
||||
{
|
||||
parent::__construct("Extension {$extensionId} cannot be directly removed because it is a dependency of another extension.");
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return 'extension_not_directly_dependency';
|
||||
}
|
||||
}
|
21
extensions/package-manager/src/Extension/ExtensionUtils.php
Executable file
21
extensions/package-manager/src/Extension/ExtensionUtils.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Extension;
|
||||
|
||||
class ExtensionUtils
|
||||
{
|
||||
public static function nameToId(string $name): string
|
||||
{
|
||||
[$vendor, $package] = explode('/', $name);
|
||||
$package = str_replace(['flarum-ext-', 'flarum-'], '', $package);
|
||||
|
||||
return "$vendor-$package";
|
||||
}
|
||||
}
|
@@ -12,13 +12,11 @@ namespace Flarum\PackageManager\Job;
|
||||
use Flarum\Bus\Dispatcher;
|
||||
use Flarum\PackageManager\Command\AbstractActionCommand;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
||||
use Flarum\Queue\AbstractJob;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
use Throwable;
|
||||
|
||||
class ComposerCommandJob extends AbstractJob implements ShouldBeUnique
|
||||
class ComposerCommandJob extends AbstractJob
|
||||
{
|
||||
/**
|
||||
* @var AbstractActionCommand
|
||||
@@ -39,10 +37,10 @@ class ComposerCommandJob extends AbstractJob implements ShouldBeUnique
|
||||
public function handle(Dispatcher $bus)
|
||||
{
|
||||
try {
|
||||
$this->command->task->start();
|
||||
|
||||
ComposerAdapter::setPhpVersion($this->phpVersion);
|
||||
|
||||
$this->command->task->start();
|
||||
|
||||
$bus->dispatch($this->command);
|
||||
|
||||
$this->command->task->end(true);
|
||||
@@ -57,19 +55,12 @@ class ComposerCommandJob extends AbstractJob implements ShouldBeUnique
|
||||
$this->command->task->output = $exception->getMessage();
|
||||
}
|
||||
|
||||
if ($exception instanceof ComposerCommandFailedException) {
|
||||
$this->command->task->guessed_cause = $exception->guessCause();
|
||||
}
|
||||
|
||||
$this->command->task->end(false);
|
||||
|
||||
$this->fail($exception);
|
||||
}
|
||||
|
||||
public function failed(Throwable $exception): void
|
||||
{
|
||||
$this->abort($exception);
|
||||
}
|
||||
|
||||
public function middleware(): array
|
||||
public function middleware()
|
||||
{
|
||||
return [
|
||||
new WithoutOverlapping(),
|
||||
|
@@ -9,9 +9,7 @@
|
||||
|
||||
namespace Flarum\PackageManager\Job;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Bus\Dispatcher as Bus;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\PackageManager\Command\AbstractActionCommand;
|
||||
use Flarum\PackageManager\Task\Task;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
@@ -35,11 +33,6 @@ class Dispatcher
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* Overrides the user setting for execution mode if set.
|
||||
* Runs synchronously regardless of user setting if set true.
|
||||
@@ -49,12 +42,11 @@ class Dispatcher
|
||||
*/
|
||||
protected $runSyncOverride;
|
||||
|
||||
public function __construct(Bus $bus, Queue $queue, SettingsRepositoryInterface $settings, ExtensionManager $extensions)
|
||||
public function __construct(Bus $bus, Queue $queue, SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
$this->queue = $queue;
|
||||
$this->settings = $settings;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
public function sync(): self
|
||||
@@ -75,15 +67,8 @@ class Dispatcher
|
||||
{
|
||||
$queueJobs = ($this->runSyncOverride === false) || ($this->runSyncOverride !== true && $this->settings->get('flarum-package-manager.queue_jobs'));
|
||||
|
||||
// Skip if there is already a pending or running task.
|
||||
if ($queueJobs && Task::query()->whereIn('status', [Task::PENDING, Task::RUNNING])->exists()) {
|
||||
return new DispatcherResponse(true, null);
|
||||
}
|
||||
|
||||
if ($queueJobs && (! $this->queue instanceof SyncQueue)) {
|
||||
$extension = $command->extensionId ? $this->extensions->getExtension($command->extensionId) : null;
|
||||
|
||||
$task = Task::build($command->getOperationName(), $command->package ?? ($extension ? $extension->name : null));
|
||||
$task = Task::build($command->getOperationName(), $command->package ?? null);
|
||||
|
||||
$command->task = $task;
|
||||
|
||||
@@ -94,21 +79,6 @@ class Dispatcher
|
||||
$data = $this->bus->dispatch($command);
|
||||
}
|
||||
|
||||
$this->clearOldTasks();
|
||||
|
||||
return new DispatcherResponse($queueJobs, $data ?? null);
|
||||
}
|
||||
|
||||
protected function clearOldTasks(): void
|
||||
{
|
||||
$days = $this->settings->get('flarum-package-manager.task_retention_days');
|
||||
|
||||
if ($days === null || ((int) $days) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Task::query()
|
||||
->where('created_at', '<', Carbon::now()->subDays($days))
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ namespace Flarum\PackageManager;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\Console\Application;
|
||||
use Composer\Util\Platform;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Paths;
|
||||
@@ -41,9 +40,9 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
|
||||
/** @var Paths $paths */
|
||||
$paths = $container->make(Paths::class);
|
||||
|
||||
Platform::putenv('COMPOSER_HOME', "$paths->storage/.composer");
|
||||
Platform::putenv('COMPOSER', "$paths->base/composer.json");
|
||||
Platform::putenv('COMPOSER_DISABLE_XDEBUG_WARN', '1');
|
||||
putenv("COMPOSER_HOME={$paths->storage}/.composer");
|
||||
putenv("COMPOSER={$paths->base}/composer.json");
|
||||
putenv('COMPOSER_DISABLE_XDEBUG_WARN=1');
|
||||
Config::$defaultConfig['vendor-dir'] = $paths->vendor;
|
||||
|
||||
// When running simple require, update and remove commands on packages,
|
||||
@@ -52,11 +51,7 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
|
||||
@ini_set('memory_limit', '1G');
|
||||
@set_time_limit(5 * 60);
|
||||
|
||||
return new ComposerAdapter(
|
||||
$composer,
|
||||
$container->make(OutputLogger::class),
|
||||
$container->make(Paths::class),
|
||||
);
|
||||
return new ComposerAdapter($composer, $container->make(OutputLogger::class), $container->make(Paths::class));
|
||||
});
|
||||
|
||||
$this->container->alias(ComposerAdapter::class, 'flarum.composer');
|
||||
|
@@ -13,7 +13,7 @@ use Flarum\Foundation\AbstractValidator;
|
||||
|
||||
class RequirePackageValidator extends AbstractValidator
|
||||
{
|
||||
public const PACKAGE_NAME_REGEX = '/^[A-z0-9-_]+\/[A-z-0-9]+(?::[A-z-0-9.->=<_@"*]+){0,1}$/i';
|
||||
public const PACKAGE_NAME_REGEX = '/^[A-z0-9-_]+\/[A-z-0-9]+(?::[A-z-0-9.->=<_]+){0,1}$/i';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Support;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
class Util
|
||||
{
|
||||
public static function nameToId(string $name): string
|
||||
{
|
||||
[$vendor, $package] = explode('/', $name);
|
||||
$package = str_replace(['flarum-ext-', 'flarum-'], '', $package);
|
||||
|
||||
return "$vendor-$package";
|
||||
}
|
||||
|
||||
public static function isMajorUpdate(string $currentVersion, string $latestVersion): bool
|
||||
{
|
||||
// Drop any v prefixes
|
||||
if (str_starts_with($currentVersion, 'v')) {
|
||||
$currentVersion = substr($currentVersion, 1);
|
||||
}
|
||||
|
||||
$currentVersion = explode('.', $currentVersion);
|
||||
$latestVersion = explode('.', $latestVersion);
|
||||
|
||||
if (! is_numeric($currentVersion[0]) || ! is_numeric($latestVersion[0])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (intval($currentVersion[0]) < intval($latestVersion[0])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function readableConsoleInput(InputInterface $input): string
|
||||
{
|
||||
if ($input instanceof ArrayInput) {
|
||||
$input = explode(' ', $input->__toString());
|
||||
|
||||
foreach ($input as $key => $value) {
|
||||
if (str_starts_with($value, '--')) {
|
||||
if (! str_contains($value, '=')) {
|
||||
unset($input[$key]);
|
||||
} else {
|
||||
$input[$key] = Str::before($value, '=');
|
||||
}
|
||||
}
|
||||
|
||||
if (is_numeric($value) && isset($input[$key - 1]) && str_starts_with($input[$key - 1], '-') && ! str_starts_with($input[$key - 1], '--')) {
|
||||
unset($input[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $input);
|
||||
} elseif (method_exists($input, '__toString')) {
|
||||
return $input->__toString();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -19,10 +19,9 @@ use Flarum\Database\AbstractModel;
|
||||
* @property string $command
|
||||
* @property string $package
|
||||
* @property string $output
|
||||
* @property string|null $guessed_cause
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon|null $started_at
|
||||
* @property Carbon|null $finished_at
|
||||
* @property Carbon $started_at
|
||||
* @property Carbon $finished_at
|
||||
* @property float $peak_memory_used
|
||||
*/
|
||||
class Task extends AbstractModel
|
||||
@@ -51,7 +50,7 @@ class Task extends AbstractModel
|
||||
|
||||
protected $table = 'package_manager_tasks';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $fillable = ['command', 'output'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
@@ -85,14 +84,6 @@ class Task extends AbstractModel
|
||||
|
||||
public function end(bool $success): bool
|
||||
{
|
||||
if ($this->finished_at) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->started_at) {
|
||||
$this->start();
|
||||
}
|
||||
|
||||
$this->status = $success ? static::SUCCESS : static::FAILURE;
|
||||
$this->finished_at = Carbon::now();
|
||||
$this->peak_memory_used = round(memory_get_peak_usage() / 1024);
|
||||
|
@@ -17,7 +17,6 @@ class UpdateExtensionValidator extends AbstractValidator
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $rules = [
|
||||
'extensionId' => 'required|string',
|
||||
'updateMode' => 'required|in:soft,hard',
|
||||
'extensionId' => 'required|string'
|
||||
];
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ namespace Flarum\PackageManager\Tests\integration;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\PackageManager\Composer\ComposerAdapter;
|
||||
use Flarum\PackageManager\Composer\ComposerJson;
|
||||
use Flarum\PackageManager\Support\Util;
|
||||
use Flarum\PackageManager\Extension\ExtensionUtils;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@@ -45,7 +45,7 @@ class TestCase extends \Flarum\Testing\integration\TestCase
|
||||
return $package['type'] === 'flarum-extension';
|
||||
});
|
||||
$installedExtensionIds = array_map(function (string $name) {
|
||||
return Util::nameToId($name);
|
||||
return ExtensionUtils::nameToId($name);
|
||||
}, Arr::pluck($installedExtensions, 'name'));
|
||||
|
||||
if ($exists) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user