r87917 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87916‎ | r87917 | r87918 >
Date:16:55, 12 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed obvious bug: only fire change hook when there are actual changes :)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
@@ -41,6 +41,13 @@
4242 protected $properties = array();
4343
4444 /**
 45+ * Indicates if there are changes in the list.
 46+ *
 47+ * @var boolean
 48+ */
 49+ protected $hasChanges = false;
 50+
 51+ /**
4552 * Get the array of all properties that have changes.
4653 *
4754 * @return array of SMWDIProperty
@@ -50,6 +57,16 @@
5158 }
5259
5360 /**
 61+ * Returns if the list contains any changes.
 62+ * This info is cached, so the call is cheaper then doing a count.
 63+ *
 64+ * @return boolean
 65+ */
 66+ public function hasChanges() {
 67+ return $this->hasChanges;
 68+ }
 69+
 70+ /**
5471 * Get the array of all stored values for some property.
5572 *
5673 * @param $property SMWDIProperty
@@ -86,6 +103,8 @@
87104 }
88105
89106 $this->changes[$property->getKey()][] = $change;
 107+
 108+ $this->hasChanges = true;
90109 }
91110
92111 /**
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
@@ -280,7 +280,11 @@
281281 global $smwgCheckChangesBeforeUpdate;
282282 if ( $smwgCheckChangesBeforeUpdate && $data->hasVisibleProperties() ) {
283283 $oldData = $this->getSemanticData( $data->getSubject() );
284 - wfRunHooks( 'SMWStore::dataChanged', array( $this, SMWChangeSet::newFromSemanticData( $oldData, $data ) ) );
 284+ $changeSet = SMWChangeSet::newFromSemanticData( $oldData, $data );
 285+
 286+ if ( $changeSet->hasChanges() ) {
 287+ wfRunHooks( 'SMWStore::dataChanged', array( $this, $changeSet ) );
 288+ }
285289 }
286290
287291 // Invalidate the page, so data stored on it gets displayed immediately in queries.
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
@@ -1,8 +1,9 @@
22 <?php
33
44 /**
 5+ * This class represents a semantic property diff between 2 versions
 6+ * of a single page.
57 *
6 - *
78 * @since 1.6
89 *
910 * @file SMW_ChangeSet.php
@@ -74,17 +75,17 @@
7576 $newDataItems = array();
7677
7778 // Populate the data item arrays using keys that are their hash, so matches can be found.
78 - foreach ( $old->getPropertyValues( $diProperty ) as $dataItem ) {
 79+ // Note: this code assumes there are no duplicates.
 80+ foreach ( $old->getPropertyValues( $diProperty ) as /* SMWDataItem */ $dataItem ) {
7981 $oldDataItems[$dataItem->getHash()] = $dataItem;
8082 }
81 - foreach ( $new->getPropertyValues( $diProperty ) as $dataItem ) {
 83+ foreach ( $new->getPropertyValues( $diProperty ) as /* SMWDataItem */ $dataItem ) {
8284 $newDataItems[$dataItem->getHash()] = $dataItem;
8385 }
8486
8587 $foundMatches = array();
8688
8789 // Find values that are both in the old and new version.
88 - // Note: this code assumes there are no duplicates.
8990 foreach ( array_keys( $oldDataItems ) as $hash ) {
9091 if ( array_key_exists( $hash, $newDataItems ) ) {
9192 $foundMatches[] = $hash;
@@ -168,9 +169,20 @@
169170 }
170171
171172 /**
 173+ * Returns whether the set contains any changes.
 174+ *
 175+ * @return boolean
 176+ */
 177+ public function hasChanges() {
 178+ return $this->changes->hasChanges()
 179+ || $this->insertions->hasVisibleProperties()
 180+ || $this->deletions->hasVisibleProperties();
 181+ }
 182+
 183+ /**
172184 * Returns a list of ALL changes, including isertions and deletions.
173185 *
174 - * @return array of
 186+ * @return array of SMWPropertyChange
175187 */
176188 public function getAllChanges() {
177189 return array(); // TODO: implement

Status & tagging log