mirror of
https://github.com/flarum/framework.git
synced 2025-03-05 00:26:23 +08:00
![dependabot[bot]](/assets/img/avatar_default.png)
* chore(deps): bump glob-parent in /extensions/emoji/js Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 3.1.0 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](https://github.com/gulpjs/glob-parent/compare/v3.1.0...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Apply fixes from StyleCI [ci skip] [skip ci] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
98 lines
3.7 KiB
PHP
Executable File
98 lines
3.7 KiB
PHP
Executable File
<?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 Composer\Config;
|
|
use Composer\Console\Application;
|
|
use Flarum\Extension\ExtensionManager;
|
|
use Flarum\Foundation\AbstractServiceProvider;
|
|
use Flarum\Foundation\Paths;
|
|
use Flarum\Frontend\RecompileFrontendAssets;
|
|
use Flarum\Locale\LocaleManager;
|
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
|
use Flarum\PackageManager\Event\FlarumUpdated;
|
|
use Flarum\PackageManager\Extension\Event\Updated;
|
|
use Flarum\PackageManager\Listener\ClearCacheAfterUpdate;
|
|
use Flarum\PackageManager\Listener\ReCheckForUpdates;
|
|
use Illuminate\Contracts\Container\Container;
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
|
use Monolog\Formatter\LineFormatter;
|
|
use Monolog\Handler\RotatingFileHandler;
|
|
use Monolog\Logger;
|
|
|
|
class PackageManagerServiceProvider extends AbstractServiceProvider
|
|
{
|
|
public function register()
|
|
{
|
|
$this->container->singleton(ComposerAdapter::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);
|
|
|
|
/** @var Paths $paths */
|
|
$paths = $container->make(Paths::class);
|
|
|
|
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,
|
|
// 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 new ComposerAdapter($composer, $container->make(OutputLogger::class), $container->make(Paths::class));
|
|
});
|
|
|
|
$this->container->alias(ComposerAdapter::class, 'flarum.composer');
|
|
|
|
$this->container->singleton(OutputLogger::class, function (Container $container) {
|
|
$logPath = $container->make(Paths::class)->storage.'/logs/composer/output.log';
|
|
$handler = new RotatingFileHandler($logPath, Logger::INFO);
|
|
$handler->setFormatter(new LineFormatter(null, null, true, true));
|
|
|
|
$logger = new Logger('composer', [$handler]);
|
|
|
|
return new OutputLogger($logger);
|
|
});
|
|
}
|
|
|
|
public function boot(Container $container)
|
|
{
|
|
/** @var Dispatcher $events */
|
|
$events = $container->make('events');
|
|
|
|
$events->listen(
|
|
[Updated::class],
|
|
function (Updated $event) use ($container) {
|
|
/** @var ExtensionManager $extensions */
|
|
$extensions = $container->make(ExtensionManager::class);
|
|
|
|
if ($extensions->isEnabled($event->extension->getId())) {
|
|
$recompile = new RecompileFrontendAssets(
|
|
$container->make('flarum.assets.forum'),
|
|
$container->make(LocaleManager::class)
|
|
);
|
|
$recompile->flush();
|
|
|
|
$extensions->migrate($event->extension);
|
|
$event->extension->copyAssetsTo($container->make('filesystem')->disk('flarum-assets'));
|
|
}
|
|
}
|
|
);
|
|
|
|
$events->listen(FlarumUpdated::class, ClearCacheAfterUpdate::class);
|
|
$events->listen([FlarumUpdated::class, Updated::class], ReCheckForUpdates::class);
|
|
}
|
|
}
|