Jump to content

Manual:Hooks/LoadExtensionSchemaUpdates/ja

From mediawiki.org
This page is a translated version of the page Manual:Hooks/LoadExtensionSchemaUpdates and the translation is 15% complete.
LoadExtensionSchemaUpdates
バージョン 1.10.1 から利用可能
Fired when MediaWiki is updated to allow extensions to register updates for the database schema
関数の定義:
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { ... }
フックのアタッチ: extension.json 内:
{
	"Hooks": {
		"LoadExtensionSchemaUpdates": "MediaWiki\\Extension\\MyExtension\\Hooks::onLoadExtensionSchemaUpdates"
	}
}
呼び出し元: ファイル: Installer/DatabaseUpdater.php
関数: __construct
インターフェイス: LoadExtensionSchemaUpdatesHook.php

フックの設定についての詳細情報は Manual:フック を参照してください。
このフックを使用する拡張機能の例については、Category:LoadExtensionSchemaUpdates extensions/ja を参照してください。

使用法

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.
警告 警告:
  • If your extension is used on any production WMF-hosted wiki please follow the Schema change guide.
  • Handlers for this hook must not directly modify the database using methods like DatabaseUpdater::addTable(), DatabaseUpdater::dropField(), etc. They must only register updates, using methods like DatabaseUpdater::addExtensionTable(), DatabaseUpdater::modifyExtensionField(), etc.
  • Your extension should not modify any MW core database. Instead, the extension should create new tables with foreign key to the relevant MW table.

要約

  1. 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.
  2. Make sure the hook has access to any necessary SQL files, which are usually located in an sql/ directory.
  3. Format the SQL files correctly. See the ArticleFeedbackv5 SQL, and the corresponding hooks file, for some examples.
  4. From the command line run the php maintenance/run.php update script to update your wiki’s database with your extension’s LoadExtensionSchemaUpdates 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 . 例:

"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).

関連項目