Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql |
— | — | @@ -30,19 +30,19 @@ |
31 | 31 | change_new_value BLOB NULL -- The new value of the property (null for a deletion) |
32 | 32 | ) /*$wgDBTableOptions*/; |
33 | 33 | |
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 |
39 | 40 | ) /*$wgDBTableOptions*/; |
40 | 41 | |
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) |
45 | 47 | ) /*$wgDBTableOptions*/; |
46 | 48 | |
47 | 49 | -- Links change sets to watchlist groups. |
Index: trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php |
— | — | @@ -29,27 +29,117 @@ |
30 | 30 | |
31 | 31 | $everythingOk = true; |
32 | 32 | |
| 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 | + |
33 | 95 | $dbw = wfGetDB( DB_MASTER ); |
34 | 96 | $dbw->begin(); |
35 | 97 | |
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 ) |
40 | 103 | ); |
| 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 | + ); |
41 | 116 | |
42 | | - if ( $result === false ) { |
43 | | - $everythingOk = false; |
44 | | - } |
| 117 | + if ( $result === false ) { |
| 118 | + $everythingOk = false; |
45 | 119 | } |
46 | 120 | |
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 | + } |
48 | 130 | |
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 ) |
53 | 135 | ); |
| 136 | + |
| 137 | + if ( $result === false ) { |
| 138 | + $everythingOk = false; |
| 139 | + } |
| 140 | + |
| 141 | + $dbw->commit(); |
| 142 | + |
| 143 | + return $everythingOk; |
54 | 144 | } |
55 | 145 | |
56 | 146 | public function getAllowedParams() { |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -25,8 +25,8 @@ |
26 | 26 | * @return true |
27 | 27 | */ |
28 | 28 | 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() ); |
31 | 31 | |
32 | 32 | $wasInserted = $changes->writeToStore( $groups ) != 0; |
33 | 33 | |