2021-09-02 00:20:06 +08:00
|
|
|
<?php
|
|
|
|
|
2021-10-21 17:52:51 +08:00
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
2021-09-02 00:20:06 +08:00
|
|
|
*
|
2021-10-21 17:52:51 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2021-09-02 00:20:06 +08:00
|
|
|
*/
|
|
|
|
|
2024-01-23 01:58:08 +08:00
|
|
|
namespace Flarum\ExtensionManager;
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
use Flarum\Extend;
|
2024-03-02 19:20:39 +08:00
|
|
|
use Flarum\ExtensionManager\Api\Resource\TaskResource;
|
2021-09-02 00:20:06 +08:00
|
|
|
use Flarum\Foundation\Paths;
|
2021-09-23 05:08:51 +08:00
|
|
|
use Flarum\Frontend\Document;
|
2022-07-24 21:02:13 +08:00
|
|
|
use Illuminate\Contracts\Queue\Queue;
|
|
|
|
use Illuminate\Queue\SyncQueue;
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
(new Extend\Routes('api'))
|
2024-01-23 01:58:08 +08:00
|
|
|
->post('/extension-manager/extensions', 'extension-manager.extensions.require', Api\Controller\RequireExtensionController::class)
|
|
|
|
->patch('/extension-manager/extensions/{id}', 'extension-manager.extensions.update', Api\Controller\UpdateExtensionController::class)
|
|
|
|
->delete('/extension-manager/extensions/{id}', 'extension-manager.extensions.remove', Api\Controller\RemoveExtensionController::class)
|
|
|
|
->post('/extension-manager/check-for-updates', 'extension-manager.check-for-updates', Api\Controller\CheckForUpdatesController::class)
|
|
|
|
->post('/extension-manager/why-not', 'extension-manager.why-not', Api\Controller\WhyNotController::class)
|
|
|
|
->post('/extension-manager/minor-update', 'extension-manager.minor-update', Api\Controller\MinorUpdateController::class)
|
|
|
|
->post('/extension-manager/major-update', 'extension-manager.major-update', Api\Controller\MajorUpdateController::class)
|
|
|
|
->post('/extension-manager/global-update', 'extension-manager.global-update', Api\Controller\GlobalUpdateController::class)
|
|
|
|
->post('/extension-manager/composer', 'extension-manager.composer', Api\Controller\ConfigureComposerController::class),
|
2021-09-02 00:20:06 +08:00
|
|
|
|
2024-03-08 21:41:35 +08:00
|
|
|
new Extend\ApiResource(TaskResource::class),
|
2024-03-02 19:20:39 +08:00
|
|
|
|
2021-09-02 00:20:06 +08:00
|
|
|
(new Extend\Frontend('admin'))
|
2022-03-12 07:11:20 +08:00
|
|
|
->css(__DIR__.'/less/admin.less')
|
|
|
|
->js(__DIR__.'/js/dist/admin.js')
|
2021-09-23 05:08:51 +08:00
|
|
|
->content(function (Document $document) {
|
|
|
|
$paths = resolve(Paths::class);
|
|
|
|
|
2024-01-23 01:58:08 +08:00
|
|
|
$document->payload['flarum-extension-manager.writable_dirs'] = is_writable($paths->vendor)
|
2022-08-20 16:53:23 +08:00
|
|
|
&& is_writable($paths->storage)
|
|
|
|
&& (! file_exists($paths->storage.'/.composer') || is_writable($paths->storage.'/.composer'))
|
2021-09-23 05:08:51 +08:00
|
|
|
&& is_writable($paths->base.'/composer.json')
|
|
|
|
&& is_writable($paths->base.'/composer.lock');
|
2022-07-24 21:02:13 +08:00
|
|
|
|
2024-01-23 01:58:08 +08:00
|
|
|
$document->payload['flarum-extension-manager.using_sync_queue'] = resolve(Queue::class) instanceof SyncQueue;
|
2021-09-23 05:08:51 +08:00
|
|
|
}),
|
2021-09-02 00:20:06 +08:00
|
|
|
|
2022-03-12 07:11:20 +08:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
2021-09-02 00:20:06 +08:00
|
|
|
|
2021-11-20 23:31:26 +08:00
|
|
|
(new Extend\Settings())
|
2024-01-23 01:58:08 +08:00
|
|
|
->default(Settings\LastUpdateCheck::key(), json_encode(Settings\LastUpdateCheck::default()))
|
|
|
|
->default(Settings\LastUpdateRun::key(), json_encode(Settings\LastUpdateRun::default()))
|
|
|
|
->default('flarum-extension-manager.queue_jobs', '0')
|
|
|
|
->default('flarum-extension-manager.minimum_stability', 'stable')
|
|
|
|
->default('flarum-extension-manager.task_retention_days', 7),
|
2021-11-20 23:31:26 +08:00
|
|
|
|
2021-09-02 00:20:06 +08:00
|
|
|
(new Extend\ServiceProvider)
|
2024-01-23 01:58:08 +08:00
|
|
|
->register(ExtensionManagerServiceProvider::class),
|
2021-09-23 05:08:51 +08:00
|
|
|
|
|
|
|
(new Extend\ErrorHandling)
|
2024-01-23 01:58:08 +08:00
|
|
|
->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)
|
2021-09-29 18:03:13 +08:00
|
|
|
->status('extension_already_installed', 409)
|
2021-11-20 23:31:26 +08:00
|
|
|
->status('extension_not_installed', 409)
|
2024-01-23 01:58:08 +08:00
|
|
|
->status('no_new_major_version', 409)
|
|
|
|
->status('extension_not_directly_dependency', 409),
|
2021-09-02 00:20:06 +08:00
|
|
|
];
|