r98782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98781‎ | r98782 | r98783 >
Date:17:38, 3 October 2011
Author:ashley
Status:deferred
Tags:
Comment:
FreqPatternTagCloud: move DB table generation out of the special page and use the LoadExtensionSchemaUpdates hook instead so that the user has to run update.php to add the new tables into the DB
Modified paths:
  • /trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.php (modified) (history)
  • /trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloudMaintenance.php (modified) (history)
  • /trunk/extensions/FreqPatternTagCloud/freqpatterntagcloud.sql (added) (history)

Diff [purge]

Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloudMaintenance.php
@@ -1,85 +1,45 @@
22 <?php
3 -
43 /**
54 * Frequent Pattern Tag Cloud Plug-in
65 * Special page for maintenance
7 - *
 6+ *
87 * @author Tobias Beck, University of Heidelberg
98 * @author Andreas Fay, University of Heidelberg
109 * @version 1.0
1110 */
1211
1312 class FreqPatternTagCloudMaintenance extends SpecialPage {
14 -
 13+
1514 /**
16 - * Constructor
17 - *
18 - * @return void
 15+ * Constructor -- set up the new special page
1916 */
2017 public function __construct() {
21 - parent::__construct("FreqPatternTagCloudMaintenance");
 18+ parent::__construct( 'FreqPatternTagCloudMaintenance' );
2219 }
23 -
24 -
 20+
2521 /**
2622 * Executes special page (will be called when accessing special page)
2723 *
28 - * @param string $par Content of GET-Parameter
29 - * @return void
 24+ * @param $par Mixed: parameter passed to the special page or null
3025 */
31 - public function execute($par) {
 26+ public function execute( $par ) {
3227 global $wgOut, $wgUser;
33 - $dbr =& wfGetDB( DB_SLAVE );
34 -
 28+
3529 $this->setHeaders();
36 -
37 - if (!$wgUser->isAllowed("protect")) {
 30+
 31+ if ( !$wgUser->isAllowed( 'protect' ) ) {
3832 // No admin
39 - $wgOut->addWikiText(wfMsg("fptc-insufficient-rights-for-maintenance"));
 33+ $wgOut->addWikiMsg( 'fptc-insufficient-rights-for-maintenance' );
4034 } else {
41 - // Check if this call is the first
42 - try {
43 - $dbr->query("SELECT COUNT(1) FROM ".$dbr->tableName("fptc_associationrules"));
44 - } catch (exception $e) {
45 - // Yes: create database tables
46 - $this->initSchema();
47 - }
48 -
4935 // Refresh frequent pattern rules
50 - include_once("includes/FrequentPattern.php");
51 -
 36+ include_once( "includes/FrequentPattern.php" );
 37+
5238 FrequentPattern::deleteAllRules();
5339 FrequentPattern::computeAllRules();
54 -
 40+
5541 // Notify user
56 - $wgOut->addWikiText(wfMsg("fptc-refreshed-frequent-patterns"));
 42+ $wgOut->addWikiMsg( 'fptc-refreshed-frequent-patterns' );
5743 }
5844 }
59 -
60 -
61 -
62 -
63 - /**
64 - * Creates database schema
65 - *
66 - * @return void
67 - */
68 - private function initSchema() {
69 - $dbw =& wfGetDB( DB_MASTER );
70 -
71 - $dbw->query("CREATE TABLE IF NOT EXISTS ".$dbw->tableName("fptc_associationrules")." (
72 - `rule_id` int(11) NOT NULL auto_increment,
73 - `p_id` int(8) NOT NULL COMMENT 'Attribute',
74 - `rule_support` float(5,3) NOT NULL,
75 - `rule_confidence` float(5,3) NOT NULL,
76 - PRIMARY KEY (`rule_id`)
77 - )");
78 - $dbw->query("ALTER TABLE ".$dbw->tableName("fptc_associationrules")." ADD INDEX ( `p_id` );");
79 - $dbw->query("CREATE TABLE IF NOT EXISTS ".$dbw->tableName("fptc_items")." (
80 - `o_id` INT( 8 ) NOT NULL ,
81 - `rule_id` INT NOT NULL ,
82 - `item_order` TINYINT( 1 ) NOT NULL ,
83 - PRIMARY KEY ( `o_id` , `rule_id` )
84 - );");
85 - }
 45+
8646 }
\ No newline at end of file
Index: trunk/extensions/FreqPatternTagCloud/freqpatterntagcloud.sql
@@ -0,0 +1,15 @@
 2+CREATE TABLE IF NOT EXISTS /*_*/fptc_associationrules (
 3+ `rule_id` int(11) NOT NULL PRIMARY KEY auto_increment,
 4+ `p_id` int(8) NOT NULL COMMENT 'Attribute',
 5+ `rule_support` float(5,3) NOT NULL,
 6+ `rule_confidence` float(5,3) NOT NULL
 7+)/*$wgDBTableOptions*/;
 8+
 9+CREATE INDEX /*i*/p_id ON fptc_associationrules (p_id);
 10+
 11+CREATE TABLE IF NOT EXISTS /*_*/fptc_items (
 12+ `o_id` INT(8) NOT NULL,
 13+ `rule_id` INT NOT NULL,
 14+ `item_order` TINYINT(1) NOT NULL,
 15+ PRIMARY KEY ( `o_id` , `rule_id` )
 16+)/*$wgDBTableOptions*/;
\ No newline at end of file
Property changes on: trunk/extensions/FreqPatternTagCloud/freqpatterntagcloud.sql
___________________________________________________________________
Added: svn:eol-style
117 + native
Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.php
@@ -35,6 +35,8 @@
3636 // Register hook to prepare header files
3737 $wgHooks['BeforePageDisplay'][] = 'fptc_initializeHeaders';
3838
 39+$wgHooks['LoadExtensionSchemaUpdates'][] = 'fptc_applySchemaChanges';
 40+
3941 // Register files
4042 $wgAutoloadClasses['FreqPatternTagCloud'] = FPTC_PATH_HOME . 'FreqPatternTagCloud.body.php';
4143 $wgExtensionMessagesFiles['FreqPatternTagCloud'] = FPTC_PATH_HOME . 'FreqPatternTagCloud.i18n.php';
@@ -83,4 +85,25 @@
8486 $wgOut->addScriptFile( $wgScriptPath . '/extensions/FreqPatternTagCloud/javascripts/main.js' );
8587
8688 return true;
 89+}
 90+
 91+
 92+/**
 93+ * Applies the schema changes when the user runs maintenance/update.php.
 94+ *
 95+ * @param $updater Object: instance of DatabaseUpdater
 96+ * @return Boolean: true
 97+ */
 98+function fptc_applySchemaChanges( $updater = null ) {
 99+ $dir = dirname( __FILE__ );
 100+ $file = "$dir/freqpatterntagcloud.sql";
 101+ if ( $updater === null ) {
 102+ global $wgExtNewTables;
 103+ $wgExtNewTables[] = array( 'fptc_associationrules', $file );
 104+ $wgExtNewTables[] = array( 'fptc_items', $file );
 105+ } else {
 106+ $updater->addExtensionUpdate( array( 'addTable', 'fptc_associationrules', $file, true ) );
 107+ $updater->addExtensionUpdate( array( 'addTable', 'fptc_items', $file, true ) );
 108+ }
 109+ return true;
87110 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r98988Fixing sql-file in r98782fptc09:23, 5 October 2011

Status & tagging log