65 'table' =>
'revision_comment_temp',
66 'pk' =>
'revcomment_rev',
67 'field' =>
'revcomment_comment_id',
70 'deprecatedIn' =>
null,
72 'img_description' => [
74 'deprecatedIn' =>
'1.32',
105 $this->stage = $migrationStage;
119 MediaWikiServices::getInstance()->getContentLanguage(),
MIGRATION_NEW
131 return MediaWikiServices::getInstance()->getCommentStore();
140 private function getKey( $methodKey =
null ) {
141 $key = $this->
key ?? $methodKey;
142 if (
$key ===
null ) {
144 throw new InvalidArgumentException(
'$key should not be null' );
170 $fields[
"{$key}_text"] =
$key;
171 $fields[
"{$key}_data"] =
'NULL';
172 $fields[
"{$key}_cid"] =
'NULL';
175 $fields[
"{$key}_old"] =
$key;
178 $tempTableStage = isset( $this->tempTables[
$key] )
181 $fields[
"{$key}_pk"] = $this->tempTables[
$key][
'joinPK'];
184 $fields[
"{$key}_id"] =
"{$key}_id";
209 if ( !array_key_exists(
$key, $this->joinCache ) ) {
215 $fields[
"{$key}_text"] =
$key;
216 $fields[
"{$key}_data"] =
'NULL';
217 $fields[
"{$key}_cid"] =
'NULL';
219 $join = $this->stage ===
MIGRATION_NEW ?
'JOIN' :
'LEFT JOIN';
221 $tempTableStage = isset( $this->tempTables[
$key] )
224 $t = $this->tempTables[
$key];
225 $alias =
"temp_$key";
227 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
229 $joinField =
"{$alias}.{$t['field']}";
235 $joins[$alias][0] =
'LEFT JOIN';
236 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
237 throw new LogicException(
'Nothing should reach this code path at this time' );
241 $joinField =
"{$key}_id";
244 $alias =
"comment_$key";
246 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
249 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
251 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
253 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
254 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
257 $this->joinCache[
$key] = [
264 return $this->joinCache[
$key];
281 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
282 $cid = $row[
"{$key}_cid"] ??
null;
283 $text = $row[
"{$key}_text"];
284 $data = $row[
"{$key}_data"];
288 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
291 wfLogWarning(
"Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD" );
296 $tempTableStage = isset( $this->tempTables[
$key] )
299 if ( $tempTableStage >
MIGRATION_OLD && array_key_exists(
"{$key}_id", $row ) ) {
301 throw new InvalidArgumentException(
302 "\$row does not contain fields needed for comment $key and getComment(), but "
303 .
"does have fields for getCommentLegacy()"
306 $id = $row[
"{$key}_id"];
307 $row2 = $db->selectRow(
309 [
'comment_id',
'comment_text',
'comment_data' ],
310 [
'comment_id' => $id ],
314 if ( !$row2 && $tempTableStage <
MIGRATION_NEW && array_key_exists(
"{$key}_pk", $row ) ) {
316 throw new InvalidArgumentException(
317 "\$row does not contain fields needed for comment $key and getComment(), but "
318 .
"does have fields for getCommentLegacy()"
321 $t = $this->tempTables[
$key];
322 $id = $row[
"{$key}_pk"];
323 $row2 = $db->selectRow(
324 [
$t[
'table'],
'comment' ],
325 [
'comment_id',
'comment_text',
'comment_data' ],
329 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
333 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
334 $row2 = (
object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
336 if ( $row2 ===
null ) {
337 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
341 $cid = $row2->comment_id;
342 $text = $row2->comment_text;
343 $data = $row2->comment_data;
344 } elseif ( $this->stage <
MIGRATION_NEW && array_key_exists(
"{$key}_old", $row ) ) {
346 $text = $row[
"{$key}_old"];
359 if (
$data !==
null ) {
361 if ( !is_array(
$data ) ) {
363 wfLogWarning(
"Invalid JSON object in comment: $data" );
367 if ( isset(
$data[
'_message'] ) ) {
369 ->setInterfaceMessageFlag(
true );
371 if ( !empty(
$data[
'_null'] ) ) {
374 foreach (
$data as $k => $v ) {
375 if ( substr( $k, 0, 1 ) ===
'_' ) {
404 if ( $this->
key !==
null ) {
409 if ( $row ===
null ) {
411 throw new InvalidArgumentException(
'$row must not be null' );
438 if ( $this->
key !==
null ) {
443 if ( $row ===
null ) {
445 throw new InvalidArgumentException(
'$row must not be null' );
474 # Truncate comment in a Unicode-sensitive manner
475 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
478 $dbData = $comment->data;
479 if ( !$comment->message instanceof
RawMessage ) {
480 if ( $dbData ===
null ) {
481 $dbData = [
'_null' =>
true ];
485 if ( $dbData !==
null ) {
487 $len = strlen( $dbData );
488 if ( $len > self::MAX_DATA_LENGTH ) {
490 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
494 $hash =
self::hash( $comment->text, $dbData );
499 'comment_hash' => $hash,
500 'comment_text' => $comment->text,
501 'comment_data' => $dbData,
505 if ( !$comment->id ) {
509 'comment_hash' => $hash,
510 'comment_text' => $comment->text,
511 'comment_data' => $dbData,
538 $fields[
$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
542 $tempTableStage = isset( $this->tempTables[
$key] )
545 $t = $this->tempTables[
$key];
547 $commentId = $comment->id;
548 $callback =
function ( $id )
use ( $dbw, $commentId,
$t, $func ) {
553 $t[
'field'] => $commentId,
560 $fields[
"{$key}_id"] = $comment->id;
564 return [ $fields, $callback ];
584 if ( $this->
key !==
null ) {
589 if ( $comment ===
null ) {
591 throw new InvalidArgumentException(
'$comment can not be null' );
595 $tempTableStage = isset( $this->tempTables[
$key] )
598 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
628 if ( $this->
key !==
null ) {
633 if ( $comment ===
null ) {
635 throw new InvalidArgumentException(
'$comment can not be null' );
639 if ( !isset( $this->tempTables[
$key] ) ) {
640 throw new InvalidArgumentException(
"Must use insert() for $key" );
641 } elseif ( isset( $this->tempTables[
$key][
'deprecatedIn'] ) ) {
642 wfDeprecated( __METHOD__ .
" for $key", $this->tempTables[
$key][
'deprecatedIn'] );
647 $callback =
function () {
651 return [ $fields, $callback ];
660 $key =
count( $msg->getKeysToTry() ) > 1 ? $msg->getKeysToTry() : $msg->getKey();
663 if ( $param instanceof Message ) {
681 if ( is_object( $param ) ) {
682 $param = (
array)$param;
684 if ( is_array( $param ) &&
count( $param ) === 1 && isset( $param[
'message'] ) ) {
698 $hash = crc32( $text ) ^ crc32( (
string)
$data );
702 if ( $hash >= 0x80000000 ) {