Manuel:Accroches/LoadExtensionSchemaUpdates
Appearance
LoadExtensionSchemaUpdates | |
---|---|
Disponible depuis version 1.10.1 Déclenché lorsque MediaWiki est mis à jour pour permettre aux extensions d'enregistrer les mises à jour du schéma de base de données | |
Fonction à définir : | public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { ... }
|
Attacher l'accroche : | Dans extension.json :
{
"Hooks": {
"LoadExtensionSchemaUpdates": "MediaWiki\\Extension\\MyExtension\\Hooks::onLoadExtensionSchemaUpdates"
}
}
|
Appelé de : | Fichier(s) : installer/DatabaseUpdater.php Fonction(s) : __construct |
Interface : | LoadExtensionSchemaUpdatesHook.php |
Pour plus d'information sur l'ajout des accroches (hooks), voir Manuel:Accroches .
Pour des exemples d'extensions utilisant cette accroche, voir Category:LoadExtensionSchemaUpdates extensions/fr .
Utilisation
If your extension requires changes to the database when MediaWiki is updated, use this hook to add them to the updater using methods like
DatabaseUpdater::addExtensionTable()
, DatabaseUpdater::modifyExtensionField()
, etc.
Résumé
- Create your hook as indicated below. The example shows how to setup the hook function. If you have more than one schema update, you can put them in the same function. Make sure you are using the methods with Extension in the name to register the updates, rather than execute them directly.
- Make sure the hook has access to any necessary SQL files, which are usually located in an
sql/
directory. - Format the SQL files correctly. See the ArticleFeedbackv5 SQL, and the corresponding hooks file, for some examples.
- From the command line run the
php maintenance/update.php
script to update your wiki’s database with your extension’sLoadExtensionSchemaUpdates
hook. See the update.php manual for more information.
>= 1.25
Extension registration was introduced in MW 1.25, and so the Hooks section of extension.json
should be used instead of $wgHooks .
Par exemple :
"Hooks": {
"LoadExtensionSchemaUpdates": "MediaWiki\\Extension\\ExtensionName\\Hooks::onLoadExtensionSchemaUpdates"
}
And in ExtensionName/includes/Hooks.php
:
namespace MediaWiki\Extension\ExtensionName;
use DatabaseUpdater;
class Hooks {
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
// Register an SQL patch for changing the field
$updater->modifyExtensionField(
'tablename',
'name_of_field',
__DIR__ . '/sql/patch_file_changing_field.sql'
);
}
}
The code of the hook callback is the same as for earlier versions (see below).
Voir aussi
- Manual:Hooks/ParserTestTables – This hook may also be necessary if your extension changes the behavior of the parser (parser functions, tag hooks, etc.)
- Manual:SQL patch file
- class MediaWiki\Installer\DatabaseUpdater's generated documentation