Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MigrateSearchPagePrefs | |
0.00% |
0 / 42 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MediaSearch\Maintenance; |
4 | |
5 | use Maintenance; |
6 | |
7 | $IP = getenv( 'MW_INSTALL_PATH' ); |
8 | if ( $IP === false ) { |
9 | $IP = __DIR__ . '/../../..'; |
10 | } |
11 | require_once "$IP/maintenance/Maintenance.php"; |
12 | |
13 | /** |
14 | * Migrate users from sdms-specialsearch-default to the core search-special-page preference. |
15 | * |
16 | * Users used to indicate their preference for Special:Search instead of Special:MediaSearch |
17 | * via the extension-owned `sdms-specialsearch-default` preference. There is now a core |
18 | * preference for this, called `search-special-page`. |
19 | */ |
20 | class MigrateSearchPagePrefs extends Maintenance { |
21 | |
22 | public function __construct() { |
23 | parent::__construct(); |
24 | $this->addDescription( 'Migrate users from sdms-specialsearch-default to the core ' |
25 | . 'search-special-page preference' ); |
26 | |
27 | $this->requireExtension( 'MediaSearch' ); |
28 | } |
29 | |
30 | public function execute() { |
31 | $dbr = $this->getReplicaDB(); |
32 | $userIds = $dbr->newSelectQueryBuilder() |
33 | ->select( [ 'up_user' ] ) |
34 | ->from( 'user_properties' ) |
35 | ->where( [ |
36 | 'up_property' => 'sdms-specialsearch-default', |
37 | 'up_value' => '1', |
38 | ] ) |
39 | ->caller( __METHOD__ ) |
40 | ->fetchResultSet(); |
41 | if ( !$userIds->numRows() ) { |
42 | return; |
43 | } |
44 | $insertRows = []; |
45 | $deleteUserIds = []; |
46 | foreach ( $userIds as $userId ) { |
47 | $userId = (int)$userId; |
48 | $insertRows[] = [ |
49 | 'up_user' => $userId, |
50 | 'up_property' => 'search-special-page', |
51 | 'up_value' => 'Search', |
52 | ]; |
53 | $deleteUserIds[] = $userId; |
54 | } |
55 | |
56 | $dbw = $this->getPrimaryDB(); |
57 | $this->beginTransaction( $dbw, __METHOD__ ); |
58 | $dbw->newInsertQueryBuilder() |
59 | ->insertInto( 'user_properties' ) |
60 | ->rows( $insertRows ) |
61 | ->caller( __METHOD__ ) |
62 | ->execute(); |
63 | $dbw->newDeleteQueryBuilder() |
64 | ->deleteFrom( 'user_properties' ) |
65 | ->where( [ |
66 | 'up_user' => $deleteUserIds, |
67 | 'up_property' => 'sdms-specialsearch-default', |
68 | ] ) |
69 | ->caller( __METHOD__ ) |
70 | ->execute(); |
71 | $this->commitTransaction( $dbw, __METHOD__ ); |
72 | } |
73 | } |
74 | |
75 | $maintClass = MigrateSearchPagePrefs::class; |
76 | require_once RUN_MAINTENANCE_IF_MAIN; |