Skip to content

Commit

Permalink
Deletion hook support
Browse files Browse the repository at this point in the history
Support data update trigger upon articles deletion
  • Loading branch information
vedmaka committed Nov 16, 2023
1 parent 14a6a64 commit a068caa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"Hooks": {
"SMW::SQLStore::AfterDataUpdateComplete": [
"SDU\\Hooks::onAfterDataUpdateComplete"
],
"SMW::SQLStore::BeforeDeleteSubjectComplete": [
"SDU\\Hooks::onBeforeDeleteSubjectComplete"
]
},
"JobClasses": {
Expand Down
23 changes: 17 additions & 6 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
use SMW\Options;
use SMW\Services\ServicesFactory as ApplicationFactory;
use SMWDIBlob;
use SMWDIWikiPage;
use SMWQueryProcessor;
use SMWSemanticData;
use SMWStore;
use Title;
use WikiPage;

class Hooks {
Expand All @@ -24,6 +26,12 @@ public static function setup() {
}
}

public static function onBeforeDeleteSubjectComplete( SMWStore $store, Title $title ) {
$diWikiPage = SMWDIWikiPage::newFromTitle( $title );
$smwData = $store->getSemanticData( $diWikiPage );
self::onAfterDataUpdateComplete( $store, $smwData, null );
}

Check warning on line 33 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L29-L33

Added lines #L29 - L33 were not covered by tests

public static function onAfterDataUpdateComplete(
SMWStore $store, SMWSemanticData $newData,
$compositePropertyTableDiffIterator
Expand Down Expand Up @@ -53,18 +61,21 @@ public static function onAfterDataUpdateComplete(
return true;
}

$diffTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable();
if ( $compositePropertyTableDiffIterator !== null ) {
$diffTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable();

Check warning on line 65 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L64-L65

Added lines #L64 - L65 were not covered by tests

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

Check warning on line 69 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L69

Added line #L69 was not covered by tests

if ( count( $diffTable ) > 0 ) {
if ( count( $diffTable ) > 0 ) {

Check warning on line 71 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L71

Added line #L71 was not covered by tests
// wfDebugLog('SemanticDependencyUpdater', "[SDU] diffTable: " . print_r($diffTable, true));
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] -----> Data changes detected" );
} else {
} else {

Check warning on line 74 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L74

Added line #L74 was not covered by tests
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] <-- No semantic data changes detected" );

return true;
}

Check warning on line 78 in src/Hooks.php

View check run for this annotation

Codecov / codecov/patch

src/Hooks.php#L78

Added line #L78 was not covered by tests
}

// THIRD CHECK: Has this page been already traversed more than twice?
Expand Down

0 comments on commit a068caa

Please sign in to comment.