This commit is contained in:
SychO9 2021-09-01 19:49:44 +01:00
parent 5d3804c7ca
commit 1d48c9878b
12 changed files with 179 additions and 112 deletions

View File

@ -9,7 +9,6 @@ namespace SychO\PackageManager;
use Flarum\Extend; use Flarum\Extend;
use Flarum\Foundation\Paths; use Flarum\Foundation\Paths;
use Illuminate\Console\Scheduling\Event; use Illuminate\Console\Scheduling\Event;
use SychO\PackageManager\Console\TaskCommand;
return [ return [
(new Extend\Routes('api')) (new Extend\Routes('api'))
@ -24,13 +23,6 @@ return [
new Extend\Locales(__DIR__ . '/locale'), new Extend\Locales(__DIR__ . '/locale'),
(new Extend\ServiceProvider) (new Extend\ServiceProvider)
->register(ComposerEnvironmentProvider::class), ->register(ComposerEnvironmentProvider::class)
->register(PackageManagerServiceProvider::class),
(new Extend\Console)
->schedule(TaskCommand::class, function (Event $event) {
$event
->everyMinute()
->withoutOverlapping()
->appendOutputTo(resolve(Paths::class)->storage.'/logs/bazaar-tasks.log');
}),
]; ];

View File

@ -87,17 +87,31 @@ module.exports =
/************************************************************************/ /************************************************************************/
/******/ ({ /******/ ({
/***/ "../../core/js/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js": /***/ "./admin.js":
/*!***********************************************************************************************************!*\ /*!******************!*\
!*** /home/samilyas/www/flarum/packages/core/js/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js ***! !*** ./admin.js ***!
\***********************************************************************************************************/ \******************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _src_admin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/admin */ "./src/admin/index.js");
/* empty/unused harmony star reexport */
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js":
/*!******************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js ***!
\******************************************************************/
/*! exports provided: default */ /*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) { /***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _inheritsLoose; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _inheritsLoose; });
/* harmony import */ var _setPrototypeOf_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./setPrototypeOf.js */ "../../core/js/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js"); /* harmony import */ var _setPrototypeOf_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./setPrototypeOf.js */ "./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js");
function _inheritsLoose(subClass, superClass) { function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype); subClass.prototype = Object.create(superClass.prototype);
@ -107,10 +121,10 @@ function _inheritsLoose(subClass, superClass) {
/***/ }), /***/ }),
/***/ "../../core/js/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js": /***/ "./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js":
/*!************************************************************************************************************!*\ /*!*******************************************************************!*\
!*** /home/samilyas/www/flarum/packages/core/js/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js ***! !*** ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js ***!
\************************************************************************************************************/ \*******************************************************************/
/*! exports provided: default */ /*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) { /***/ (function(module, __webpack_exports__, __webpack_require__) {
@ -128,20 +142,6 @@ function _setPrototypeOf(o, p) {
/***/ }), /***/ }),
/***/ "./admin.js":
/*!******************!*\
!*** ./admin.js ***!
\******************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _src_admin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/admin */ "./src/admin/index.js");
/* empty/unused harmony star reexport */
/***/ }),
/***/ "./src/admin/components/Installer.tsx": /***/ "./src/admin/components/Installer.tsx":
/*!********************************************!*\ /*!********************************************!*\
!*** ./src/admin/components/Installer.tsx ***! !*** ./src/admin/components/Installer.tsx ***!
@ -152,7 +152,7 @@ __webpack_require__.r(__webpack_exports__);
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Installer; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Installer; });
/* harmony import */ var _babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/inheritsLoose */ "../../core/js/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"); /* harmony import */ var _babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/inheritsLoose */ "./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js");
/* harmony import */ var flarum_admin_app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! flarum/admin/app */ "flarum/admin/app"); /* harmony import */ var flarum_admin_app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! flarum/admin/app */ "flarum/admin/app");
/* harmony import */ var flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_app__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_app__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var flarum_common_Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! flarum/common/Component */ "flarum/common/Component"); /* harmony import */ var flarum_common_Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! flarum/common/Component */ "flarum/common/Component");
@ -161,6 +161,9 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! flarum/common/utils/Stream */ "flarum/common/utils/Stream"); /* harmony import */ var flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! flarum/common/utils/Stream */ "flarum/common/utils/Stream");
/* harmony import */ var flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(flarum_common_utils_Stream__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! flarum/admin/components/LoadingModal */ "flarum/admin/components/LoadingModal");
/* harmony import */ var flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_5__);
@ -227,20 +230,23 @@ var Installer = /*#__PURE__*/function (_Component) {
var _this2 = this; var _this2 = this;
this.isLoading = true; this.isLoading = true;
flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.modal.show(flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_5___default.a);
flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.request({ flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.request({
method: 'POST', method: 'POST',
url: flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.forum.attribute('apiUrl') + "/package-manager/extensions", url: flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.forum.attribute('apiUrl') + "/package-manager/extensions",
body: { body: {
data: this.data() data: this.data()
} }
}).then(function () { }).then(function (response) {
_this2.isLoading = false; var extensionId = response.data.attributes.id;
flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.alerts.show({ flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.alerts.show({
type: 'success', type: 'success'
message: flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.translator.trans('core.lib.success') }, flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.translator.trans('sycho-package-manager.admin.extensions.successful_install', {
}); extension: extensionId
m.redraw(); }));
})["catch"](function () { window.location.href = flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.forum.attribute('adminUrl') + "#/extension/" + extensionId;
window.location.reload();
})["finally"](function () {
_this2.isLoading = false; _this2.isLoading = false;
m.redraw(); m.redraw();
}); });
@ -270,7 +276,10 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! flarum/common/components/Button */ "flarum/common/components/Button"); /* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! flarum/common/components/Button */ "flarum/common/components/Button");
/* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Button__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _components_Installer__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./components/Installer */ "./src/admin/components/Installer.tsx"); /* harmony import */ var flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! flarum/admin/components/LoadingModal */ "flarum/admin/components/LoadingModal");
/* harmony import */ var flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _components_Installer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./components/Installer */ "./src/admin/components/Installer.tsx");
@ -278,7 +287,7 @@ __webpack_require__.r(__webpack_exports__);
flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.initializers.add('sycho-package-manager', function (app) { flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.initializers.add('sycho-package-manager', function (app) {
app.extensionData["for"]('sycho-package-manager').registerSetting(function () { app.extensionData["for"]('sycho-package-manager').registerSetting(function () {
return m(_components_Installer__WEBPACK_IMPORTED_MODULE_4__["default"], null); return m(_components_Installer__WEBPACK_IMPORTED_MODULE_5__["default"], null);
}); });
Object(flarum_common_extend__WEBPACK_IMPORTED_MODULE_0__["extend"])(flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2___default.a.prototype, 'topItems', function (items) { Object(flarum_common_extend__WEBPACK_IMPORTED_MODULE_0__["extend"])(flarum_admin_components_ExtensionPage__WEBPACK_IMPORTED_MODULE_2___default.a.prototype, 'topItems', function (items) {
var _this = this; var _this = this;
@ -287,14 +296,17 @@ flarum_admin_app__WEBPACK_IMPORTED_MODULE_1___default.a.initializers.add('sycho-
className: "Button Button--danger", className: "Button Button--danger",
icon: "fas fa-times", icon: "fas fa-times",
onclick: function onclick() { onclick: function onclick() {
app.modal.show(flarum_admin_components_LoadingModal__WEBPACK_IMPORTED_MODULE_4___default.a);
app.request({ app.request({
url: app.forum.attribute('apiUrl') + "/package-manager/extensions/" + _this.extension.id, url: app.forum.attribute('apiUrl') + "/package-manager/extensions/" + _this.extension.id,
method: 'DELETE' method: 'DELETE'
}).then(function () { }).then(function () {
app.alerts.show({ app.alerts.show({
type: 'success', type: 'success'
message: 'Success!' }, app.translator.trans('sycho-package-manager.admin.extensions.successful_remove'));
}); window.location = app.forum.attribute('adminUrl');
})["finally"](function () {
app.modal.close();
}); });
} }
}, "Remove")); }, "Remove"));
@ -325,6 +337,17 @@ module.exports = flarum.core.compat['admin/components/ExtensionPage'];
/***/ }), /***/ }),
/***/ "flarum/admin/components/LoadingModal":
/*!**********************************************************************!*\
!*** external "flarum.core.compat['admin/components/LoadingModal']" ***!
\**********************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = flarum.core.compat['admin/components/LoadingModal'];
/***/ }),
/***/ "flarum/common/Component": /***/ "flarum/common/Component":
/*!*********************************************************!*\ /*!*********************************************************!*\
!*** external "flarum.core.compat['common/Component']" ***! !*** external "flarum.core.compat['common/Component']" ***!

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ import app from 'flarum/admin/app';
import Component from 'flarum/common/Component'; import Component from 'flarum/common/Component';
import Button from "flarum/common/components/Button"; import Button from "flarum/common/components/Button";
import Stream from "flarum/common/utils/Stream"; import Stream from "flarum/common/utils/Stream";
import LoadingModal from "flarum/admin/components/LoadingModal";
export default class Installer extends Component { export default class Installer extends Component {
packageName!: Stream<string>; packageName!: Stream<string>;
@ -39,6 +40,7 @@ export default class Installer extends Component {
onsubmit(): void { onsubmit(): void {
this.isLoading = true; this.isLoading = true;
app.modal.show(LoadingModal);
app.request({ app.request({
method: 'POST', method: 'POST',
@ -46,11 +48,12 @@ export default class Installer extends Component {
body: { body: {
data: this.data() data: this.data()
}, },
}).then(() => { }).then((response) => {
this.isLoading = false; const extensionId = response.data.attributes.id;
app.alerts.show({ type: 'success', message: app.translator.trans('core.lib.success')}); app.alerts.show({ type: 'success' }, app.translator.trans('sycho-package-manager.admin.extensions.successful_install', { extension: extensionId }));
m.redraw(); window.location.href = `${app.forum.attribute('adminUrl')}#/extension/${extensionId}`;
}).catch(() => { window.location.reload();
}).finally(() => {
this.isLoading = false; this.isLoading = false;
m.redraw(); m.redraw();
}); });

View File

@ -2,6 +2,7 @@ import { extend } from 'flarum/common/extend';
import app from 'flarum/admin/app'; import app from 'flarum/admin/app';
import ExtensionPage from 'flarum/admin/components/ExtensionPage'; import ExtensionPage from 'flarum/admin/components/ExtensionPage';
import Button from 'flarum/common/components/Button'; import Button from 'flarum/common/components/Button';
import LoadingModal from 'flarum/admin/components/LoadingModal';
import Installer from "./components/Installer"; import Installer from "./components/Installer";
app.initializers.add('sycho-package-manager', (app) => { app.initializers.add('sycho-package-manager', (app) => {
@ -20,11 +21,16 @@ app.initializers.add('sycho-package-manager', (app) => {
className="Button Button--danger" className="Button Button--danger"
icon="fas fa-times" icon="fas fa-times"
onclick={() => { onclick={() => {
app.modal.show(LoadingModal);
app.request({ app.request({
url: `${app.forum.attribute('apiUrl')}/package-manager/extensions/${this.extension.id}`, url: `${app.forum.attribute('apiUrl')}/package-manager/extensions/${this.extension.id}`,
method: 'DELETE', method: 'DELETE',
}).then(() => { }).then(() => {
app.alerts.show({ type: 'success', message: 'Success!' }); app.alerts.show({ type: 'success' }, app.translator.trans('sycho-package-manager.admin.extensions.successful_remove'));
window.location = app.forum.attribute('adminUrl');
}).finally(() => {
app.modal.close();
}); });
}}> }}>
Remove Remove

View File

@ -1,7 +1,9 @@
sycho-package-manager: sycho-package-manager:
admin: admin:
extensions: extensions:
install: Install a new extension install: Install a new extension
install_help: Fill in the extension package name to proceed. Visit {extiverse} to browse extensions. install_help: Fill in the extension package name to proceed. Visit {extiverse} to browse extensions.
proceed: Proceed proceed: Proceed
successful_install: "{extension} was installed successfully, redirecting.."
successful_remove: Extension removed successfully.

View File

@ -31,10 +31,8 @@ class RequireExtensionController extends AbstractCreateController
$actor = RequestUtil::getActor($request); $actor = RequestUtil::getActor($request);
$package = Arr::get($request->getParsedBody(), 'data.package'); $package = Arr::get($request->getParsedBody(), 'data.package');
$this->bus->dispatch( return $this->bus->dispatch(
new RequireExtension($actor, $package) new RequireExtension($actor, $package)
); );
return null;
} }
} }

View File

@ -33,10 +33,8 @@ class UpdateExtensionController extends AbstractShowController
$actor = RequestUtil::getActor($request); $actor = RequestUtil::getActor($request);
$extensionId = Arr::get($request->getQueryParams(), 'id'); $extensionId = Arr::get($request->getQueryParams(), 'id');
$this->bus->dispatch( return $this->bus->dispatch(
new UpdateExtension($actor, $extensionId) new UpdateExtension($actor, $extensionId)
); );
return null;
} }
} }

View File

@ -0,0 +1,27 @@
<?php
namespace SychO\PackageManager\Api\Serializer;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Extension\Extension;
use InvalidArgumentException;
class ExtensionSerializer extends AbstractSerializer
{
protected $type = 'extensions';
protected function getDefaultAttributes($model)
{
if (is_array($model)) {
return $model;
}
if (! ($model instanceof Extension)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Extension::class
);
}
return $model->toArray();
}
}

View File

@ -2,25 +2,27 @@
namespace SychO\PackageManager\Command; namespace SychO\PackageManager\Command;
use Composer\Console\Application;
use Flarum\Extension\ExtensionManager; use Flarum\Extension\ExtensionManager;
use SychO\PackageManager\Extension\PackageManager; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
class RemoveExtensionHandler class RemoveExtensionHandler
{ {
/**
* @var Application
*/
protected $composer;
/** /**
* @var ExtensionManager * @var ExtensionManager
*/ */
protected $extensions; protected $extensions;
/** public function __construct(Application $composer, ExtensionManager $extensions,)
* @var PackageManager
*/
protected $packages;
public function __construct(ExtensionManager $extensions, PackageManager $packages)
{ {
$this->composer = $composer;
$this->extensions = $extensions; $this->extensions = $extensions;
$this->packages = $packages;
} }
/** /**
@ -37,6 +39,12 @@ class RemoveExtensionHandler
// ... exception // ... exception
} }
$this->packages->removePackage($extension->name); $output = new BufferedOutput();
$input = new ArrayInput([
'command' => 'remove',
'packages' => [$extension->name],
]);
$this->composer->run($input, $output);
} }
} }

View File

@ -2,46 +2,34 @@
namespace SychO\PackageManager\Command; namespace SychO\PackageManager\Command;
use Composer\Command\RequireCommand;
use Composer\Config;
use Composer\Console\Application; use Composer\Console\Application;
use Flarum\Extension\ExtensionManager; use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Console\Kernel;
use SychO\PackageManager\Extension\ExtensionUtils; use SychO\PackageManager\Extension\ExtensionUtils;
use SychO\PackageManager\Extension\PackageManager;
use SychO\PackageManager\RequirePackageValidator; use SychO\PackageManager\RequirePackageValidator;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\BufferedOutput;
class RequireExtensionHandler class RequireExtensionHandler
{ {
/**
* @var Application
*/
protected $composer;
/** /**
* @var ExtensionManager * @var ExtensionManager
*/ */
protected $extensions; protected $extensions;
/**
* @var PackageManager
*/
protected $packages;
/**
* @var RequireCommand
*/
protected $command;
/** /**
* @var RequirePackageValidator * @var RequirePackageValidator
*/ */
protected $validator; protected $validator;
public function __construct(ExtensionManager $extensions, PackageManager $packages, RequireCommand $command, RequirePackageValidator $validator) public function __construct(Application $composer, ExtensionManager $extensions, RequirePackageValidator $validator)
{ {
$this->composer = $composer;
$this->extensions = $extensions; $this->extensions = $extensions;
$this->packages = $packages;
$this->command = $command;
$this->validator = $validator; $this->validator = $validator;
} }
@ -56,36 +44,20 @@ class RequireExtensionHandler
$this->validator->assertValid(['package' => $command->package]); $this->validator->assertValid(['package' => $command->package]);
$extensionId = ExtensionUtils::nameToId($command->package); $extensionId = ExtensionUtils::nameToId($command->package);
$extension = $this->extensions->getExtension($extensionId);
if (! empty($this->extensions->getExtension($extensionId))) { if (! empty($extension)) {
// ... exception // ... exception
} }
// $this->packages->requirePackage($command->package);
$paths = resolve(Paths::class);
putenv("COMPOSER_HOME={$paths->storage}/.composer");
putenv("COMPOSER={$paths->base}/composer.json");
Config::$defaultConfig['vendor-dir'] = $paths->base.'/vendor';
@ini_set('memory_limit', '1G');
@set_time_limit(5 * 60);
$application = new Application();
$application->setAutoExit(false);
$output = new BufferedOutput(); $output = new BufferedOutput();
$input = new ArrayInput([ $input = new ArrayInput([
'command' => 'require', 'command' => 'require',
'packages' => [$command->package], 'packages' => [$command->package],
// '--dry-run' => true,
]); ]);
$application->run($input, $output); $this->composer->run($input, $output);
error_log('nandeeeeeeeeeeeeeee'); return ['id' => $extensionId];
throw new \Exception($output->fetch());
} }
} }

View File

@ -0,0 +1,38 @@
<?php
namespace SychO\PackageManager;
use Composer\Config;
use Composer\Console\Application;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Container\Container;
class PackageManagerServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->container->singleton(Application::class, function (Container $container) {
// This should only ever be resolved when running composer commands,
// because we modify other environment configurations.
$composer = new Application();
$composer->setAutoExit(false);
$paths = $container->make(Paths::class);
putenv("COMPOSER_HOME={$paths->storage}/.composer");
putenv("COMPOSER={$paths->base}/composer.json");
Config::$defaultConfig['vendor-dir'] = $paths->base.'/vendor';
// When running simple require, update and remove commands on packages,
// composer 2 doesn't really need this much unless the extensions are very loaded dependency wise,
// but this is necessary for running flarum updates.
@ini_set('memory_limit', '1G');
@set_time_limit(5 * 60);
return $composer;
});
$this->container->alias(Application::class, 'flarum.composer');
}
}