r88642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88641‎ | r88642 | r88643 >
Date:14:49, 23 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some schedma changes and work on proper clean up when deleting a watchlist group
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql (modified) (history)
  • /trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
@@ -30,19 +30,19 @@
3131 change_new_value BLOB NULL -- The new value of the property (null for a deletion)
3232 ) /*$wgDBTableOptions*/;
3333
34 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets (
35 - set_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
36 - set_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip)
37 - set_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on
38 - set_time CHAR(14) binary NOT NULL default '' -- The time the chages where made
 34+-- Individual edits to pages.
 35+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_edits (
 36+ edit_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
 37+ edit_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip)
 38+ edit_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on
 39+ edit_time CHAR(14) binary NOT NULL default '' -- The time the chages where made
3940 ) /*$wgDBTableOptions*/;
4041
41 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_edits_per_group (
42 - epg_group_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_groups.group_id
43 - epg_edit_id INT(10) unsigned NOT NULL, -- Edit ID
44 - PRIMARY KEY (epg_group_id,epg_edit_id)
 42+-- Links change sets their edits.
 43+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets_per_edit (
 44+ spe_set_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_sets.set_id
 45+ spe_edit_id INT(10) unsigned NOT NULL, -- Edit ID
 46+ PRIMARY KEY (spe_set_id,spe_edit_id)
4547 ) /*$wgDBTableOptions*/;
4648
4749 -- Links change sets to watchlist groups.
Index: trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
@@ -29,27 +29,117 @@
3030
3131 $everythingOk = true;
3232
 33+ foreach ( $params['ids'] as $id ) {
 34+ $everythingOk = $this->deleteGroup( $id ) && $everythingOk;
 35+ }
 36+
 37+ $this->getResult()->addValue(
 38+ null,
 39+ 'success',
 40+ $everythingOk
 41+ );
 42+ }
 43+
 44+ /**
 45+ * Delete the group with specified ID, and
 46+ * all linked data not used by other groups.
 47+ *
 48+ * @since 0.1
 49+ *
 50+ * @param integer $groupId
 51+ *
 52+ * @return boolean Sucess indicator
 53+ */
 54+ protected function deleteGroup( $groupId ) {
 55+ $everythingOk = true;
 56+
 57+ $dbr = wfGetDB( DB_SLAVE );
 58+
 59+ // Find all edits linked to this group.
 60+ $editsForGroup = $dbr->select(
 61+ array( 'swl_sets_per_group', 'swl_sets_per_edit', 'swl_edits' ),
 62+ array( 'spe_edit_id' ),
 63+ array(
 64+ 'spg_group_id' => $id,
 65+ ),
 66+ '',
 67+ array(),
 68+ array(
 69+ 'swl_sets_per_edit' => array( 'INNER JOIN', array( 'spe_set_id=spg_set_id' ) ),
 70+ )
 71+ );
 72+
 73+ $editsToDelete = array();
 74+
 75+ // For each linked edit, find all linked groups, and save those with only one (this one).
 76+ foreach ( $editsForGroup as $edit ) {
 77+ $groupsForEdit = $dbr->select(
 78+ array( 'swl_sets_per_group', 'swl_sets_per_edit', 'swl_groups' ),
 79+ array( 'spg_group_id' ),
 80+ array(
 81+ 'spe_edit_id' => $edit->edit_id,
 82+ ),
 83+ '',
 84+ array(),
 85+ array(
 86+ 'swl_sets_per_edit' => array( 'INNER JOIN', array( 'spe_set_id=spg_set_id' ) ),
 87+ )
 88+ );
 89+
 90+ if ( $dbr->numRows( $groupsForEdit ) < 2 ) {
 91+ $editsToDelete[] = $edit->edit_id;
 92+ }
 93+ }
 94+
3395 $dbw = wfGetDB( DB_MASTER );
3496 $dbw->begin();
3597
36 - foreach ( $params['ids'] as $id ) {
37 - $result = $dbw->delete(
38 - 'swl_groups',
39 - array( 'group_id' => $id )
 98+ // Delete all edits and sets per edits only linked to this group.
 99+ foreach ( $editsToDelete as $editId ) {
 100+ $dbw->delete(
 101+ 'swl_edits',
 102+ array( 'edit_id' => $editId )
40103 );
 104+
 105+ $dbw->delete(
 106+ 'swl_sets_per_edit',
 107+ array( 'spe_edit_id' => $editId )
 108+ );
 109+ }
 110+
 111+ // Delete sets per group links for this group.
 112+ $result = $dbw->delete(
 113+ 'swl_sets_per_group',
 114+ array( 'spg_group_id' => $id )
 115+ );
41116
42 - if ( $result === false ) {
43 - $everythingOk = false;
44 - }
 117+ if ( $result === false ) {
 118+ $everythingOk = false;
45119 }
46120
47 - $dbw->commit();
 121+ // Delete users per group links for this group.
 122+ $result = $dbw->delete(
 123+ 'swl_users_per_group',
 124+ array( 'upg_group_id' => $id )
 125+ );
 126+
 127+ if ( $result === false ) {
 128+ $everythingOk = false;
 129+ }
48130
49 - $this->getResult()->addValue(
50 - null,
51 - 'success',
52 - $everythingOk
 131+ // Delete the actual group.
 132+ $result = $dbw->delete(
 133+ 'swl_groups',
 134+ array( 'group_id' => $id )
53135 );
 136+
 137+ if ( $result === false ) {
 138+ $everythingOk = false;
 139+ }
 140+
 141+ $dbw->commit();
 142+
 143+ return $everythingOk;
54144 }
55145
56146 public function getAllowedParams() {
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -25,8 +25,8 @@
2626 * @return true
2727 */
2828 public static function onDataUpdate( SMWStore $store, SMWSemanticData $newData ) {
29 - $changes = SWLChangeSet::newFromSemanticData( $store->getSemanticData( $newData->getSubject() ), $newData );
30 - $groups = SWLGroups::getMatchingWatchGroups( $changes->getTitle() );
 29+ $changeSet = SWLChangeSet::newFromSemanticData( $store->getSemanticData( $newData->getSubject() ), $newData );
 30+ $groups = SWLGroups::getMatchingWatchGroups( $changeSet->getTitle() );
3131
3232 $wasInserted = $changes->writeToStore( $groups ) != 0;
3333

Status & tagging log