Manual:Hooks/LoadExtensionSchemaUpdates/cs

Obsah 1	Použití 1.1	Summary 1.2	>= 1.25 2	Související stránky LoadExtensionSchemaUpdates Available from version 1.10.1 Fired when MediaWiki is updated to allow extensions to register updates for the database schema Define function: public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { ... } Attach hook:	In extension.json: {	"Hooks": { "LoadExtensionSchemaUpdates": "MyExtensionHooks::onLoadExtensionSchemaUpdates" } } Called from:	File(s): installer/DatabaseUpdater.php Function(s): __construct Interface:	LoadExtensionSchemaUpdatesHook.php For more information about attaching hooks, see Manual:Hooks. For examples of extensions using this hook, see Category:LoadExtensionSchemaUpdates extensions.

Použití 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::changeExtensionField, etc. Warning Warning:	If your extension is used on any production WMF-hosted wiki please follow the Schema change guide. Warning Warning:	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::changeExtensionField, etc. Warning Warning:	Your extension should not modify any MW core database. Instead, the extension should create new tables with foreign key to the relevant MW table. Summary 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’s LoadExtensionSchemaUpdates hook. See the update.php manual for more information. >= 1.25 Extension registration was introduced in 1.25, and so the Hooks section of extension.json should be used instead of $wgHooks. For example:

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

Související stránky 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 DatabaseUpdater's generated documentation vte Databases Engines Current MySQL/MariaDBPostgreSQLSQLite Former OracleSQL Server Technical documentation Schema (tables)API property associationsField prefixesPrimary key storage in other fieldsWikimedia extension tables Configuration SettingsSharing Development AccessOptimizationPolicyUpdaterExtension schema updatesPatch file Core tables Current actorarchivebot_passwordscategorycategorylinkschange_tagchange_tag_defcommentcontentcontent_modelsexternallinksfilearchiveimageimagelinksinterwikiiwlinksipblocksipblocks_restrictionsip_changesjobl10n_cachelanglinkslinktargetlogginglog_searchmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionrevision_actor_temprevision_comment_tempsearchindexsitessite_identifierssite_statsslotsslot_rolestemplatelinkstextupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertieswatchlistwatchlist_expiry Former blobsbrokenlinksconfigcurexternal_userhitcounterimage_comment_tempipblocks_oldlinkslinksccmathmsg_resourcemsg_resource_linksoldprofilingtag_summarytrackbackstranscacheuser_rightsvalid_tagvalidate