33 public function __construct(
35 private readonly JobQueueGroup $jobQueue,
37 private readonly IConnectionProvider $dbProvider,
44 public function move( Title $oldName, Title $newName ):
void {
45 $oldTranslatablePage = TranslatablePage::newFromTitle( $oldName );
46 $newTranslatablePage = TranslatablePage::newFromTitle( $newName );
47 $oldGroupId = $oldTranslatablePage->getMessageGroupId();
48 $newGroupId = $newTranslatablePage->getMessageGroupId();
50 $this->messageGroupMetadata->moveMetadata( $oldGroupId, $newGroupId, TranslatablePage::METADATA_KEYS );
52 $this->moveMetadata( $oldGroupId, $newGroupId );
54 TranslatablePage::clearSourcePageCache();
57 MessageGroups::singleton()->recache();
60 $this->messageIndex->rebuild();
62 $job = UpdateTranslatablePageJob::newFromPage( TranslatablePage::newFromTitle( $newName ) );
63 $this->jobQueue->push( $job );
66 public function handleNullRevisionInsert(
TranslatableBundle $bundle, RevisionRecord $revision ):
void {
68 throw new InvalidArgumentException(
69 'Expected $bundle to be of type TranslatablePage, got ' . get_class( $bundle )
73 $pageContent = $revision->getContent( SlotRecord::MAIN );
74 if ( !$pageContent instanceof TextContent ) {
75 throw new RuntimeException(
"Translatable page {$bundle->getTitle()} has non-textual content." );
79 $pageText = $pageContent->getText();
80 if ( $this->translatablePageParser->containsMarkup( $pageText ) ) {
82 TranslatablePage::clearSourcePageCache();
87 public function delete( Title $title ): void {
88 $dbw = $this->dbProvider->getPrimaryDatabase();
89 $dbw->newDeleteQueryBuilder()
90 ->deleteFrom(
'translate_sections' )
91 ->where( [
'trs_page' => $title->getId() ] )
92 ->caller( __METHOD__ )
99 public function unmark( PageIdentity $title ): void {
101 foreach ( $translatablePage->getTranslationPages() as $page ) {
102 $page->invalidateCache();
106 $this->messageGroupMetadata->clearMetadata( $groupId, TranslatablePage::METADATA_KEYS );
107 $this->removeFromAggregateGroups( $groupId );
112 $this->translatableBundleStatusStore->removeStatus( $title->getId() );
114 MessageGroups::singleton()->recache();
115 $this->jobQueue->push( RebuildMessageIndexJob::newJob( __METHOD__ ) );
117 TranslatablePage::clearSourcePageCache();
118 $translatablePage->getTitle()->invalidateCache();
123 DeferredUpdates::addCallableUpdate(
124 function () use ( $title ) {
125 $this->updateStatus( $title );
131 public function updateStatus( Title $title ): ?TranslatableBundleStatus {
132 $revTags = $this->revTagStore->getLatestRevisionsForTags(
138 $status = TranslatablePage::determineStatus(
139 $revTags[RevTagStore::TP_READY_TAG] ??
null,
140 $revTags[RevTagStore::TP_MARK_TAG] ??
null,
141 $title->getLatestRevID( IDBAccessObject::READ_LATEST )
145 $this->translatableBundleStatusStore->setStatus(
148 TranslatablePage::class
155 private function moveMetadata(
string $oldGroupId,
string $newGroupId ): void {
158 $this->messageGroupMetadata->preloadGroups( array_keys( $aggregateGroups ), __METHOD__ );
160 foreach ( $aggregateGroups as $id => $group ) {
161 $subgroups = $this->messageGroupMetadata->get( $id,
'subgroups' );
162 if ( $subgroups ===
false ) {
166 $subgroups = explode(
',', $subgroups );
167 $subgroups = array_flip( $subgroups );
168 if ( isset( $subgroups[$oldGroupId] ) ) {
169 $subgroups[$newGroupId] = $subgroups[$oldGroupId];
170 unset( $subgroups[$oldGroupId] );
171 $subgroups = array_flip( $subgroups );
172 $this->messageGroupMetadata->set(
175 implode(
',', $subgroups )
181 $priority = MessageGroups::getPriority( $oldGroupId );
182 if ( $priority !==
'' ) {
183 MessageGroups::setPriority( $newGroupId, $priority );
184 MessageGroups::setPriority( $oldGroupId,
'' );
188 private function removeFromAggregateGroups(
string $groupId ): void {
191 $this->messageGroupMetadata->preloadGroups( array_keys( $aggregateGroups ), __METHOD__ );
192 foreach ( $aggregateGroups as $group ) {
193 $subgroups = $this->messageGroupMetadata->get( $group,
'subgroups' );
194 if ( $subgroups !==
false ) {
195 $subgroups = explode(
',', $subgroups );
196 $subgroups = array_flip( $subgroups );
197 if ( isset( $subgroups[$groupId] ) ) {
198 unset( $subgroups[$groupId] );
199 $subgroups = array_flip( $subgroups );
200 $this->messageGroupMetadata->set(
203 implode(
',', $subgroups )