saper has uploaded a new change for review.
https://gerrit.wikimedia.org/r/260173
Change subject: Non-destructive migration, allow update on 1.24.
......................................................................
Non-destructive migration, allow update on 1.24.
Allow old-style registration and update on 1.24 - just run
the updater, anticipating 1.25+ core upgrade.
Change-Id: I17cc6fa601d2921d539303a06ea90b7c294c690c
---
M HCUpdater.php
M HitCounters.hooks.php
M HitCounters.php
M README.md
R create_hit_counter.sql
R create_hit_counter_extension.sql
D drop_field.sql
M extension.json
A migrate_hitcounter.sql
A migrate_page_counter.sql
D rename_table.sql
11 files changed, 47 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HitCounters
refs/changes/73/260173/1
diff --git a/HCUpdater.php b/HCUpdater.php
index 331f2fa..f2cf3ac 100644
--- a/HCUpdater.php
+++ b/HCUpdater.php
@@ -6,19 +6,21 @@
use Installer;
use MWException;
-/* hack to get at protected member */
+// hack to get at protected member
class HCUpdater extends DatabaseUpdater {
public static function getDBUpdates ( DatabaseUpdater $updater ) {
- /* This is an ugly abuse to rename a table. */
+ // This is an ugly abuse to rename a table.
$updater->modifyExtensionField( 'hitcounter',
'hc_id',
- __DIR__ . '/rename_table.sql' );
- $updater->addExtensionTable( 'hit_counter_extension',
- __DIR__ . '/hit_counter_extension.sql', true );
+ __DIR__ . '/migrate_hitcounter.sql' );
$updater->addExtensionTable( 'hit_counter',
- __DIR__ . '/page_counter.sql', true );
- $updater->dropExtensionField( 'page', 'page_counter',
- __DIR__ . '/drop_field.sql' );
+ __DIR__ . '/migrate_page_counter.sql' );
+
+ # If we couldn't migrate, try to create
+ $updater->addExtensionTable( 'hit_counter_extension',
+ __DIR__ . '/create_hit_counter_extension.sql', true );
+ $updater->addExtensionTable( 'hit_counter',
+ __DIR__ . '/create_hit_counter.sql', true );
}
public function clearExtensionUpdates() {
@@ -44,4 +46,9 @@
}
}
+ public static function onLoadExtensionSchemaUpdates(
+ DatabaseUpdater $updater
+ ) {
+ HCUpdater::getDBUpdates( $updater );
+ }
}
diff --git a/HitCounters.hooks.php b/HitCounters.hooks.php
index f38e388..7af3294 100644
--- a/HitCounters.hooks.php
+++ b/HitCounters.hooks.php
@@ -29,12 +29,6 @@
$specialPages['PopularPages'] =
'HitCounters\SpecialPopularPages';
}
- public static function onLoadExtensionSchemaUpdates(
- DatabaseUpdater $updater
- ) {
- HCUpdater::getDBUpdates( $updater );
- }
-
public static function onSpecialStatsAddExtra(
array &$extraStats, RequestContext $statsPage
) {
diff --git a/HitCounters.php b/HitCounters.php
index 706aab4..ae05e40 100644
--- a/HitCounters.php
+++ b/HitCounters.php
@@ -11,7 +11,7 @@
* @copyright 2015 Mark A. Hershberger
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public
License, version 3
* (or later)
- * @version GIT: 0.3
+ * @version GIT: 0.4
* @link https://www.mediawiki.org/wiki/Extension:HitCounters
*/
@@ -35,9 +35,10 @@
* @file
*/
-call_user_func(
- function () {
- if ( function_exists( 'wfLoadExtension' ) ) {
+
+if ( function_exists( 'wfLoadExtension' ) ) {
+ call_user_func(
+ function () {
wfLoadExtension( 'HitCounters' );
wfWarn(
'Deprecated PHP entry point used for HitCounters
extension. ' .
@@ -46,8 +47,9 @@
'for more details.'
);
return;
- } else {
- die( 'This extension requires MediaWiki 1.25+' );
- }
- }
-);
+ });
+} else {
+ global $wgAutoloadClasses, $wgHooks;
+ $wgAutoloadClasses['HitCounters\\HCUpdater'] = __DIR__ .
'/HCUpdater.php';
+ $wgHooks['LoadExtensionSchemaUpdates'][] =
'HitCounters\\HCUpdater::onLoadExtensionSchemaUpdates';
+}
diff --git a/README.md b/README.md
index 61337bb..047dade 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,19 @@
If you wish to continue using the HitCounter's despite the flawed
implementation, this extension should help.
-Note that some steps will be needed to maintain you current hit
-count. When those steps are understood, they'll be documented.
+== Migrating page counters ==
+This extension can be installed first on the 1.24 (or older)
+in order to migrate data. Add the extension to LocalSettings.php:
+
+ require_only( "$IP/extensions/HitCounters/HitCounters.php" );
+
+and run update.php.
+
+For MediaWiki 1.25 (after update) replace the 'require_only' line
+in LocalSettings.php with:
+
+ wfLoadExtension( 'HitCounters' );
+
+It is mandatory to have a good working database backup before running
+above operations.
diff --git a/page_counter.sql b/create_hit_counter.sql
similarity index 72%
rename from page_counter.sql
rename to create_hit_counter.sql
index 420e59e..f2331cb 100644
--- a/page_counter.sql
+++ b/create_hit_counter.sql
@@ -2,5 +2,3 @@
page_id INT(8) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
page_counter BIGINT(20) UNSIGNED NOT NULL DEFAULT '0'
) /*$wgDBTableOptions*/;
-
-CREATE INDEX /*i*/page_counter ON /*_*/hit_counter (page_counter);
\ No newline at end of file
diff --git a/hit_counter_extension.sql b/create_hit_counter_extension.sql
similarity index 100%
rename from hit_counter_extension.sql
rename to create_hit_counter_extension.sql
diff --git a/drop_field.sql b/drop_field.sql
deleted file mode 100644
index d4159e3..0000000
--- a/drop_field.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO /*_*/hit_counter (page_id, page_counter) SELECT /*_*/page.page_id,
/*_*/page.page_counter FROM /*_*/page;
-ALTER TABLE /*_*/page DROP page_counter;
diff --git a/extension.json b/extension.json
index 1826005..7d25684 100644
--- a/extension.json
+++ b/extension.json
@@ -1,7 +1,7 @@
{
"name": "HitCounters",
"namemsg": "hitcounters-extensionname",
- "version": "0.3",
+ "version": "0.4",
"author": [
"[//mwstake.org Mark A. Hershberger]"
],
@@ -29,7 +29,7 @@
"HitCounters\\Hooks::onSpecialStatsAddExtra"
],
"LoadExtensionSchemaUpdates": [
- "HitCounters\\Hooks::onLoadExtensionSchemaUpdates"
+ "HitCounters\\HCUpdater::onLoadExtensionSchemaUpdates"
],
"MagicWordwgVariableIDs": [
"HitCounters\\Hooks::onMagicWordwgVariableIDs"
@@ -53,6 +53,7 @@
"ViewCountUpdate": "ViewCountUpdate.php",
"HitCounters\\SpecialPopularPages": "SpecialPopularPages.php",
"HitCounters\\HCUpdater": "HCUpdater.php"
+
},
"config": {
"HitcounterUpdateFreq": 1,
diff --git a/migrate_hitcounter.sql b/migrate_hitcounter.sql
new file mode 100644
index 0000000..23e7559
--- /dev/null
+++ b/migrate_hitcounter.sql
@@ -0,0 +1,2 @@
+CREATE TABLE /*_*/hit_counter_extension ENGINE=MEMORY MAX_ROWS=25000
+AS SELECT hc_id FROM /*_*/hitcounter;
diff --git a/migrate_page_counter.sql b/migrate_page_counter.sql
new file mode 100644
index 0000000..31b4314
--- /dev/null
+++ b/migrate_page_counter.sql
@@ -0,0 +1 @@
+CREATE TABLE /*_*/hit_counter /*$wgDBTableOptions*/ AS SELECT page_id,
page_counter FROM page;
diff --git a/rename_table.sql b/rename_table.sql
deleted file mode 100644
index 56d8e42..0000000
--- a/rename_table.sql
+++ /dev/null
@@ -1 +0,0 @@
-RENAME TABLE /*_*/hitcounter TO /*_*/hit_counter_extension;
--
To view, visit https://gerrit.wikimedia.org/r/260173
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I17cc6fa601d2921d539303a06ea90b7c294c690c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HitCounters
Gerrit-Branch: master
Gerrit-Owner: saper <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits