From 2f30defc743b93316e2bd7cf46a548b6da9a6512 Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Tue, 26 Mar 2019 16:17:05 +0100 Subject: [PATCH] Supress ChangeTags::addTags() exceptions for ManualLogEntry objects Looks like some parts of the code try to publish log event when $newId is 0 or null. This cause ChangeTags::addTags to throw an exception as at least one of rc_id, rev_id, or log_id must be specified. When ChangeTags::addTags() fails (because both $rev_id and $log_id are not present), just ignore the exception and continue with the execution. Also, if one of those is set to 0, we need to pass null instead (do not insert 0's in to DB as both log_id and rev_id are foreign keys). Additionally log all places where ManualLogEntry::publish() is called with incorrect arguments so later we can fix all occurencie and remove that try{}catch around ChangeTags::addTags() call. Bug: T218940 Change-Id: I495f79f2b7a7ef1503d229a689babdc12deb353c --- includes/logging/LogEntry.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 33dd69b8fd..5cad31f2fe 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -793,8 +793,24 @@ class ManualLogEntry extends LogEntryBase implements Taggable { * @param string $to One of: rcandudp (default), rc, udp */ public function publish( $newId, $to = 'rcandudp' ) { + $canAddTags = true; + // FIXME: this code should be removed once all callers properly call publish() + if ( $to === 'udp' && !$newId && !$this->getAssociatedRevId() ) { + \MediaWiki\Logger\LoggerFactory::getInstance( 'logging' )->warning( + 'newId and/or revId must be set when calling ManualLogEntry::publish()', + [ + 'newId' => $newId, + 'to' => $to, + 'revId' => $this->getAssociatedRevId(), + // pass a new exception to register the stack trace + 'exception' => new RuntimeException() + ] + ); + $canAddTags = false; + } + DeferredUpdates::addCallableUpdate( - function () use ( $newId, $to ) { + function () use ( $newId, $to, $canAddTags ) { $log = new LogPage( $this->getType() ); if ( !$log->isRestricted() ) { Hooks::runWithoutAbort( 'ManualLogEntryBeforePublish', [ $this ] ); @@ -806,9 +822,14 @@ class ManualLogEntry extends LogEntryBase implements Taggable { $rc->save( $rc::SEND_NONE ); } else { $tags = $this->getTags(); - if ( $tags ) { - $revId = $this->getAssociatedRevId(); // Use null if $revId is 0 - ChangeTags::addTags( $tags, null, $revId > 0 ? $revId : null, $newId ); + if ( $tags && $canAddTags ) { + $revId = $this->getAssociatedRevId(); + ChangeTags::addTags( + $tags, + null, + $revId > 0 ? $revId : null, + $newId > 0 ? $newId : null + ); } } -- 2.20.1