execute( 'DELETE FROM {knowledge_chunks} WHERE site_id = ? AND source_id = ? AND version_id IN (SELECT id FROM {knowledge_versions} WHERE site_id = ? AND source_id = ? AND generation_id IS NOT NULL)', [$siteId, $sourceId, $siteId, $sourceId] ); $versions = $db->execute('DELETE FROM {knowledge_versions} WHERE site_id = ? AND source_id = ? AND generation_id IS NOT NULL', [$siteId, $sourceId]); $db->execute('DELETE FROM {knowledge_claims} WHERE site_id = ? AND source_id = ?', [$siteId, $sourceId]); return ['versions' => $versions, 'chunks' => $chunks]; } /** * Ready generation copies of the source built from other text than $contentHash (the source's content was just replaced). Versions * being built are left alone: their publish checks the content hash inside its own transaction. * * @return array{versions:int, chunks:int} */ public static function removeOtherContent(Connection $db, int $siteId, int $sourceId, string $contentHash): array { $chunks = $db->execute( "DELETE FROM {knowledge_chunks} WHERE site_id = ? AND source_id = ? AND version_id IN (SELECT id FROM {knowledge_versions} WHERE site_id = ? AND source_id = ? AND generation_id IS NOT NULL AND state = 'ready' AND content_hash <> ?)", [$siteId, $sourceId, $siteId, $sourceId, $contentHash] ); $versions = $db->execute( "DELETE FROM {knowledge_versions} WHERE site_id = ? AND source_id = ? AND generation_id IS NOT NULL AND state = 'ready' AND content_hash <> ?", [$siteId, $sourceId, $contentHash] ); return ['versions' => $versions, 'chunks' => $chunks]; } }