Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / Revision / McrSchemaDetection.php
1 <?php
2
3 namespace MediaWiki\Tests\Revision;
4
5 use Wikimedia\Rdbms\IDatabase;
6
7 /**
8 * Trait providing methods for detecting which MCR schema migration phase the current schema
9 * is compatible with.
10 */
11 trait McrSchemaDetection {
12
13 /**
14 * Returns true if MCR-related tables exist in the database.
15 * If yes, the database is compatible with with MIGRATION_NEW.
16 * If hasPreMcrFields() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
17 *
18 * @param IDatabase $db
19 * @return bool
20 */
21 protected function hasMcrTables( IDatabase $db ) {
22 return $db->tableExists( 'slots', __METHOD__ );
23 }
24
25 /**
26 * Returns true if pre-MCR fields still exist in the database.
27 * If yes, the database is compatible with with MIGRATION_OLD mode.
28 * If hasMcrTables() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
29 *
30 * Note that if the database has been updated in MIGRATION_NEW mode,
31 * the rev_text_id field will be 0 for new revisions. This means that
32 * in MIGRATION_OLD mode, reading such revisions will fail, even though
33 * all the necessary fields exist.
34 * This is not relevant for unit tests, since unit tests reset the database content anyway.
35 *
36 * @param IDatabase $db
37 * @return bool
38 */
39 protected function hasPreMcrFields( IDatabase $db ) {
40 return $db->fieldExists( 'revision', 'rev_content_model', __METHOD__ );
41 }
42
43 }