r87960 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87959‎ | r87960 | r87961 >
Date:10:09, 13 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on getting and storing changes and changesets from/to datastore
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
@@ -36,16 +36,16 @@
3737 cg_time CHAR(14) binary NOT NULL default '' -- The time the chages where made
3838 ) /*$wgDBTableOptions*/;
3939
 40+-- Links change groups to watchlist groups.
4041 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)
4445 ) /*$wgDBTableOptions*/;
4546
4647 -- Links users to watchlist groups.
4748 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
5051 PRIMARY KEY (upg_group_id,upg_user_id)
5152 ) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php
@@ -13,6 +13,11 @@
1414 */
1515 final class SWLGroups {
1616
 17+ /**
 18+ * Cached list of all watchlist groups.
 19+ *
 20+ * @var array of SWLGroup
 21+ */
1722 protected static $groups = false;
1823
1924 /**
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
@@ -23,6 +23,11 @@
2424 */
2525 protected $time;
2626
 27+ /**
 28+ * DB ID of the change set (swl_change_groups.cg_id).
 29+ *
 30+ * @var integer
 31+ */
2732 protected $id;
2833
2934 /**
@@ -39,11 +44,30 @@
4045 *
4146 * @return SWLChangeSet
4247 */
43 - public static function newFromDBResult( $set ) {
 48+ public static function newFromDBResult( $set ) {
4449 $changeSet = new SMWChangeSet(
4550 SMWDIWikiPage::newFromTitle( Title::newFromID( $set->cg_page_id ) )
4651 );
4752
 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+
4872 $changeSet = new SWLChangeSet( // swl_change_groups
4973 $changeSet,
5074 User::newFromName( $set->cg_user_name ),
@@ -90,9 +114,9 @@
91115 * @return boolean Success indicator
92116 */
93117 public function writeToStore() {
94 - $dbr = wfGetDB( DB_MASTER );
 118+ $dbw = wfGetDB( DB_MASTER );
95119
96 - $dbr->insert(
 120+ $dbw->insert(
97121 'swl_change_groups',
98122 array(
99123 'cg_user_name' => $this->getUser()->getName(),
@@ -100,8 +124,65 @@
101125 'cg_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime()
102126 )
103127 );
 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+ }
104180 }
105181
 182+ /**
 183+ * Gets the title of the page these changes belong to.
 184+ *
 185+ * @return Title
 186+ */
106187 public function getTitle() {
107188 if ( $this->title === false ) {
108189 $this->title = Title::makeTitle( $this->getSubject()->getNamespace(), $this->getSubject()->getDBkey() );
@@ -110,18 +191,38 @@
111192 return $this->title;
112193 }
113194
 195+ /**
 196+ * Sets the user that made the changes.
 197+ *
 198+ * @param User $user
 199+ */
114200 public function setUser( User $user ) {
115201 $this->user = $user;
116202 }
117203
 204+ /**
 205+ * Gets the user that made the changes.
 206+ *
 207+ * @return User
 208+ */
118209 public function getUser() {
119210 return $this->user;
120211 }
121212
 213+ /**
 214+ * Sets the time on which the changes where made.
 215+ *
 216+ * @param integer $time
 217+ */
122218 public function setTime( $time ) {
123219 $this->time = $time;
124220 }
125221
 222+ /**
 223+ * Gets the time on which the changes where made.
 224+ *
 225+ * @return integer
 226+ */
126227 public function getTime() {
127228 return $this->time;
128229 }
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -26,6 +26,7 @@
2727 */
2828 public static function onDataChanged( SMWStore $store, SMWChangeSet $changes ) {
2929 $changes = new SWLChangeSet( $changes );
 30+ $changes->writeToStore();
3031
3132 foreach ( SWLGroups::getMatchingWatchGroups( $changes->getTitle() ) as /* SWLGroup */ $group ) {
3233 $group->notifyWatchingUsers( $changes );

Status & tagging log