Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletion hook support #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
],
"PageDelete": [
"SDU\\Hooks::onPageDelete"
]
},
"callback": "SDU\\Hooks::setup",
Expand Down
64 changes: 40 additions & 24 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use SMW\MediaWiki\Jobs\UpdateJob;
use SMW\Services\ServicesFactory as ApplicationFactory;
use SMWDIBlob;
use SMWDIWikiPage;
use SMWQueryProcessor;
use SMWSemanticData;
use SMWStore;
use Title;
use WikiPage;

class Hooks {

Expand All @@ -23,6 +26,15 @@ public static function setup() {
}
}

// Note: at the time SMW::SQLStore::BeforeDeleteSubjectComplete fires there is no data already
// so the PageDelete hook is used
public static function onPageDelete( $page, $deleter, string $reason, $status, bool $suppress ) {
$store = smwfGetStore();
$diWikiPage = SMWDIWikiPage::newFromTitle( Title::newFromDBkey( $page->getDBkey() ) );
$smwData = $store->getSemanticData( $diWikiPage );
self::onAfterDataUpdateComplete( $store, $smwData, null );
}

public static function onAfterDataUpdateComplete(
SMWStore $store, SMWSemanticData $newData,
$compositePropertyTableDiffIterator
Expand Down Expand Up @@ -52,34 +64,38 @@ public static function onAfterDataUpdateComplete(
return true;
}

$diffTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable();
$smwSID = $compositePropertyTableDiffIterator->getSubject()->getId();
// 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"

// lets try first to check the data tables: https://www.semantic-mediawiki.org/wiki/Help:Database_schema
// if change, on pageID from Issue, that is not REvision ID, then trigger all changes
$triggerSemanticDependencies = false;

if ( count( $diffTable ) > 0 ) {
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] -----> Data changes detected" );

foreach ( $diffTable as $key => $value ) {
if ( strpos( $key, 'smw_di' ) === 0 && is_array( $value ) ) {
foreach ( $value["insert"] as $insert ) {
if ( $insert["s_id"] == $smwSID ) {
if ( $insert["p_id"] != 506 ) {
$triggerSemanticDependencies = true;
break 2;
} // revision ID change is good, but must not trigger UpdateJob for semantic dependencies
if ( $compositePropertyTableDiffIterator !== null ) {
// SECOND CHECK: Have there been actual changes in the data? (Ignore internal SMW data!)
// (Skipping this check if we got here from a page deletion)
// TODO: Introduce an explicit list of Semantic Properties to watch ?
$diffTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable();
$smwSID = $compositePropertyTableDiffIterator->getSubject()->getId();

unset( $diffTable['smw_fpt_mdat'] ); // Ignore SMW's internal properties "smw_fpt_mdat"

// lets try first to check the data tables: https://www.semantic-mediawiki.org/wiki/Help:Database_schema
// if change, on pageID from Issue, that is not REvision ID, then trigger all changes
$triggerSemanticDependencies = false;

if ( count( $diffTable ) > 0 ) {
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] -----> Data changes detected" );

foreach ( $diffTable as $key => $value ) {
if ( strpos( $key, 'smw_di' ) === 0 && is_array( $value ) ) {
foreach ( $value["insert"] as $insert ) {
if ( $insert["s_id"] == $smwSID ) {
if ( $insert["p_id"] != 506 ) {
$triggerSemanticDependencies = true;
break 2;
} // revision ID change is good, but must not trigger UpdateJob for semantic dependencies
}
}
}
}
} else {
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] <-- No semantic data changes detected" );
return true;
}
} else {
wfDebugLog( 'SemanticDependencyUpdater', "[SDU] <-- No semantic data changes detected" );
return true;
}

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