Skip to content

Commit

Permalink
Fixes REL1_39 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vedmaka committed Nov 16, 2023
1 parent a068caa commit 3eedd54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"SMW::SQLStore::AfterDataUpdateComplete": [
"SDU\\Hooks::onAfterDataUpdateComplete"
],
"SMW::SQLStore::BeforeDeleteSubjectComplete": [
"SDU\\Hooks::onBeforeDeleteSubjectComplete"
"PageDelete": [
"SDU\\Hooks::onPageDelete"
]
},
"JobClasses": {
Expand Down
19 changes: 14 additions & 5 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use DeferredUpdates;
use JobQueueGroup;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\WikiPageFactory;
use SMW\Options;
use SMW\Services\ServicesFactory as ApplicationFactory;
use SMWDIBlob;
Expand All @@ -26,8 +28,11 @@ public static function setup() {
}
}

public static function onBeforeDeleteSubjectComplete( SMWStore $store, Title $title ) {
$diWikiPage = SMWDIWikiPage::newFromTitle( $title );
// 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 );
}
Expand Down Expand Up @@ -153,12 +158,12 @@ public static function rebuildData( $wikiPageValues, $store ) {

$pageArray = [];
foreach ( $wikiPageValues as $wikiPageValue ) {
$page = WikiPage::newFromID( $wikiPageValue->getTitle()->getArticleId() );
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromID( $wikiPageValue->getTitle()->getArticleId() );
if ( $page ) {
$pageArray[] = $page->getTitle()->prefixedText;
$pageArray[] = $page->getTitle()->getPrefixedText();
}
}
$pageString = implode( $pageArray, "|" );
$pageString = implode( "|", $pageArray );

// TODO: A threshold when to switch to Queue Jobs might be smarter

Expand Down Expand Up @@ -186,6 +191,10 @@ public static function rebuildData( $wikiPageValues, $store ) {
new Options( [ 'page' => $pageString ] )
);
$dataRebuilder->rebuild();
foreach ( explode( '|', $pageString ) as $wikipage ) {
$wikipage = new WikiPage( Title::newFromText( $pageString ) );
$wikipage->doPurge();
}
} );
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/PageUpdaterJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CommentStoreComment;
use GenericParameterJob;
use Job;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
use RequestContext;
Expand All @@ -22,7 +23,7 @@ public function __construct( array $params ) {
*/
public function run() {
$pageParam = $this->params['page'];
$page = WikiPage::newFromID( $this->params['page']->getTitle()->getArticleId() );
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromID( $this->params['page']->getTitle()->getArticleId() );
$content = $page->getContent( RevisionRecord::RAW );
$title = $page->getTitle();

Expand All @@ -34,6 +35,7 @@ public function run() {
$updater->setContent( SlotRecord::MAIN, $content );
$updater->saveRevision( CommentStoreComment::newUnsavedComment( __CLASS__ . ' [SemanticDependencyUpdater] Null edit. ' . $title ) );

$page->doPurge();
return true;
}
}

0 comments on commit 3eedd54

Please sign in to comment.