MediaWiki  master
ActorMigrationTest.php
Go to the documentation of this file.
1 <?php
2 
6 
12 
13  protected $tablesUsed = [
14  'revision',
15  'revision_actor_temp',
16  'ipblocks',
17  'recentchanges',
18  'actor',
19  ];
20 
26  public function testConstructor( $stage, $exceptionMsg ) {
27  try {
28  $m = new ActorMigration( $stage );
29  if ( $exceptionMsg !== null ) {
30  $this->fail( 'Expected exception not thrown' );
31  }
32  $this->assertInstanceOf( ActorMigration::class, $m );
33  } catch ( InvalidArgumentException $ex ) {
34  $this->assertSame( $exceptionMsg, $ex->getMessage() );
35  }
36  }
37 
38  public static function provideConstructor() {
39  return [
40  [ 0, '$stage must include a write mode' ],
41  [ SCHEMA_COMPAT_READ_OLD, '$stage must include a write mode' ],
42  [ SCHEMA_COMPAT_READ_NEW, '$stage must include a write mode' ],
43  [ SCHEMA_COMPAT_READ_BOTH, '$stage must include a write mode' ],
44 
45  [ SCHEMA_COMPAT_WRITE_OLD, '$stage must include a read mode' ],
46  [ SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_OLD, null ],
47  [
48  SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_NEW,
49  'Cannot read the new schema without also writing it'
50  ],
51  [ SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
52 
53  [ SCHEMA_COMPAT_WRITE_NEW, '$stage must include a read mode' ],
54  [
55  SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_OLD,
56  'Cannot read the old schema without also writing it'
57  ],
58  [ SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_NEW, null ],
59  [ SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
60 
61  [ SCHEMA_COMPAT_WRITE_BOTH, '$stage must include a read mode' ],
62  [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, null ],
63  [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, null ],
64  [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_BOTH, 'Cannot read both schemas' ],
65  ];
66  }
67 
74  public function testGetJoin( $stage, $key, $expect ) {
75  $m = new ActorMigration( $stage );
76  $result = $m->getJoin( $key );
77  $this->assertEquals( $expect, $result );
78  }
79 
80  public static function provideGetJoin() {
81  return [
82  'Simple table, old' => [
83  SCHEMA_COMPAT_OLD, 'rc_user', [
84  'tables' => [],
85  'fields' => [
86  'rc_user' => 'rc_user',
87  'rc_user_text' => 'rc_user_text',
88  'rc_actor' => 'NULL',
89  ],
90  'joins' => [],
91  ],
92  ],
93  'Simple table, read-old' => [
95  'tables' => [],
96  'fields' => [
97  'rc_user' => 'rc_user',
98  'rc_user_text' => 'rc_user_text',
99  'rc_actor' => 'NULL',
100  ],
101  'joins' => [],
102  ],
103  ],
104  'Simple table, read-new' => [
106  'tables' => [ 'actor_rc_user' => 'actor' ],
107  'fields' => [
108  'rc_user' => 'actor_rc_user.actor_user',
109  'rc_user_text' => 'actor_rc_user.actor_name',
110  'rc_actor' => 'rc_actor',
111  ],
112  'joins' => [
113  'actor_rc_user' => [ 'JOIN', 'actor_rc_user.actor_id = rc_actor' ],
114  ],
115  ],
116  ],
117  'Simple table, new' => [
118  SCHEMA_COMPAT_NEW, 'rc_user', [
119  'tables' => [ 'actor_rc_user' => 'actor' ],
120  'fields' => [
121  'rc_user' => 'actor_rc_user.actor_user',
122  'rc_user_text' => 'actor_rc_user.actor_name',
123  'rc_actor' => 'rc_actor',
124  ],
125  'joins' => [
126  'actor_rc_user' => [ 'JOIN', 'actor_rc_user.actor_id = rc_actor' ],
127  ],
128  ],
129  ],
130 
131  'ipblocks, old' => [
132  SCHEMA_COMPAT_OLD, 'ipb_by', [
133  'tables' => [],
134  'fields' => [
135  'ipb_by' => 'ipb_by',
136  'ipb_by_text' => 'ipb_by_text',
137  'ipb_by_actor' => 'NULL',
138  ],
139  'joins' => [],
140  ],
141  ],
142  'ipblocks, read-old' => [
144  'tables' => [],
145  'fields' => [
146  'ipb_by' => 'ipb_by',
147  'ipb_by_text' => 'ipb_by_text',
148  'ipb_by_actor' => 'NULL',
149  ],
150  'joins' => [],
151  ],
152  ],
153  'ipblocks, read-new' => [
155  'tables' => [ 'actor_ipb_by' => 'actor' ],
156  'fields' => [
157  'ipb_by' => 'actor_ipb_by.actor_user',
158  'ipb_by_text' => 'actor_ipb_by.actor_name',
159  'ipb_by_actor' => 'ipb_by_actor',
160  ],
161  'joins' => [
162  'actor_ipb_by' => [ 'JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
163  ],
164  ],
165  ],
166  'ipblocks, new' => [
167  SCHEMA_COMPAT_NEW, 'ipb_by', [
168  'tables' => [ 'actor_ipb_by' => 'actor' ],
169  'fields' => [
170  'ipb_by' => 'actor_ipb_by.actor_user',
171  'ipb_by_text' => 'actor_ipb_by.actor_name',
172  'ipb_by_actor' => 'ipb_by_actor',
173  ],
174  'joins' => [
175  'actor_ipb_by' => [ 'JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
176  ],
177  ],
178  ],
179 
180  'Revision, old' => [
181  SCHEMA_COMPAT_OLD, 'rev_user', [
182  'tables' => [],
183  'fields' => [
184  'rev_user' => 'rev_user',
185  'rev_user_text' => 'rev_user_text',
186  'rev_actor' => 'NULL',
187  ],
188  'joins' => [],
189  ],
190  ],
191  'Revision, read-old' => [
193  'tables' => [],
194  'fields' => [
195  'rev_user' => 'rev_user',
196  'rev_user_text' => 'rev_user_text',
197  'rev_actor' => 'NULL',
198  ],
199  'joins' => [],
200  ],
201  ],
202  'Revision, read-new' => [
204  'tables' => [
205  'temp_rev_user' => 'revision_actor_temp',
206  'actor_rev_user' => 'actor',
207  ],
208  'fields' => [
209  'rev_user' => 'actor_rev_user.actor_user',
210  'rev_user_text' => 'actor_rev_user.actor_name',
211  'rev_actor' => 'temp_rev_user.revactor_actor',
212  ],
213  'joins' => [
214  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
215  'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
216  ],
217  ],
218  ],
219  'Revision, new' => [
220  SCHEMA_COMPAT_NEW, 'rev_user', [
221  'tables' => [
222  'temp_rev_user' => 'revision_actor_temp',
223  'actor_rev_user' => 'actor',
224  ],
225  'fields' => [
226  'rev_user' => 'actor_rev_user.actor_user',
227  'rev_user_text' => 'actor_rev_user.actor_name',
228  'rev_actor' => 'temp_rev_user.revactor_actor',
229  ],
230  'joins' => [
231  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
232  'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
233  ],
234  ],
235  ],
236  ];
237  }
238 
247  public function testGetWhere( $stage, $key, $users, $useId, $expect ) {
248  $expect['conds'] = '(' . implode( ') OR (', $expect['orconds'] ) . ')';
249 
250  if ( count( $users ) === 1 ) {
251  $users = reset( $users );
252  }
253 
254  $m = new ActorMigration( $stage );
255  $result = $m->getWhere( $this->db, $key, $users, $useId );
256  $this->assertEquals( $expect, $result );
257  }
258 
259  public function provideGetWhere() {
260  $makeUserIdentity = function ( $id, $name, $actor ) {
261  $u = $this->getMock( UserIdentity::class );
262  $u->method( 'getId' )->willReturn( $id );
263  $u->method( 'getName' )->willReturn( $name );
264  $u->method( 'getActorId' )->willReturn( $actor );
265  return $u;
266  };
267 
268  $genericUser = [ $makeUserIdentity( 1, 'User1', 11 ) ];
269  $complicatedUsers = [
270  $makeUserIdentity( 1, 'User1', 11 ),
271  $makeUserIdentity( 2, 'User2', 12 ),
272  $makeUserIdentity( 3, 'User3', 0 ),
273  $makeUserIdentity( 0, '192.168.12.34', 34 ),
274  $makeUserIdentity( 0, '192.168.12.35', 0 ),
275  ];
276 
277  return [
278  'Simple table, old' => [
279  SCHEMA_COMPAT_OLD, 'rc_user', $genericUser, true, [
280  'tables' => [],
281  'orconds' => [ 'userid' => "rc_user = '1'" ],
282  'joins' => [],
283  ],
284  ],
285  'Simple table, read-old' => [
286  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rc_user', $genericUser, true, [
287  'tables' => [],
288  'orconds' => [ 'userid' => "rc_user = '1'" ],
289  'joins' => [],
290  ],
291  ],
292  'Simple table, read-new' => [
293  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $genericUser, true, [
294  'tables' => [],
295  'orconds' => [ 'actor' => "rc_actor = '11'" ],
296  'joins' => [],
297  ],
298  ],
299  'Simple table, new' => [
300  SCHEMA_COMPAT_NEW, 'rc_user', $genericUser, true, [
301  'tables' => [],
302  'orconds' => [ 'actor' => "rc_actor = '11'" ],
303  'joins' => [],
304  ],
305  ],
306 
307  'ipblocks, old' => [
308  SCHEMA_COMPAT_OLD, 'ipb_by', $genericUser, true, [
309  'tables' => [],
310  'orconds' => [ 'userid' => "ipb_by = '1'" ],
311  'joins' => [],
312  ],
313  ],
314  'ipblocks, read-old' => [
315  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'ipb_by', $genericUser, true, [
316  'tables' => [],
317  'orconds' => [ 'userid' => "ipb_by = '1'" ],
318  'joins' => [],
319  ],
320  ],
321  'ipblocks, read-new' => [
322  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'ipb_by', $genericUser, true, [
323  'tables' => [],
324  'orconds' => [ 'actor' => "ipb_by_actor = '11'" ],
325  'joins' => [],
326  ],
327  ],
328  'ipblocks, new' => [
329  SCHEMA_COMPAT_NEW, 'ipb_by', $genericUser, true, [
330  'tables' => [],
331  'orconds' => [ 'actor' => "ipb_by_actor = '11'" ],
332  'joins' => [],
333  ],
334  ],
335 
336  'Revision, old' => [
337  SCHEMA_COMPAT_OLD, 'rev_user', $genericUser, true, [
338  'tables' => [],
339  'orconds' => [ 'userid' => "rev_user = '1'" ],
340  'joins' => [],
341  ],
342  ],
343  'Revision, read-old' => [
344  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rev_user', $genericUser, true, [
345  'tables' => [],
346  'orconds' => [ 'userid' => "rev_user = '1'" ],
347  'joins' => [],
348  ],
349  ],
350  'Revision, read-new' => [
351  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rev_user', $genericUser, true, [
352  'tables' => [
353  'temp_rev_user' => 'revision_actor_temp',
354  ],
355  'orconds' => [ 'actor' => "temp_rev_user.revactor_actor = '11'" ],
356  'joins' => [
357  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
358  ],
359  ],
360  ],
361  'Revision, new' => [
362  SCHEMA_COMPAT_NEW, 'rev_user', $genericUser, true, [
363  'tables' => [
364  'temp_rev_user' => 'revision_actor_temp',
365  ],
366  'orconds' => [ 'actor' => "temp_rev_user.revactor_actor = '11'" ],
367  'joins' => [
368  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
369  ],
370  ],
371  ],
372 
373  'Multiple users, old' => [
374  SCHEMA_COMPAT_OLD, 'rc_user', $complicatedUsers, true, [
375  'tables' => [],
376  'orconds' => [
377  'userid' => "rc_user IN ('1','2','3') ",
378  'username' => "rc_user_text IN ('192.168.12.34','192.168.12.35') "
379  ],
380  'joins' => [],
381  ],
382  ],
383  'Multiple users, read-old' => [
384  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'rc_user', $complicatedUsers, true, [
385  'tables' => [],
386  'orconds' => [
387  'userid' => "rc_user IN ('1','2','3') ",
388  'username' => "rc_user_text IN ('192.168.12.34','192.168.12.35') "
389  ],
390  'joins' => [],
391  ],
392  ],
393  'Multiple users, read-new' => [
394  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $complicatedUsers, true, [
395  'tables' => [],
396  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
397  'joins' => [],
398  ],
399  ],
400  'Multiple users, new' => [
401  SCHEMA_COMPAT_NEW, 'rc_user', $complicatedUsers, true, [
402  'tables' => [],
403  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
404  'joins' => [],
405  ],
406  ],
407 
408  'Multiple users, no use ID, old' => [
409  SCHEMA_COMPAT_OLD, 'rc_user', $complicatedUsers, false, [
410  'tables' => [],
411  'orconds' => [
412  'username' => "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
413  ],
414  'joins' => [],
415  ],
416  ],
417  'Multiple users, read-old' => [
418  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_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-new' => [
427  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'rc_user', $complicatedUsers, false, [
428  'tables' => [],
429  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
430  'joins' => [],
431  ],
432  ],
433  'Multiple users, new' => [
434  SCHEMA_COMPAT_NEW, 'rc_user', $complicatedUsers, false, [
435  'tables' => [],
436  'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
437  'joins' => [],
438  ],
439  ],
440  ];
441  }
442 
450  public function testInsertRoundTrip( $table, $key, $pk, $extraFields ) {
451  $u = $this->getTestUser()->getUser();
452  $user = $this->getMock( UserIdentity::class );
453  $user->method( 'getId' )->willReturn( $u->getId() );
454  $user->method( 'getName' )->willReturn( $u->getName() );
455  if ( $u->getActorId( $this->db ) ) {
456  $user->method( 'getActorId' )->willReturn( $u->getActorId() );
457  } else {
458  $this->db->insert(
459  'actor',
460  [ 'actor_user' => $u->getId(), 'actor_name' => $u->getName() ],
461  __METHOD__
462  );
463  $user->method( 'getActorId' )->willReturn( $this->db->insertId() );
464  }
465 
466  $stageNames = [
467  SCHEMA_COMPAT_OLD => 'old',
468  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD => 'write-both-read-old',
469  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW => 'write-both-read-new',
470  SCHEMA_COMPAT_NEW => 'new',
471  ];
472 
473  $stages = [
474  SCHEMA_COMPAT_OLD => [
477  ],
483  ],
489  ],
490  SCHEMA_COMPAT_NEW => [
493  ],
494  ];
495 
496  $nameKey = $key . '_text';
497  $actorKey = $key === 'ipb_by' ? 'ipb_by_actor' : substr( $key, 0, -5 ) . '_actor';
498 
499  foreach ( $stages as $writeStage => $possibleReadStages ) {
500  if ( $key === 'ipb_by' ) {
501  $extraFields['ipb_address'] = __CLASS__ . "#{$stageNames[$writeStage]}";
502  }
503 
504  $w = new ActorMigration( $writeStage );
505  $usesTemp = $key === 'rev_user';
506 
507  if ( $usesTemp ) {
508  list( $fields, $callback ) = $w->getInsertValuesWithTempTable( $this->db, $key, $user );
509  } else {
510  $fields = $w->getInsertValues( $this->db, $key, $user );
511  }
512 
513  if ( $writeStage & SCHEMA_COMPAT_WRITE_OLD ) {
514  $this->assertSame( $user->getId(), $fields[$key],
515  "old field, stage={$stageNames[$writeStage]}" );
516  $this->assertSame( $user->getName(), $fields[$nameKey],
517  "old field, stage={$stageNames[$writeStage]}" );
518  } else {
519  $this->assertArrayNotHasKey( $key, $fields, "old field, stage={$stageNames[$writeStage]}" );
520  $this->assertArrayNotHasKey( $nameKey, $fields, "old field, stage={$stageNames[$writeStage]}" );
521  }
522  if ( ( $writeStage & SCHEMA_COMPAT_WRITE_NEW ) && !$usesTemp ) {
523  $this->assertSame( $user->getActorId(), $fields[$actorKey],
524  "new field, stage={$stageNames[$writeStage]}" );
525  } else {
526  $this->assertArrayNotHasKey( $actorKey, $fields,
527  "new field, stage={$stageNames[$writeStage]}" );
528  }
529 
530  $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
531  $id = $this->db->insertId();
532  if ( $usesTemp ) {
533  $callback( $id, $extraFields );
534  }
535 
536  foreach ( $possibleReadStages as $readStage ) {
537  $r = new ActorMigration( $readStage );
538 
539  $queryInfo = $r->getJoin( $key );
540  $row = $this->db->selectRow(
541  [ $table ] + $queryInfo['tables'],
542  $queryInfo['fields'],
543  [ $pk => $id ],
544  __METHOD__,
545  [],
546  $queryInfo['joins']
547  );
548 
549  $this->assertSame( $user->getId(), (int)$row->$key,
550  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, id" );
551  $this->assertSame( $user->getName(), $row->$nameKey,
552  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, name" );
553  $this->assertSame(
554  ( $readStage & SCHEMA_COMPAT_READ_OLD ) ? 0 : $user->getActorId(),
555  (int)$row->$actorKey,
556  "w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, actor"
557  );
558  }
559  }
560  }
561 
562  public static function provideInsertRoundTrip() {
563  $db = wfGetDB( DB_REPLICA ); // for timestamps
564 
565  $comment = MediaWikiServices::getInstance()->getCommentStore()
566  ->createComment( wfGetDB( DB_MASTER ), '' );
567 
568  return [
569  'recentchanges' => [ 'recentchanges', 'rc_user', 'rc_id', [
570  'rc_timestamp' => $db->timestamp(),
571  'rc_namespace' => 0,
572  'rc_title' => 'Test',
573  'rc_this_oldid' => 42,
574  'rc_last_oldid' => 41,
575  'rc_source' => 'test',
576  'rc_comment_id' => $comment->id,
577  ] ],
578  'ipblocks' => [ 'ipblocks', 'ipb_by', 'ipb_id', [
579  'ipb_range_start' => '',
580  'ipb_range_end' => '',
581  'ipb_timestamp' => $db->timestamp(),
582  'ipb_expiry' => $db->getInfinity(),
583  'ipb_reason_id' => $comment->id,
584  ] ],
585  'revision' => [ 'revision', 'rev_user', 'rev_id', [
586  'rev_page' => 42,
587  'rev_len' => 0,
588  'rev_timestamp' => $db->timestamp(),
589  ] ],
590  ];
591  }
592 
593  public static function provideStages() {
594  return [
595  'old' => [ SCHEMA_COMPAT_OLD ],
598  'new' => [ SCHEMA_COMPAT_NEW ],
599  ];
600  }
601 
608  public function testInsertWrong( $stage ) {
609  $m = new ActorMigration( $stage );
610  $m->getInsertValues( $this->db, 'rev_user', $this->getTestUser()->getUser() );
611  }
612 
619  public function testInsertWithTempTableWrong( $stage ) {
620  $m = new ActorMigration( $stage );
621  $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
622  }
623 
628  public function testInsertWithTempTableDeprecated( $stage ) {
629  $wrap = TestingAccessWrapper::newFromClass( ActorMigration::class );
630  $wrap->formerTempTables += [ 'rc_user' => '1.30' ];
631 
632  $this->hideDeprecated( 'ActorMigration::getInsertValuesWithTempTable for rc_user' );
633  $m = new ActorMigration( $stage );
634  list( $fields, $callback )
635  = $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
636  $this->assertTrue( is_callable( $callback ) );
637  }
638 
646  $m = new ActorMigration( $stage );
647  list( $fields, $callback )
648  = $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $this->getTestUser()->getUser() );
649  $callback( 1, [] );
650  }
651 
656  public function testInsertUserIdentity( $stage ) {
657  $this->setMwGlobals( [
658  // for User::getActorId()
659  'wgActorTableSchemaMigrationStage' => $stage
660  ] );
661  $this->overrideMwServices();
662 
663  $user = $this->getMutableTestUser()->getUser();
664  $userIdentity = $this->getMock( UserIdentity::class );
665  $userIdentity->method( 'getId' )->willReturn( $user->getId() );
666  $userIdentity->method( 'getName' )->willReturn( $user->getName() );
667  $userIdentity->method( 'getActorId' )->willReturn( 0 );
668 
669  list( $cFields, $cCallback ) = MediaWikiServices::getInstance()->getCommentStore()
670  ->insertWithTempTable( $this->db, 'rev_comment', '' );
671  $m = new ActorMigration( $stage );
672  list( $fields, $callback ) =
673  $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $userIdentity );
674  $extraFields = [
675  'rev_page' => 42,
676  'rev_len' => 0,
677  'rev_timestamp' => $this->db->timestamp(),
678  ] + $cFields;
679  $this->db->insert( 'revision', $extraFields + $fields, __METHOD__ );
680  $id = $this->db->insertId();
681  $callback( $id, $extraFields );
682  $cCallback( $id );
683 
684  $qi = $m->getJoin( 'rev_user' );
685  $row = $this->db->selectRow(
686  [ 'revision' ] + $qi['tables'], $qi['fields'], [ 'rev_id' => $id ], __METHOD__, [], $qi['joins']
687  );
688  $this->assertSame( $user->getId(), (int)$row->rev_user );
689  $this->assertSame( $user->getName(), $row->rev_user_text );
690  $this->assertSame(
691  ( $stage & SCHEMA_COMPAT_READ_NEW ) ? $user->getActorId() : 0,
692  (int)$row->rev_actor
693  );
694 
695  $m = new ActorMigration( $stage );
696  $fields = $m->getInsertValues( $this->db, 'dummy_user', $userIdentity );
697  if ( $stage & SCHEMA_COMPAT_WRITE_OLD ) {
698  $this->assertSame( $user->getId(), $fields['dummy_user'] );
699  $this->assertSame( $user->getName(), $fields['dummy_user_text'] );
700  } else {
701  $this->assertArrayNotHasKey( 'dummy_user', $fields );
702  $this->assertArrayNotHasKey( 'dummy_user_text', $fields );
703  }
704  if ( $stage & SCHEMA_COMPAT_WRITE_NEW ) {
705  $this->assertSame( $user->getActorId(), $fields['dummy_actor'] );
706  } else {
707  $this->assertArrayNotHasKey( 'dummy_actor', $fields );
708  }
709  }
710 
711  public function testNewMigration() {
713  $this->assertInstanceOf( ActorMigration::class, $m );
714  $this->assertSame( $m, ActorMigration::newMigration() );
715  }
716 
723  public function testIsAnon( $stage, $isAnon, $isNotAnon ) {
724  $m = new ActorMigration( $stage );
725  $this->assertSame( $isAnon, $m->isAnon( 'foo' ) );
726  $this->assertSame( $isNotAnon, $m->isNotAnon( 'foo' ) );
727  }
728 
729  public static function provideIsAnon() {
730  return [
731  'old' => [ SCHEMA_COMPAT_OLD, 'foo = 0', 'foo != 0' ],
732  'read-old' => [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, 'foo = 0', 'foo != 0' ],
733  'read-new' => [
734  SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, 'foo IS NULL', 'foo IS NOT NULL'
735  ],
736  'new' => [ SCHEMA_COMPAT_NEW, 'foo IS NULL', 'foo IS NOT NULL' ],
737  ];
738  }
739 
740 }
const SCHEMA_COMPAT_WRITE_OLD
Definition: Defines.php:280
testInsertWithTempTableCallbackMissingFields( $stage)
provideStages
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
const SCHEMA_COMPAT_READ_BOTH
Definition: Defines.php:285
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:283
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
const DB_MASTER
Definition: defines.php:26
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:1980
testInsertUserIdentity( $stage)
provideStages
testGetWhere( $stage, $key, $users, $useId, $expect)
provideGetWhere
static newMigration()
Static constructor.
testIsAnon( $stage, $isAnon, $isNotAnon)
provideIsAnon
const SCHEMA_COMPAT_WRITE_NEW
Definition: Defines.php:282
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
testInsertWithTempTableWrong( $stage)
provideStages
testInsertWithTempTableDeprecated( $stage)
provideStages
testGetJoin( $stage, $key, $expect)
provideGetJoin
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
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
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
const SCHEMA_COMPAT_WRITE_BOTH
Definition: Defines.php:284
hideDeprecated( $function)
Don&#39;t throw a warning if $function is deprecated and called later.
static TestUser [] $users
testInsertWrong( $stage)
provideStages
Database ActorMigration.
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
testConstructor( $stage, $exceptionMsg)
provideConstructor
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
const SCHEMA_COMPAT_NEW
Definition: Defines.php:287
Database $db
Primary database.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
testInsertRoundTrip( $table, $key, $pk, $extraFields)
provideInsertRoundTrip
const DB_REPLICA
Definition: defines.php:25
const SCHEMA_COMPAT_READ_OLD
Definition: Defines.php:281
const SCHEMA_COMPAT_OLD
Definition: Defines.php:286
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473