MediaWiki  1.33.0
ActorMigrationTest.php
Go to the documentation of this file.
1 <?php
2 
5 use Wikimedia\TestingAccessWrapper;
6 
12 
13  protected $tablesUsed = [
14  'revision',
15  'revision_actor_temp',
16  'ipblocks',
17  'recentchanges',
18  'actor',
19  ];
20 
26  protected function makeMigration( $stage ) {
27  return new ActorMigration( $stage );
28  }
29 
35  public function testConstructor( $stage, $exceptionMsg ) {
36  try {
37  $m = new ActorMigration( $stage );
38  if ( $exceptionMsg !== null ) {
39  $this->fail( 'Expected exception not thrown' );
40  }
41  $this->assertInstanceOf( ActorMigration::class, $m );
42  } catch ( InvalidArgumentException $ex ) {
43  $this->assertSame( $exceptionMsg, $ex->getMessage() );
44  }
45  }
46 
47  public static function provideConstructor() {
48  return [
49  [ 0, '$stage must include a write mode' ],
50  [ SCHEMA_COMPAT_READ_OLD, '$stage must include a write mode' ],
51  [ SCHEMA_COMPAT_READ_NEW, '$stage must include a write mode' ],
52  [ SCHEMA_COMPAT_READ_BOTH, '$stage must include a write mode' ],
53 
54  [ SCHEMA_COMPAT_WRITE_OLD, '$stage must include a read mode' ],
56  [
58  'Cannot read the new schema without also writing it'
59  ],
60  [ SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
61 
62  [ SCHEMA_COMPAT_WRITE_NEW, '$stage must include a read mode' ],
63  [
65  'Cannot read the old schema without also writing it'
66  ],
68  [ SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
69 
70  [ SCHEMA_COMPAT_WRITE_BOTH, '$stage must include a read mode' ],
73  [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
74  ];
75  }
76 
83  public function testGetJoin( $stage, $key, $expect ) {
84  $m = $this->makeMigration( $stage );
85  $result = $m->getJoin( $key );
86  $this->assertEquals( $expect, $result );
87  }
88 
89  public static function provideGetJoin() {
90  return [
91  'Simple table, old' => [
92  SCHEMA_COMPAT_OLD, 'rc_user', [
93  'tables' => [],
94  'fields' => [
95  'rc_user' => 'rc_user',
96  'rc_user_text' => 'rc_user_text',
97  'rc_actor' => 'NULL',
98  ],
99  'joins' => [],
100  ],
101  ],
102  'Simple table, read-old' => [
104  'tables' => [],
105  'fields' => [
106  'rc_user' => 'rc_user',
107  'rc_user_text' => 'rc_user_text',
108  'rc_actor' => 'NULL',
109  ],
110  'joins' => [],
111  ],
112  ],
113  'Simple table, read-new' => [
115  'tables' => [ 'actor_rc_user' => 'actor' ],
116  'fields' => [
117  'rc_user' => 'actor_rc_user.actor_user',
118  'rc_user_text' => 'actor_rc_user.actor_name',
119  'rc_actor' => 'rc_actor',
120  ],
121  'joins' => [
122  'actor_rc_user' => [ 'JOIN', 'actor_rc_user.actor_id = rc_actor' ],
123  ],
124  ],
125  ],
126  'Simple table, new' => [
127  SCHEMA_COMPAT_NEW, 'rc_user', [
128  'tables' => [ 'actor_rc_user' => 'actor' ],
129  'fields' => [
130  'rc_user' => 'actor_rc_user.actor_user',
131  'rc_user_text' => 'actor_rc_user.actor_name',
132  'rc_actor' => 'rc_actor',
133  ],
134  'joins' => [
135  'actor_rc_user' => [ 'JOIN', 'actor_rc_user.actor_id = rc_actor' ],
136  ],
137  ],
138  ],
139 
140  'ipblocks, old' => [
141  SCHEMA_COMPAT_OLD, 'ipb_by', [
142  'tables' => [],
143  'fields' => [
144  'ipb_by' => 'ipb_by',
145  'ipb_by_text' => 'ipb_by_text',
146  'ipb_by_actor' => 'NULL',
147  ],
148  'joins' => [],
149  ],
150  ],
151  'ipblocks, read-old' => [
153  'tables' => [],
154  'fields' => [
155  'ipb_by' => 'ipb_by',
156  'ipb_by_text' => 'ipb_by_text',
157  'ipb_by_actor' => 'NULL',
158  ],
159  'joins' => [],
160  ],
161  ],
162  'ipblocks, read-new' => [
164  'tables' => [ 'actor_ipb_by' => 'actor' ],
165  'fields' => [
166  'ipb_by' => 'actor_ipb_by.actor_user',
167  'ipb_by_text' => 'actor_ipb_by.actor_name',
168  'ipb_by_actor' => 'ipb_by_actor',
169  ],
170  'joins' => [
171  'actor_ipb_by' => [ 'JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
172  ],
173  ],
174  ],
175  'ipblocks, new' => [
176  SCHEMA_COMPAT_NEW, 'ipb_by', [
177  'tables' => [ 'actor_ipb_by' => 'actor' ],
178  'fields' => [
179  'ipb_by' => 'actor_ipb_by.actor_user',
180  'ipb_by_text' => 'actor_ipb_by.actor_name',
181  'ipb_by_actor' => 'ipb_by_actor',
182  ],
183  'joins' => [
184  'actor_ipb_by' => [ 'JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
185  ],
186  ],
187  ],
188 
189  'Revision, old' => [
190  SCHEMA_COMPAT_OLD, 'rev_user', [
191  'tables' => [],
192  'fields' => [
193  'rev_user' => 'rev_user',
194  'rev_user_text' => 'rev_user_text',
195  'rev_actor' => 'NULL',
196  ],
197  'joins' => [],
198  ],
199  ],
200  'Revision, read-old' => [
202  'tables' => [],
203  'fields' => [
204  'rev_user' => 'rev_user',
205  'rev_user_text' => 'rev_user_text',
206  'rev_actor' => 'NULL',
207  ],
208  'joins' => [],
209  ],
210  ],
211  'Revision, read-new' => [
213  'tables' => [
214  'temp_rev_user' => 'revision_actor_temp',
215  'actor_rev_user' => 'actor',
216  ],
217  'fields' => [
218  'rev_user' => 'actor_rev_user.actor_user',
219  'rev_user_text' => 'actor_rev_user.actor_name',
220  'rev_actor' => 'temp_rev_user.revactor_actor',
221  ],
222  'joins' => [
223  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
224  'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
225  ],
226  ],
227  ],
228  'Revision, new' => [
229  SCHEMA_COMPAT_NEW, 'rev_user', [
230  'tables' => [
231  'temp_rev_user' => 'revision_actor_temp',
232  'actor_rev_user' => 'actor',
233  ],
234  'fields' => [
235  'rev_user' => 'actor_rev_user.actor_user',
236  'rev_user_text' => 'actor_rev_user.actor_name',
237  'rev_actor' => 'temp_rev_user.revactor_actor',
238  ],
239  'joins' => [
240  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
241  'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
242  ],
243  ],
244  ],
245  ];
246  }
247 
256  public function testGetWhere( $stage, $key, $users, $useId, $expect ) {
257  $expect['conds'] = '(' . implode( ') OR (', $expect['orconds'] ) . ')';
258 
259  if ( count( $users ) === 1 ) {
260  $users = reset( $users );
261  }
262 
263  $m = $this->makeMigration( $stage );
264  $result = $m->getWhere( $this->db, $key, $users, $useId );
265  $this->assertEquals( $expect, $result );
266  }
267 
268  public function provideGetWhere() {
269  $makeUserIdentity = function ( $id, $name, $actor ) {
270  $u = $this->getMock( UserIdentity::class );
271  $u->method( 'getId' )->willReturn( $id );
272  $u->method( 'getName' )->willReturn( $name );
273  $u->method( 'getActorId' )->willReturn( $actor );
274  return $u;
275  };
276 
277  $genericUser = [ $makeUserIdentity( 1, 'User1', 11 ) ];
278  $complicatedUsers = [
279  $makeUserIdentity( 1, 'User1', 11 ),
280  $makeUserIdentity( 2, 'User2', 12 ),
281  $makeUserIdentity( 3, 'User3', 0 ),
282  $makeUserIdentity( 0, '192.168.12.34', 34 ),
283  $makeUserIdentity( 0, '192.168.12.35', 0 ),
284  ];
285 
286  return [
287  'Simple table, old' => [
288  SCHEMA_COMPAT_OLD, 'rc_user', $genericUser, true, [
289  'tables' => [],
290  'orconds' => [ 'userid' => "rc_user = '1'" ],
291  'joins' => [],
292  ],
293  ],
294  'Simple table, read-old' => [
295  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rc_user', $genericUser, true, [
296  'tables' => [],
297  'orconds' => [ 'userid' => "rc_user = '1'" ],
298  'joins' => [],
299  ],
300  ],
301  'Simple table, read-new' => [
302  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $genericUser, true, [
303  'tables' => [],
304  'orconds' => [ 'actor' => "rc_actor = '11'" ],
305  'joins' => [],
306  ],
307  ],
308  'Simple table, new' => [
309  SCHEMA_COMPAT_NEW, 'rc_user', $genericUser, true, [
310  'tables' => [],
311  'orconds' => [ 'actor' => "rc_actor = '11'" ],
312  'joins' => [],
313  ],
314  ],
315 
316  'ipblocks, old' => [
317  SCHEMA_COMPAT_OLD, 'ipb_by', $genericUser, true, [
318  'tables' => [],
319  'orconds' => [ 'userid' => "ipb_by = '1'" ],
320  'joins' => [],
321  ],
322  ],
323  'ipblocks, read-old' => [
324  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'ipb_by', $genericUser, true, [
325  'tables' => [],
326  'orconds' => [ 'userid' => "ipb_by = '1'" ],
327  'joins' => [],
328  ],
329  ],
330  'ipblocks, read-new' => [
331  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'ipb_by', $genericUser, true, [
332  'tables' => [],
333  'orconds' => [ 'actor' => "ipb_by_actor = '11'" ],
334  'joins' => [],
335  ],
336  ],
337  'ipblocks, new' => [
338  SCHEMA_COMPAT_NEW, 'ipb_by', $genericUser, true, [
339  'tables' => [],
340  'orconds' => [ 'actor' => "ipb_by_actor = '11'" ],
341  'joins' => [],
342  ],
343  ],
344 
345  'Revision, old' => [
346  SCHEMA_COMPAT_OLD, 'rev_user', $genericUser, true, [
347  'tables' => [],
348  'orconds' => [ 'userid' => "rev_user = '1'" ],
349  'joins' => [],
350  ],
351  ],
352  'Revision, read-old' => [
353  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rev_user', $genericUser, true, [
354  'tables' => [],
355  'orconds' => [ 'userid' => "rev_user = '1'" ],
356  'joins' => [],
357  ],
358  ],
359  'Revision, read-new' => [
360  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rev_user', $genericUser, true, [
361  'tables' => [
362  'temp_rev_user' => 'revision_actor_temp',
363  ],
364  'orconds' => [ 'actor' => "temp_rev_user.revactor_actor = '11'" ],
365  'joins' => [
366  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
367  ],
368  ],
369  ],
370  'Revision, new' => [
371  SCHEMA_COMPAT_NEW, 'rev_user', $genericUser, true, [
372  'tables' => [
373  'temp_rev_user' => 'revision_actor_temp',
374  ],
375  'orconds' => [ 'actor' => "temp_rev_user.revactor_actor = '11'" ],
376  'joins' => [
377  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
378  ],
379  ],
380  ],
381 
382  'Multiple users, old' => [
383  SCHEMA_COMPAT_OLD, 'rc_user', $complicatedUsers, true, [
384  'tables' => [],
385  'orconds' => [
386  'userid' => "rc_user IN ('1','2','3') ",
387  'username' => "rc_user_text IN ('192.168.12.34','192.168.12.35') "
388  ],
389  'joins' => [],
390  ],
391  ],
392  'Multiple users, read-old' => [
393  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rc_user', $complicatedUsers, true, [
394  'tables' => [],
395  'orconds' => [
396  'userid' => "rc_user IN ('1','2','3') ",
397  'username' => "rc_user_text IN ('192.168.12.34','192.168.12.35') "
398  ],
399  'joins' => [],
400  ],
401  ],
402  'Multiple users, read-new' => [
403  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $complicatedUsers, true, [
404  'tables' => [],
405  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
406  'joins' => [],
407  ],
408  ],
409  'Multiple users, new' => [
410  SCHEMA_COMPAT_NEW, 'rc_user', $complicatedUsers, true, [
411  'tables' => [],
412  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
413  'joins' => [],
414  ],
415  ],
416 
417  'Multiple users, no use ID, old' => [
418  SCHEMA_COMPAT_OLD, 'rc_user', $complicatedUsers, false, [
419  'tables' => [],
420  'orconds' => [
421  'username' => "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
422  ],
423  'joins' => [],
424  ],
425  ],
426  'Multiple users, read-old' => [
427  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rc_user', $complicatedUsers, false, [
428  'tables' => [],
429  'orconds' => [
430  'username' => "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
431  ],
432  'joins' => [],
433  ],
434  ],
435  'Multiple users, read-new' => [
436  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $complicatedUsers, false, [
437  'tables' => [],
438  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
439  'joins' => [],
440  ],
441  ],
442  'Multiple users, new' => [
443  SCHEMA_COMPAT_NEW, 'rc_user', $complicatedUsers, false, [
444  'tables' => [],
445  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
446  'joins' => [],
447  ],
448  ],
449  ];
450  }
451 
459  public function testInsertRoundTrip( $table, $key, $pk, $extraFields ) {
460  $u = $this->getTestUser()->getUser();
461  $user = $this->getMock( UserIdentity::class );
462  $user->method( 'getId' )->willReturn( $u->getId() );
463  $user->method( 'getName' )->willReturn( $u->getName() );
464  if ( $u->getActorId( $this->db ) ) {
465  $user->method( 'getActorId' )->willReturn( $u->getActorId() );
466  } else {
467  $this->db->insert(
468  'actor',
469  [ 'actor_user' => $u->getId(), 'actor_name' => $u->getName() ],
470  __METHOD__
471  );
472  $user->method( 'getActorId' )->willReturn( $this->db->insertId() );
473  }
474 
475  $stageNames = [
476  SCHEMA_COMPAT_OLD => 'old',
477  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD => 'write-both-read-old',
478  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW => 'write-both-read-new',
479  SCHEMA_COMPAT_NEW => 'new',
480  ];
481 
482  $stages = [
483  SCHEMA_COMPAT_OLD => [
486  ],
492  ],
498  ],
499  SCHEMA_COMPAT_NEW => [
502  ],
503  ];
504 
505  $nameKey = $key . '_text';
506  $actorKey = $key === 'ipb_by' ? 'ipb_by_actor' : substr( $key, 0, -5 ) . '_actor';
507 
508  foreach ( $stages as $writeStage => $possibleReadStages ) {
509  if ( $key === 'ipb_by' ) {
510  $extraFields['ipb_address'] = __CLASS__ . "#{$stageNames[$writeStage]}";
511  }
512 
513  $w = $this->makeMigration( $writeStage );
514  $usesTemp = $key === 'rev_user';
515 
516  if ( $usesTemp ) {
517  list( $fields, $callback ) = $w->getInsertValuesWithTempTable( $this->db, $key, $user );
518  } else {
519  $fields = $w->getInsertValues( $this->db, $key, $user );
520  }
521 
522  if ( $writeStage & SCHEMA_COMPAT_WRITE_OLD ) {
523  $this->assertSame( $user->getId(), $fields[$key],
524  "old field, stage={$stageNames[$writeStage]}" );
525  $this->assertSame( $user->getName(), $fields[$nameKey],
526  "old field, stage={$stageNames[$writeStage]}" );
527  } else {
528  $this->assertArrayNotHasKey( $key, $fields, "old field, stage={$stageNames[$writeStage]}" );
529  $this->assertArrayNotHasKey( $nameKey, $fields, "old field, stage={$stageNames[$writeStage]}" );
530  }
531  if ( ( $writeStage & SCHEMA_COMPAT_WRITE_NEW ) && !$usesTemp ) {
532  $this->assertSame( $user->getActorId(), $fields[$actorKey],
533  "new field, stage={$stageNames[$writeStage]}" );
534  } else {
535  $this->assertArrayNotHasKey( $actorKey, $fields,
536  "new field, stage={$stageNames[$writeStage]}" );
537  }
538 
539  $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
540  $id = $this->db->insertId();
541  if ( $usesTemp ) {
542  $callback( $id, $extraFields );
543  }
544 
545  foreach ( $possibleReadStages as $readStage ) {
546  $r = $this->makeMigration( $readStage );
547 
548  $queryInfo = $r->getJoin( $key );
549  $row = $this->db->selectRow(
550  [ $table ] + $queryInfo['tables'],
551  $queryInfo['fields'],
552  [ $pk => $id ],
553  __METHOD__,
554  [],
555  $queryInfo['joins']
556  );
557 
558  $this->assertSame( $user->getId(), (int)$row->$key,
559  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, id" );
560  $this->assertSame( $user->getName(), $row->$nameKey,
561  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, name" );
562  $this->assertSame(
563  ( $readStage & SCHEMA_COMPAT_READ_OLD ) ? 0 : $user->getActorId(),
564  (int)$row->$actorKey,
565  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, actor"
566  );
567  }
568  }
569  }
570 
571  public static function provideInsertRoundTrip() {
572  $db = wfGetDB( DB_REPLICA ); // for timestamps
573 
574  $comment = MediaWikiServices::getInstance()->getCommentStore()
575  ->createComment( wfGetDB( DB_MASTER ), '' );
576 
577  return [
578  'recentchanges' => [ 'recentchanges', 'rc_user', 'rc_id', [
579  'rc_timestamp' => $db->timestamp(),
580  'rc_namespace' => 0,
581  'rc_title' => 'Test',
582  'rc_this_oldid' => 42,
583  'rc_last_oldid' => 41,
584  'rc_source' => 'test',
585  'rc_comment_id' => $comment->id,
586  ] ],
587  'ipblocks' => [ 'ipblocks', 'ipb_by', 'ipb_id', [
588  'ipb_range_start' => '',
589  'ipb_range_end' => '',
590  'ipb_timestamp' => $db->timestamp(),
591  'ipb_expiry' => $db->getInfinity(),
592  'ipb_reason_id' => $comment->id,
593  ] ],
594  'revision' => [ 'revision', 'rev_user', 'rev_id', [
595  'rev_page' => 42,
596  'rev_len' => 0,
597  'rev_timestamp' => $db->timestamp(),
598  ] ],
599  ];
600  }
601 
602  public static function provideStages() {
603  return [
604  'old' => [ SCHEMA_COMPAT_OLD ],
607  'new' => [ SCHEMA_COMPAT_NEW ],
608  ];
609  }
610 
617  public function testInsertWrong( $stage ) {
618  $m = $this->makeMigration( $stage );
619  $m->getInsertValues( $this->db, 'rev_user', $this->getTestUser()->getUser() );
620  }
621 
628  public function testInsertWithTempTableWrong( $stage ) {
629  $m = $this->makeMigration( $stage );
630  $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
631  }
632 
637  public function testInsertWithTempTableDeprecated( $stage ) {
638  $wrap = TestingAccessWrapper::newFromClass( ActorMigration::class );
639  $wrap->formerTempTables += [ 'rc_user' => '1.30' ];
640 
641  $this->hideDeprecated( 'ActorMigration::getInsertValuesWithTempTable for rc_user' );
642  $m = $this->makeMigration( $stage );
643  list( $fields, $callback )
644  = $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
645  $this->assertTrue( is_callable( $callback ) );
646  }
647 
655  $m = $this->makeMigration( $stage );
656  list( $fields, $callback )
657  = $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $this->getTestUser()->getUser() );
658  $callback( 1, [] );
659  }
660 
665  public function testInsertUserIdentity( $stage ) {
666  $this->setMwGlobals( [
667  // for User::getActorId()
668  'wgActorTableSchemaMigrationStage' => $stage
669  ] );
670  $this->overrideMwServices();
671 
672  $user = $this->getMutableTestUser()->getUser();
673  $userIdentity = $this->getMock( UserIdentity::class );
674  $userIdentity->method( 'getId' )->willReturn( $user->getId() );
675  $userIdentity->method( 'getName' )->willReturn( $user->getName() );
676  $userIdentity->method( 'getActorId' )->willReturn( 0 );
677 
678  list( $cFields, $cCallback ) = MediaWikiServices::getInstance()->getCommentStore()
679  ->insertWithTempTable( $this->db, 'rev_comment', '' );
680  $m = $this->makeMigration( $stage );
681  list( $fields, $callback ) =
682  $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $userIdentity );
683  $extraFields = [
684  'rev_page' => 42,
685  'rev_len' => 0,
686  'rev_timestamp' => $this->db->timestamp(),
687  ] + $cFields;
688  $this->db->insert( 'revision', $extraFields + $fields, __METHOD__ );
689  $id = $this->db->insertId();
690  $callback( $id, $extraFields );
691  $cCallback( $id );
692 
693  $qi = $m->getJoin( 'rev_user' );
694  $row = $this->db->selectRow(
695  [ 'revision' ] + $qi['tables'], $qi['fields'], [ 'rev_id' => $id ], __METHOD__, [], $qi['joins']
696  );
697  $this->assertSame( $user->getId(), (int)$row->rev_user );
698  $this->assertSame( $user->getName(), $row->rev_user_text );
699  $this->assertSame(
700  ( $stage & SCHEMA_COMPAT_READ_NEW ) ? $user->getActorId() : 0,
701  (int)$row->rev_actor
702  );
703 
704  $m = $this->makeMigration( $stage );
705  $fields = $m->getInsertValues( $this->db, 'dummy_user', $userIdentity );
706  if ( $stage & SCHEMA_COMPAT_WRITE_OLD ) {
707  $this->assertSame( $user->getId(), $fields['dummy_user'] );
708  $this->assertSame( $user->getName(), $fields['dummy_user_text'] );
709  } else {
710  $this->assertArrayNotHasKey( 'dummy_user', $fields );
711  $this->assertArrayNotHasKey( 'dummy_user_text', $fields );
712  }
713  if ( $stage & SCHEMA_COMPAT_WRITE_NEW ) {
714  $this->assertSame( $user->getActorId(), $fields['dummy_actor'] );
715  } else {
716  $this->assertArrayNotHasKey( 'dummy_actor', $fields );
717  }
718  }
719 
720  public function testNewMigration() {
722  $this->assertInstanceOf( ActorMigration::class, $m );
723  $this->assertSame( $m, ActorMigration::newMigration() );
724  }
725 
732  public function testIsAnon( $stage, $isAnon, $isNotAnon ) {
733  $m = $this->makeMigration( $stage );
734  $this->assertSame( $isAnon, $m->isAnon( 'foo' ) );
735  $this->assertSame( $isNotAnon, $m->isNotAnon( 'foo' ) );
736  }
737 
738  public static function provideIsAnon() {
739  return [
740  'old' => [ SCHEMA_COMPAT_OLD, 'foo = 0', 'foo != 0' ],
741  'read-old' => [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'foo = 0', 'foo != 0' ],
742  'read-new' => [
743  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'foo IS NULL', 'foo IS NOT NULL'
744  ],
745  'new' => [ SCHEMA_COMPAT_NEW, 'foo IS NULL', 'foo IS NOT NULL' ],
746  ];
747  }
748 
749 }
ActorMigrationTest\testInsertUserIdentity
testInsertUserIdentity( $stage)
provideStages
Definition: ActorMigrationTest.php:665
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
ActorMigrationTest\$tablesUsed
$tablesUsed
Definition: ActorMigrationTest.php:13
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
ActorMigrationTest\provideInsertRoundTrip
static provideInsertRoundTrip()
Definition: ActorMigrationTest.php:571
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
captcha-old.count
count
Definition: captcha-old.py:249
ActorMigrationTest\provideConstructor
static provideConstructor()
Definition: ActorMigrationTest.php:47
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1983
ActorMigration
This class handles the logic for the actor table migration.
Definition: ActorMigration.php:35
ActorMigrationTest\testInsertWithTempTableCallbackMissingFields
testInsertWithTempTableCallbackMissingFields( $stage)
provideStages
Definition: ActorMigrationTest.php:654
ActorMigrationTest\makeMigration
makeMigration( $stage)
Create an ActorMigration for a particular stage.
Definition: ActorMigrationTest.php:26
ActorMigrationTest\provideGetJoin
static provideGetJoin()
Definition: ActorMigrationTest.php:89
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ActorMigrationTest\provideIsAnon
static provideIsAnon()
Definition: ActorMigrationTest.php:738
MediaWikiTestCase\overrideMwServices
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
Definition: MediaWikiTestCase.php:937
ActorMigrationTest\testInsertRoundTrip
testInsertRoundTrip( $table, $key, $pk, $extraFields)
provideInsertRoundTrip
Definition: ActorMigrationTest.php:459
ActorMigrationTest\testInsertWithTempTableDeprecated
testInsertWithTempTableDeprecated( $stage)
provideStages
Definition: ActorMigrationTest.php:637
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1974
ActorMigrationTest\provideStages
static provideStages()
Definition: ActorMigrationTest.php:602
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWikiTestCase\$users
static TestUser[] $users
Definition: MediaWikiTestCase.php:53
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ActorMigrationTest\testGetJoin
testGetJoin( $stage, $key, $expect)
provideGetJoin
Definition: ActorMigrationTest.php:83
ActorMigrationTest\provideGetWhere
provideGetWhere()
Definition: ActorMigrationTest.php:268
DB_MASTER
const DB_MASTER
Definition: defines.php:26
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
ActorMigrationTest\testConstructor
testConstructor( $stage, $exceptionMsg)
provideConstructor
Definition: ActorMigrationTest.php:35
ActorMigrationTest\testNewMigration
testNewMigration()
Definition: ActorMigrationTest.php:720
ActorMigrationTest\testInsertWithTempTableWrong
testInsertWithTempTableWrong( $stage)
provideStages
Definition: ActorMigrationTest.php:628
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:192
SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_WRITE_OLD
Definition: Defines.php:284
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
SCHEMA_COMPAT_WRITE_NEW
const SCHEMA_COMPAT_WRITE_NEW
Definition: Defines.php:286
ActorMigrationTest\testGetWhere
testGetWhere( $stage, $key, $users, $useId, $expect)
provideGetWhere
Definition: ActorMigrationTest.php:256
ActorMigrationTest\testInsertWrong
testInsertWrong( $stage)
provideStages
Definition: ActorMigrationTest.php:617
SCHEMA_COMPAT_NEW
const SCHEMA_COMPAT_NEW
Definition: Defines.php:291
SCHEMA_COMPAT_OLD
const SCHEMA_COMPAT_OLD
Definition: Defines.php:290
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_WRITE_BOTH
Definition: Defines.php:288
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
ActorMigrationTest\testIsAnon
testIsAnon( $stage, $isAnon, $isNotAnon)
provideIsAnon
Definition: ActorMigrationTest.php:732
SCHEMA_COMPAT_READ_BOTH
const SCHEMA_COMPAT_READ_BOTH
Definition: Defines.php:289
SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_READ_OLD
Definition: Defines.php:285
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:61
ActorMigrationTest
Database ActorMigration.
Definition: ActorMigrationTest.php:11