1 | <?php |
||
21 | class ChangeNotificationFilter { |
||
22 | |||
23 | const VALUE_CHANGE = 'smw-value-change'; |
||
24 | const SPECIFICATION_CHANGE = 'smw-specification-change'; |
||
25 | |||
26 | /** |
||
27 | * @var DIWikiPage |
||
28 | */ |
||
29 | private $subject; |
||
30 | |||
31 | /** |
||
32 | * @var Store |
||
33 | */ |
||
34 | private $store; |
||
35 | |||
36 | /** |
||
37 | * @var DataValueFactory |
||
38 | */ |
||
39 | private $dataValueFactory; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private $detectedProperties = array(); |
||
45 | |||
46 | /** |
||
47 | * In case detection matrix was stored as subobject on a property then match |
||
48 | * its pairs of property => subobjectKey so that later the Locator can find |
||
49 | * out which subobject contains the group that needs to be notified. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | private $subSemanticDataMatch = array(); |
||
54 | |||
55 | /** |
||
56 | * @var string|null |
||
57 | */ |
||
58 | private $type = null; |
||
59 | |||
60 | /** |
||
61 | * @var User|null |
||
62 | */ |
||
63 | private $agent = null; |
||
64 | |||
65 | /** |
||
66 | * @var boolean |
||
67 | */ |
||
68 | private $canNotify = false; |
||
69 | |||
70 | /** |
||
71 | * @since 1.0 |
||
72 | * |
||
73 | * @param DIWikiPage $subject |
||
74 | * @param Store $store |
||
75 | */ |
||
76 | 8 | public function __construct( DIWikiPage $subject, Store $store ) { |
|
81 | |||
82 | /** |
||
83 | * @since 1.0 |
||
84 | * |
||
85 | * @param User $agent |
||
86 | */ |
||
87 | 4 | public function setAgent( User $agent ) { |
|
90 | |||
91 | /** |
||
92 | * @see EchoEvent::create |
||
93 | * |
||
94 | * @since 1.0 |
||
95 | * |
||
96 | * @param boolean|null $hasChangeToNotifyAbout |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | 2 | public function getEventRecord( $hasChangeToNotifyAbout = false ) { |
|
120 | |||
121 | /** |
||
122 | * @since 1.0 |
||
123 | * |
||
124 | * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator |
||
125 | * |
||
126 | * @return boolean|null |
||
127 | */ |
||
128 | 6 | public function hasChangeToNotifyAbout( CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator ) { |
|
129 | |||
130 | 6 | $start = microtime( true ); |
|
131 | 6 | $this->type = self::VALUE_CHANGE; |
|
132 | |||
133 | 6 | $property = new DIProperty( |
|
134 | PropertyRegistry::NOTIFICATIONS_ON |
||
135 | 6 | ); |
|
136 | |||
137 | if ( |
||
138 | 6 | $this->subject->getNamespace() === SMW_NS_PROPERTY || |
|
139 | 5 | $this->subject->getNamespace() === NS_CATEGORY || |
|
140 | 6 | $this->subject->getNamespace() === SMW_NS_CONCEPT ) { |
|
141 | 1 | $this->type = self::SPECIFICATION_CHANGE; |
|
142 | 1 | } |
|
143 | |||
144 | 6 | foreach ( $compositePropertyTableDiffIterator->getTableChangeOps() as $tableChangeOp ) { |
|
145 | |||
146 | // Skip the Modification date |
||
147 | if ( |
||
148 | 6 | ( $tableChangeOp->getFixedPropertyValueBy( 'key' ) === '_MDAT' ) || |
|
149 | 6 | ( $tableChangeOp->getFixedPropertyValueBy( 'key' ) === '_REDI' ) ) { |
|
150 | 1 | continue; |
|
151 | } |
||
152 | |||
153 | 5 | $this->doFilterOnFieldChangeOps( |
|
154 | 5 | $property, |
|
155 | 5 | $tableChangeOp, |
|
156 | 5 | $tableChangeOp->getFieldChangeOps( 'insert' ) |
|
157 | 5 | ); |
|
158 | |||
159 | 5 | $this->doFilterOnFieldChangeOps( |
|
160 | 5 | $property, |
|
161 | 5 | $tableChangeOp, |
|
162 | 5 | $tableChangeOp->getFieldChangeOps( 'delete' ) |
|
163 | 5 | ); |
|
164 | 6 | } |
|
165 | |||
166 | 6 | wfDebugLog( 'smw', __METHOD__ . ' ' . $this->subject->getHash() . ' in procTime (sec): ' . round( ( microtime( true ) - $start ), 7 ) ); |
|
167 | |||
168 | 6 | return $this->canNotify; |
|
169 | } |
||
170 | |||
171 | 5 | private function doFilterOnFieldChangeOps( $property, $tableChangeOp, $fieldChangeOps ) { |
|
209 | |||
210 | 4 | private function doCompareNotificationsOnValuesWithOps( $property, $dataItem, $fieldChangeOp ) { |
|
246 | |||
247 | 4 | private function doCompareOnPropertyValues( $dataItem, $propertyValues, $fieldChangeOp, $subobjectName = null ) { |
|
252 | |||
253 | 4 | private function doCompareFields( $value, $fieldChangeOp, $dataItem, $subobjectName ) { |
|
306 | |||
307 | } |
||
308 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.