Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql |
— | — | @@ -36,16 +36,16 @@ |
37 | 37 | cg_time CHAR(14) binary NOT NULL default '' -- The time the chages where made |
38 | 38 | ) /*$wgDBTableOptions*/; |
39 | 39 | |
| 40 | +-- Links change groups to watchlist groups. |
40 | 41 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes_per_group ( |
41 | | - cpg_group_id SMALLINT unsigned NOT NULL, |
42 | | - cpg_change_id INT(10) unsigned NOT NULL, |
43 | | - PRIMARY KEY (cpg_group_id,cpg_change_id) |
| 42 | + cpg_group_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_groups.group_id |
| 43 | + cpg_change_group_id INT(10) unsigned NOT NULL, -- Foreign key: swl_change_groups.cg_id |
| 44 | + PRIMARY KEY (cpg_group_id,cpg_change_group_id) |
44 | 45 | ) /*$wgDBTableOptions*/; |
45 | 46 | |
46 | 47 | -- Links users to watchlist groups. |
47 | 48 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_users_per_group ( |
48 | | - upg_group_id SMALLINT unsigned NOT NULL, |
49 | | - upg_user_id INT(10) unsigned NOT NULL, |
| 49 | + upg_group_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_groups.group_id |
| 50 | + upg_user_id INT(10) unsigned NOT NULL, -- Foreign key: user.user_id |
50 | 51 | PRIMARY KEY (upg_group_id,upg_user_id) |
51 | 52 | ) /*$wgDBTableOptions*/; |
\ No newline at end of file |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php |
— | — | @@ -13,6 +13,11 @@ |
14 | 14 | */ |
15 | 15 | final class SWLGroups { |
16 | 16 | |
| 17 | + /** |
| 18 | + * Cached list of all watchlist groups. |
| 19 | + * |
| 20 | + * @var array of SWLGroup |
| 21 | + */ |
17 | 22 | protected static $groups = false; |
18 | 23 | |
19 | 24 | /** |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php |
— | — | @@ -23,6 +23,11 @@ |
24 | 24 | */ |
25 | 25 | protected $time; |
26 | 26 | |
| 27 | + /** |
| 28 | + * DB ID of the change set (swl_change_groups.cg_id). |
| 29 | + * |
| 30 | + * @var integer |
| 31 | + */ |
27 | 32 | protected $id; |
28 | 33 | |
29 | 34 | /** |
— | — | @@ -39,11 +44,30 @@ |
40 | 45 | * |
41 | 46 | * @return SWLChangeSet |
42 | 47 | */ |
43 | | - public static function newFromDBResult( $set ) { |
| 48 | + public static function newFromDBResult( $set ) { |
44 | 49 | $changeSet = new SMWChangeSet( |
45 | 50 | SMWDIWikiPage::newFromTitle( Title::newFromID( $set->cg_page_id ) ) |
46 | 51 | ); |
47 | 52 | |
| 53 | + $dbr = wfGetDb( DB_SLAVE ); |
| 54 | + |
| 55 | + $changes = $dbr->select( |
| 56 | + 'swl_changes', |
| 57 | + array( |
| 58 | + 'change_id', |
| 59 | + 'change_property', |
| 60 | + 'change_old_value', |
| 61 | + 'change_new_value' |
| 62 | + ), |
| 63 | + array( |
| 64 | + 'change_group_id' => $set->cg_id |
| 65 | + ) |
| 66 | + ); |
| 67 | + |
| 68 | + foreach ( $changes as $change ) { |
| 69 | + $changeSet->addChange( $change->change_property, SMWPropertyChange( $change->change_old_value, $change->change_new_value ) ); |
| 70 | + } |
| 71 | + |
48 | 72 | $changeSet = new SWLChangeSet( // swl_change_groups |
49 | 73 | $changeSet, |
50 | 74 | User::newFromName( $set->cg_user_name ), |
— | — | @@ -90,9 +114,9 @@ |
91 | 115 | * @return boolean Success indicator |
92 | 116 | */ |
93 | 117 | public function writeToStore() { |
94 | | - $dbr = wfGetDB( DB_MASTER ); |
| 118 | + $dbw = wfGetDB( DB_MASTER ); |
95 | 119 | |
96 | | - $dbr->insert( |
| 120 | + $dbw->insert( |
97 | 121 | 'swl_change_groups', |
98 | 122 | array( |
99 | 123 | 'cg_user_name' => $this->getUser()->getName(), |
— | — | @@ -100,8 +124,65 @@ |
101 | 125 | 'cg_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime() |
102 | 126 | ) |
103 | 127 | ); |
| 128 | + |
| 129 | + $id = $dbw->insertId(); |
| 130 | + |
| 131 | + $changes = array(); |
| 132 | + |
| 133 | + foreach ( $this->getChanges()->getProperties() as /* SMWDIProperty */ $proprety ) { |
| 134 | + $propName = $proprety->getLabel(); |
| 135 | + |
| 136 | + foreach ( $this->getChanges()->getPropertyChanges( $proprety ) as /* SMWPropertyChange */ $change ) { |
| 137 | + $changes[] = array( |
| 138 | + 'property' => $propName, |
| 139 | + 'old' => $change->getOldValue()->getSerialization(), |
| 140 | + 'new' => $change->getNewValue()->getSerialization() |
| 141 | + ); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + foreach ( $this->getInsertions()->getProperties() as /* SMWDIProperty */ $proprety ) { |
| 146 | + $propName = $proprety->getLabel(); |
| 147 | + |
| 148 | + foreach ( $this->getInsertions()->getPropertyValues( $proprety ) as /* SMWDataItem */ $dataItem ) { |
| 149 | + $changes[] = array( |
| 150 | + 'property' => $propName, |
| 151 | + 'old' => null, |
| 152 | + 'new' => $dataItem->getSerialization() |
| 153 | + ); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + foreach ( $this->getDeletions()->getProperties() as /* SMWDIProperty */ $proprety ) { |
| 158 | + $propName = $proprety->getLabel(); |
| 159 | + |
| 160 | + foreach ( $this->getDeletions()->getPropertyValues( $proprety ) as /* SMWDataItem */ $dataItem ) { |
| 161 | + $changes[] = array( |
| 162 | + 'property' => $propName, |
| 163 | + 'old' => $dataItem->getSerialization(), |
| 164 | + 'new' => null |
| 165 | + ); |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + foreach ( $changes as $change ) { |
| 170 | + $dbw->insert( |
| 171 | + 'swl_changes', |
| 172 | + array( |
| 173 | + 'change_group_id' => $id, |
| 174 | + 'change_property' => $change['property'], |
| 175 | + 'change_old_value' => $change['old'], |
| 176 | + 'change_new_value' => $change['new'] |
| 177 | + ) |
| 178 | + ); |
| 179 | + } |
104 | 180 | } |
105 | 181 | |
| 182 | + /** |
| 183 | + * Gets the title of the page these changes belong to. |
| 184 | + * |
| 185 | + * @return Title |
| 186 | + */ |
106 | 187 | public function getTitle() { |
107 | 188 | if ( $this->title === false ) { |
108 | 189 | $this->title = Title::makeTitle( $this->getSubject()->getNamespace(), $this->getSubject()->getDBkey() ); |
— | — | @@ -110,18 +191,38 @@ |
111 | 192 | return $this->title; |
112 | 193 | } |
113 | 194 | |
| 195 | + /** |
| 196 | + * Sets the user that made the changes. |
| 197 | + * |
| 198 | + * @param User $user |
| 199 | + */ |
114 | 200 | public function setUser( User $user ) { |
115 | 201 | $this->user = $user; |
116 | 202 | } |
117 | 203 | |
| 204 | + /** |
| 205 | + * Gets the user that made the changes. |
| 206 | + * |
| 207 | + * @return User |
| 208 | + */ |
118 | 209 | public function getUser() { |
119 | 210 | return $this->user; |
120 | 211 | } |
121 | 212 | |
| 213 | + /** |
| 214 | + * Sets the time on which the changes where made. |
| 215 | + * |
| 216 | + * @param integer $time |
| 217 | + */ |
122 | 218 | public function setTime( $time ) { |
123 | 219 | $this->time = $time; |
124 | 220 | } |
125 | 221 | |
| 222 | + /** |
| 223 | + * Gets the time on which the changes where made. |
| 224 | + * |
| 225 | + * @return integer |
| 226 | + */ |
126 | 227 | public function getTime() { |
127 | 228 | return $this->time; |
128 | 229 | } |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | */ |
28 | 28 | public static function onDataChanged( SMWStore $store, SMWChangeSet $changes ) { |
29 | 29 | $changes = new SWLChangeSet( $changes ); |
| 30 | + $changes->writeToStore(); |
30 | 31 | |
31 | 32 | foreach ( SWLGroups::getMatchingWatchGroups( $changes->getTitle() ) as /* SWLGroup */ $group ) { |
32 | 33 | $group->notifyWatchingUsers( $changes ); |