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
|
|
|
*/
|
|
|
|
|
2021-10-21 17:52:51 +08:00
|
|
|
namespace Flarum\PackageManager;
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
use Flarum\Extend;
|
|
|
|
use Flarum\Foundation\Paths;
|
2021-09-23 05:08:51 +08:00
|
|
|
use Flarum\Frontend\Document;
|
2021-10-21 17:52:51 +08:00
|
|
|
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
|
|
|
|
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
|
|
|
|
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
|
2022-03-12 07:11:20 +08:00
|
|
|
use Flarum\PackageManager\Exception\ExceptionHandler;
|
2021-11-20 23:31:26 +08:00
|
|
|
use Flarum\PackageManager\Exception\MajorUpdateFailedException;
|
2021-11-24 06:02:56 +08:00
|
|
|
use Flarum\PackageManager\Settings\LastUpdateCheck;
|
|
|
|
use Flarum\PackageManager\Settings\LastUpdateRun;
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
(new Extend\Routes('api'))
|
|
|
|
->post('/package-manager/extensions', 'package-manager.extensions.require', Api\Controller\RequireExtensionController::class)
|
|
|
|
->patch('/package-manager/extensions/{id}', 'package-manager.extensions.update', Api\Controller\UpdateExtensionController::class)
|
2021-09-25 20:59:59 +08:00
|
|
|
->delete('/package-manager/extensions/{id}', 'package-manager.extensions.remove', Api\Controller\RemoveExtensionController::class)
|
2021-09-27 17:16:01 +08:00
|
|
|
->post('/package-manager/check-for-updates', 'package-manager.check-for-updates', Api\Controller\CheckForUpdatesController::class)
|
2021-11-24 06:02:56 +08:00
|
|
|
->post('/package-manager/why-not', 'package-manager.why-not', Api\Controller\WhyNotController::class)
|
2021-11-20 23:31:26 +08:00
|
|
|
->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)
|
2021-09-29 19:07:53 +08:00
|
|
|
->post('/package-manager/global-update', 'package-manager.global-update', Api\Controller\GlobalUpdateController::class),
|
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);
|
|
|
|
|
|
|
|
$document->payload['isRequiredDirectoriesWritable'] = is_writable($paths->vendor)
|
|
|
|
&& is_writable($paths->storage.'/.composer')
|
|
|
|
&& is_writable($paths->base.'/composer.json')
|
|
|
|
&& is_writable($paths->base.'/composer.lock');
|
|
|
|
}),
|
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())
|
2021-11-24 06:02:56 +08:00
|
|
|
->default(LastUpdateCheck::key(), json_encode(LastUpdateCheck::default()))
|
|
|
|
->default(LastUpdateRun::key(), json_encode(LastUpdateRun::default())),
|
2021-11-20 23:31:26 +08:00
|
|
|
|
2021-09-02 00:20:06 +08:00
|
|
|
(new Extend\ServiceProvider)
|
2021-09-02 02:49:44 +08:00
|
|
|
->register(PackageManagerServiceProvider::class),
|
2021-09-23 05:08:51 +08:00
|
|
|
|
|
|
|
(new Extend\ErrorHandling)
|
2021-11-20 23:31:26 +08:00
|
|
|
->handler(ComposerCommandFailedException::class, ExceptionHandler::class)
|
|
|
|
->handler(ComposerRequireFailedException::class, ExceptionHandler::class)
|
|
|
|
->handler(ComposerUpdateFailedException::class, ExceptionHandler::class)
|
|
|
|
->handler(MajorUpdateFailedException::class, 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)
|
|
|
|
->status('no_new_major_version', 409),
|
2021-09-02 00:20:06 +08:00
|
|
|
];
|