Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FixTranslationNotificationsEmptyLangPrefs
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This script removes the empty translationnotifications-lang-* properties.
5 * They became default and should not be stored.
6 *
7 * @author Amir E. Aharoni
8 * based on Narayam/maintenance/FixNarayamDisablePref.php
9 *
10 * @copyright Copyright © 2012
11 * @license GPL-2.0-or-later
12 * @file
13 */
14
15namespace MediaWiki\Extension\TranslationNotifications;
16
17// Standard boilerplate to define $IP
18use Maintenance;
19use Wikimedia\Rdbms\IExpression;
20use Wikimedia\Rdbms\LikeValue;
21
22if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
23    $IP = getenv( 'MW_INSTALL_PATH' );
24} else {
25    $IP = __DIR__ . "/../../..";
26}
27require_once "$IP/maintenance/Maintenance.php";
28
29class FixTranslationNotificationsEmptyLangPrefs extends Maintenance {
30
31    public function __construct() {
32        parent::__construct();
33
34        $this->requireExtension( 'TranslationNotifications' );
35    }
36
37    public function execute() {
38        $dbw = $this->getPrimaryDB();
39
40        $langPropertyPrefix = 'translationnotifications-lang-';
41        $this->output( "Deleting empty {$langPropertyPrefix}* property values\n" );
42
43        $dbw->newDeleteQueryBuilder()
44            ->deleteFrom( 'user_properties' )
45            ->where(
46                $dbw->expr(
47                    'up_property',
48                    IExpression::LIKE,
49                    new LikeValue( $langPropertyPrefix, $dbw->anyString() )
50                )
51            )
52            ->andWhere( $dbw->expr( 'up_value', '=', '' ) )
53            ->caller( __METHOD__ )
54            ->execute();
55    }
56}
57
58$maintClass = FixTranslationNotificationsEmptyLangPrefs::class;
59require_once RUN_MAINTENANCE_IF_MAIN;