Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SchemaHooks
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 onLoadExtensionSchemaUpdates
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * Hooks for ContentTranslation extension.
4 *
5 * @copyright See AUTHORS.txt
6 * @license GPL-2.0-or-later
7 */
8namespace ContentTranslation;
9
10use DatabaseUpdater;
11use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook;
12
13class SchemaHooks implements LoadExtensionSchemaUpdatesHook {
14
15    /**
16     * Hook: LoadExtensionSchemaUpdates
17     * @param DatabaseUpdater $updater
18     */
19    public function onLoadExtensionSchemaUpdates( $updater ) {
20        global $wgContentTranslationCluster, $wgContentTranslationDatabase;
21
22        // Following tables should only be created if both cluster and database are false.
23        // Otherwise, they are not created in the place they are accesses, because
24        // DatabaseUpdater does not support other databases other than main wiki schema.
25        if ( $wgContentTranslationCluster !== false || $wgContentTranslationDatabase !== false ) {
26            return;
27        }
28
29        $dir = dirname( __DIR__ );
30        $dbType = $updater->getDB()->getType();
31
32        // All tables for the extension
33        $updater->addExtensionTable( 'cx_translations', "$dir/sql/$dbType/tables-generated.sql" );
34
35        // 1.35
36        $updater->addExtensionTable( 'cx_notification_log', "$dir/sql/notification-log.sql" );
37
38        // 1.37
39        $updater->addExtensionField(
40            'cx_notification_log',
41            'cxn_wiki_id',
42            "$dir/sql/patch-2020-09-21-notification-log-add-wikiid.sql"
43        );
44
45        // 1.38
46        $updater->addExtensionTable( 'cx_significant_edits', "$dir/sql/significant-edits.sql" );
47        $updater->addExtensionTable( 'cx_section_translations', "$dir/sql/section-translations.sql" );
48
49        // Here we want to add "cxsx_translation_status" and "cxsx_translation_progress".
50        // Since those 2 fields have been added together, we can add only one of them to the
51        // updater, and the other one will be picked up by the updater anyway.
52        // 1.41
53        $updater->addExtensionField(
54            'cx_section_translations',
55            'cxsx_translation_status',
56            "$dir/sql/$dbType/patch-new-fields-to-cx_section_translations.sql"
57        );
58
59        // 1.39
60        if ( $dbType === 'mysql' ) {
61            $updater->modifyExtensionField(
62                'cx_lists',
63                'cxl_end_time',
64                "$dir/sql/patch-cx_lists-timestamps.sql"
65            );
66            $updater->modifyExtensionField(
67                'cx_notification_log',
68                'cxn_newest',
69                "$dir/sql/patch-cx_notification_log-timestamps.sql"
70            );
71            $updater->modifyExtensionField(
72                'cx_corpora',
73                'cxc_timestamp',
74                "$dir/sql/patch-cx_corpora-timestamp.sql"
75            );
76            $updater->modifyExtensionField(
77                'cx_translations',
78                'translation_last_updated_timestamp',
79                "$dir/sql/patch-cx_translations-timestamps.sql"
80            );
81            $updater->modifyExtensionField(
82                'cx_notification_log',
83                'cxn_wiki_id',
84                "$dir/sql/patch-tables-binary.sql"
85            );
86        }
87        $updater->dropExtensionIndex(
88            'cx_translators',
89            'cx_translation_translators',
90            "$dir/sql/$dbType/patch-cx_translators-unique-to-pk.sql"
91        );
92        $updater->addExtensionIndex(
93            'cx_translations',
94            'cx_translation_target_title',
95            "$dir/sql/$dbType/patch-cx_translations-target-title-index.sql"
96        );
97    }
98
99}