From c829ee1501d8b9df209b82d6e9e00c23c96bd3ba Mon Sep 17 00:00:00 2001 From: Robert Vogel <1201528+osnard@users.noreply.github.com> Date: Mon, 7 Feb 2022 16:11:43 +0100 Subject: [PATCH] Use new `componentloader` (#7) * Use `ComponentLoader` * Add new init requirement to `README.md` Co-authored-by: rvogel --- README.md | 8 ++++++- bootstrap.php | 61 +++++++++++++++++++++++++++------------------------ composer.json | 3 +++ 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 3507981..9411e21 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,13 @@ The frequency of that job determines the minimum frequency at which handlers can ## Use in a MediaWiki extension -Add `"mwstake/mediawiki-component-runjobstrigger": "~1.0"` to the `require` section of your `composer.json` file. +Add `"mwstake/mediawiki-component-runjobstrigger": "~2.0"` to the `require` section of your `composer.json` file. + +Since 2.0 explicit initialization is required. This can be archived by +- either adding `"callback": "mwsInitComponents"` to your `extension.json`/`skin.json` +- or calling `mwsInitComponents();` within you extensions/skins custom `callback` method + +See also [`mwstake/mediawiki-componentloader`](https://github.com/hallowelt/mwstake-mediawiki-componentloader). ### Implement a handler diff --git a/bootstrap.php b/bootstrap.php index 0293b07..21517b3 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -6,32 +6,35 @@ define( 'MWSTAKE_MEDIAWIKI_COMPONENT_RUNJOBSTRIGGER_VERSION', '1.0.0' ); -$GLOBALS['mwsgRunJobsTriggerOptions'] = [ - "*" => [ - "basetime" => [ 1, 0, 0 ], - "once-a-week-day" => "sunday" - ] -]; - -$GLOBALS['mwsgRunJobsTriggerHandlerRegistry'] = []; - -$GLOBALS['mwsgRunJobsTriggerHandlerFactories'] = [ - 'globalvars-config' => [ - 'class' => "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\HandlerFactory\\GlobalVars" - ], - 'hook' => [ - 'class' => "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\HandlerFactory\\Hook", - 'services' => [ 'MainConfig' ] - ] -]; - -$GLOBALS['mwsgRunJobsTriggerRunnerWorkingDir'] = sys_get_temp_dir(); - -$GLOBALS['wgJobClasses']['invokeRunner'] - = "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\Job\\InvokeRunner"; - -$GLOBALS['wgExtensionFunctions'][] - = "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\Runner::runDeferred"; - -$GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = "\\MWStake\\MediaWiki\\Component\\" - . "RunJobsTrigger\\Hook\\LoadExtensionSchemaUpdates\\ClearJSONFiles::callback"; +MWStake\MediaWiki\ComponentLoader\Bootstrapper::getInstance() +->register( 'runjobstrigger', function () { + $GLOBALS['mwsgRunJobsTriggerOptions'] = [ + "*" => [ + "basetime" => [ 1, 0, 0 ], + "once-a-week-day" => "sunday" + ] + ]; + + $GLOBALS['mwsgRunJobsTriggerHandlerRegistry'] = []; + + $GLOBALS['mwsgRunJobsTriggerHandlerFactories'] = [ + 'globalvars-config' => [ + 'class' => "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\HandlerFactory\\GlobalVars" + ], + 'hook' => [ + 'class' => "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\HandlerFactory\\Hook", + 'services' => [ 'MainConfig' ] + ] + ]; + + $GLOBALS['mwsgRunJobsTriggerRunnerWorkingDir'] = sys_get_temp_dir(); + + $GLOBALS['wgJobClasses']['invokeRunner'] + = "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\Job\\InvokeRunner"; + + $GLOBALS['wgExtensionFunctions'][] + = "\\MWStake\\MediaWiki\\Component\\RunJobsTrigger\\Runner::runDeferred"; + + $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = "\\MWStake\\MediaWiki\\Component\\" + . "RunJobsTrigger\\Hook\\LoadExtensionSchemaUpdates\\ClearJSONFiles::callback"; +} ); diff --git a/composer.json b/composer.json index 30cfeed..8958b86 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,9 @@ "email": "support@bluespice.com" } ], + "require": { + "mwstake/mediawiki-componentloader": "~1" + }, "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", "jakub-onderka/php-console-highlighter": "0.4.0",