Skip to content

Commit e78b046

Browse files
committed
Implemented Third Check (traversal map) to prevent SMW errors causing loops
1 parent 5d67034 commit e78b046

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Diff for: SemanticDependencyUpdater.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,21 @@ public static function setup () {
5050
public static function onAfterDataUpdateComplete( SMWStore $store, SMWSemanticData $newData, $compositePropertyTableDiffIterator ) {
5151

5252
global $wgSDUProperty;
53+
global $wgSDUTraversed;
54+
55+
if (!isset($wgSDUTraversed)) {
56+
$wgSDUTraversed = array();
57+
}
5358

5459
$wgSDUProperty = str_replace(' ', '_', $wgSDUProperty);
5560
$subject = $newData->getSubject();
5661
$title = $subject->getTitle();
62+
$id = $title->getPrefixedDBKey();
5763

5864
wfDebugLog('SemanticDependencyUpdater', "[SDU] --> " . $title);
5965

6066

6167
// FIRST CHECK: Does the page data contain a $wgSUTPropertyName semantic property ?
62-
6368
$properties = $newData->getProperties();
6469
$diffTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable();
6570

@@ -68,19 +73,34 @@ public static function onAfterDataUpdateComplete( SMWStore $store, SMWSemanticDa
6873
return true;
6974
}
7075

76+
7177
// SECOND CHECK: Have there been actual changes in the data? (Ignore internal SMW data!)
7278
// TODO: Introduce an explicit list of Semantic Properties to watch ?
73-
7479
unset($diffTable['smw_fpt_mdat']); // Ignore SMW's internal properties "smw_fpt_mdat"
7580

7681
if (count($diffTable) > 0) {
82+
// wfDebugLog('SemanticDependencyUpdater', "[SDU] diffTable: " . print_r($diffTable, true));
7783
wfDebugLog('SemanticDependencyUpdater', "[SDU] -----> Data changes detected");
7884
} else {
7985
wfDebugLog('SemanticDependencyUpdater', "[SDU] <-- No semantic data changes detected");
8086
return true;
8187
}
8288

8389

90+
// THIRD CHECK: Has this page been already traversed more than twice?
91+
// This should only be the case when SMW errors occur.
92+
// In that case, the diffTable contains everything and SDU can't know if changes happend
93+
if (array_key_exists($id, $wgSDUTraversed)) {
94+
$wgSDUTraversed[$id] = $wgSDUTraversed[$id] + 1;
95+
} else {
96+
$wgSDUTraversed[$id] = 1;
97+
}
98+
if ($wgSDUTraversed[$id] > 2) {
99+
wfDebugLog('SemanticDependencyUpdater', "[SDU] <-- Already traversed");
100+
return true;
101+
}
102+
103+
84104
// QUERY AND UPDATE DEPENDENCIES
85105

86106
$dataItem = $newData->getPropertyValues($properties[$wgSDUProperty]);

0 commit comments

Comments
 (0)