Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php |
— | — | @@ -41,6 +41,13 @@ |
42 | 42 | protected $properties = array(); |
43 | 43 | |
44 | 44 | /** |
| 45 | + * Indicates if there are changes in the list. |
| 46 | + * |
| 47 | + * @var boolean |
| 48 | + */ |
| 49 | + protected $hasChanges = false; |
| 50 | + |
| 51 | + /** |
45 | 52 | * Get the array of all properties that have changes. |
46 | 53 | * |
47 | 54 | * @return array of SMWDIProperty |
— | — | @@ -50,6 +57,16 @@ |
51 | 58 | } |
52 | 59 | |
53 | 60 | /** |
| 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 | + /** |
54 | 71 | * Get the array of all stored values for some property. |
55 | 72 | * |
56 | 73 | * @param $property SMWDIProperty |
— | — | @@ -86,6 +103,8 @@ |
87 | 104 | } |
88 | 105 | |
89 | 106 | $this->changes[$property->getKey()][] = $change; |
| 107 | + |
| 108 | + $this->hasChanges = true; |
90 | 109 | } |
91 | 110 | |
92 | 111 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php |
— | — | @@ -280,7 +280,11 @@ |
281 | 281 | global $smwgCheckChangesBeforeUpdate; |
282 | 282 | if ( $smwgCheckChangesBeforeUpdate && $data->hasVisibleProperties() ) { |
283 | 283 | $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 | + } |
285 | 289 | } |
286 | 290 | |
287 | 291 | // 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 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
| 5 | + * This class represents a semantic property diff between 2 versions |
| 6 | + * of a single page. |
5 | 7 | * |
6 | | - * |
7 | 8 | * @since 1.6 |
8 | 9 | * |
9 | 10 | * @file SMW_ChangeSet.php |
— | — | @@ -74,17 +75,17 @@ |
75 | 76 | $newDataItems = array(); |
76 | 77 | |
77 | 78 | // 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 ) { |
79 | 81 | $oldDataItems[$dataItem->getHash()] = $dataItem; |
80 | 82 | } |
81 | | - foreach ( $new->getPropertyValues( $diProperty ) as $dataItem ) { |
| 83 | + foreach ( $new->getPropertyValues( $diProperty ) as /* SMWDataItem */ $dataItem ) { |
82 | 84 | $newDataItems[$dataItem->getHash()] = $dataItem; |
83 | 85 | } |
84 | 86 | |
85 | 87 | $foundMatches = array(); |
86 | 88 | |
87 | 89 | // Find values that are both in the old and new version. |
88 | | - // Note: this code assumes there are no duplicates. |
89 | 90 | foreach ( array_keys( $oldDataItems ) as $hash ) { |
90 | 91 | if ( array_key_exists( $hash, $newDataItems ) ) { |
91 | 92 | $foundMatches[] = $hash; |
— | — | @@ -168,9 +169,20 @@ |
169 | 170 | } |
170 | 171 | |
171 | 172 | /** |
| 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 | + /** |
172 | 184 | * Returns a list of ALL changes, including isertions and deletions. |
173 | 185 | * |
174 | | - * @return array of |
| 186 | + * @return array of SMWPropertyChange |
175 | 187 | */ |
176 | 188 | public function getAllChanges() { |
177 | 189 | return array(); // TODO: implement |