register_hook(MetadataMutation::PAGE_METADATA_MUTATION_EVENT, 'AFTER', $this, 'create_quality_mutation', array()); /** * process the Async event */ $controller->register_hook(self::QUALITY_MUTATION_EVENT_NAME, 'AFTER', $this, 'handle_quality_mutation'); } public function handle_quality_mutation(Doku_Event $event, $param) { $data = $event->data; $path = $data[PagePath::getPersistentName()]; $page = MarkupPath::createPageFromAbsoluteId($path); if (!$page->getCanBeOfLowQuality()) { return; } /** * Delete the html document cache to rewrite the links * */ foreach ($page->getBacklinks() as $backlink) { try { $htmlDocument = $backlink->createHtmlFetcherWithItselfAsContextPath(); } catch (ExceptionNotExists $e) { continue; } try { $wikiId = $backlink->getWikiId(); } catch (ExceptionBadArgument $e) { LogUtility::internalError("Backlink should be only for wiki path"); continue; } $desc = $data[self::DESC]; CacheLog::deleteCacheIfExistsAndLog( $htmlDocument, self::QUALITY_MUTATION_EVENT_NAME, "The {$wikiId} of {$path} had its HTML cache deleted ($desc)." ); } } /** */ function create_quality_mutation(Doku_Event $event, $params): void { if (!Site::isLowQualityProtectionEnable()) { return; } /** * If this is not a mutation on references we return. */ $data = $event->data; $variableName = $data["name"]; if (!(in_array($variableName, self::getQualityMetas()))) { return; } $newValue = DataType::toString($data[MetadataMutation::NEW_VALUE_ATTRIBUTE]); $oldValue = DataType::toString($data[MetadataMutation::OLD_VALUE_ATTRIBUTE]); $path = $data[PagePath::getPersistentName()]; Event::createEvent( self::QUALITY_MUTATION_EVENT_NAME, [ PagePath::getPersistentName() => $path, self::DESC => "The variable ($variableName) has the new value ($newValue) overriding ($oldValue)" ] ); } }