Index: trunk/extensions/CentralAuth/migratePass0.php |
— | — | @@ -1,75 +0,0 @@ |
2 | | -<?php |
3 | | -// --> disable account creations, password changes |
4 | | -// pass 0: |
5 | | -// * generate 'globalnames' and 'localnames' entries for each user on each wiki |
6 | | -// --> enable |
7 | | - |
8 | | -require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
9 | | - |
10 | | -/** |
11 | | - * Copy user data for this wiki into the localuser table |
12 | | - */ |
13 | | -function migratePassZero() { |
14 | | - global $wgDBname; |
15 | | - $dbr = wfGetDB( DB_SLAVE ); |
16 | | - $chunkSize = 1000; |
17 | | - |
18 | | - $start = microtime( true ); |
19 | | - $migrated = 0; |
20 | | - $users = array(); |
21 | | - |
22 | | - // List all user accounts on this wiki in the migration table |
23 | | - // on the central authentication server. |
24 | | - |
25 | | - $lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __FUNCTION__ ); |
26 | | - for ( $min = 0; $min <= $lastUser; $min += $chunkSize ) { |
27 | | - $max = $min + $chunkSize; |
28 | | - $result = $dbr->select( 'user', |
29 | | - array( 'user_id', 'user_name' ), |
30 | | - "user_id BETWEEN $min AND $max", |
31 | | - __FUNCTION__ ); |
32 | | - |
33 | | - foreach( $result as $row ) { |
34 | | - $users[intval( $row->user_id )] = $row->user_name; |
35 | | - ++$migrated; |
36 | | - } |
37 | | - |
38 | | - CentralAuthUser::storeMigrationData( $wgDBname, $users ); |
39 | | - |
40 | | - $delta = microtime( true ) - $start; |
41 | | - $rate = ( $delta == 0.0 ) ? 0.0 : $migrated / $delta; |
42 | | - printf( "%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n", |
43 | | - $wgDBname, |
44 | | - $migrated, |
45 | | - min( $max, $lastUser ) / $lastUser * 100.0, |
46 | | - $delta, |
47 | | - $rate ); |
48 | | - } |
49 | | -} |
50 | | - |
51 | | -/** |
52 | | - * @param $userId |
53 | | - * @return int |
54 | | - */ |
55 | | -function getEditCount( $userId ) { |
56 | | - return countEdits( $userId, 'revision', 'rev_user' ); |
57 | | -} |
58 | | - |
59 | | -/** |
60 | | - * @param $userId |
61 | | - * @param $table |
62 | | - * @param $field |
63 | | - * @return int |
64 | | - */ |
65 | | -function countEdits( $userId, $table, $field ) { |
66 | | - $dbr = wfGetDB( DB_SLAVE ); |
67 | | - $count = $dbr->selectField( $table, 'COUNT(*)', |
68 | | - array( $field => $userId ), |
69 | | - __METHOD__ ); |
70 | | - return intval( $count ); |
71 | | -} |
72 | | - |
73 | | -echo "CentralAuth migration pass 0:\n"; |
74 | | -echo "$wgDBname preparing migration data...\n"; |
75 | | -migratePassZero(); |
76 | | -echo "done.\n"; |
Index: trunk/extensions/CentralAuth/migratePass1.php |
— | — | @@ -1,53 +0,0 @@ |
2 | | -<?php |
3 | | -// pass 1: |
4 | | -// * generate 'globaluser' entries for each username |
5 | | -// * go through all usernames in 'globalnames' and for those |
6 | | -// that can be automatically migrated, go ahead and do it. |
7 | | - |
8 | | -require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
9 | | - |
10 | | -function migratePassOne() { |
11 | | - $migrated = 0; |
12 | | - $total = 0; |
13 | | - $chunkSize = 1000; |
14 | | - $start = microtime( true ); |
15 | | - |
16 | | - $dbBackground = CentralAuthUser::getCentralSlaveDB(); |
17 | | - $result = $dbBackground->select( |
18 | | - 'globalnames', |
19 | | - array( 'gn_name' ), |
20 | | - '', |
21 | | - __METHOD__ ); |
22 | | - foreach( $result as $row ) { |
23 | | - $name = $row->gn_name; |
24 | | - $central = new CentralAuthUser( $name ); |
25 | | - if ( $central->storeAndMigrate() ) { |
26 | | - $migrated++; |
27 | | - } |
28 | | - if ( ++$total % $chunkSize == 0 ) { |
29 | | - migratePassOneReport( $migrated, $total, $start ); |
30 | | - } |
31 | | - } |
32 | | - migratePassOneReport( $migrated, $total, $start ); |
33 | | - echo "DONE\n"; |
34 | | -} |
35 | | - |
36 | | -/** |
37 | | - * @param $migrated |
38 | | - * @param $total |
39 | | - * @param $start |
40 | | - */ |
41 | | -function migratePassOneReport( $migrated, $total, $start ) { |
42 | | - $delta = microtime( true ) - $start; |
43 | | - printf( "%s processed %d usernames (%.1f/sec), %d (%.1f%%) fully migrated\n", |
44 | | - wfTimestamp( TS_DB ), |
45 | | - $total, |
46 | | - $total / $delta, |
47 | | - $migrated, |
48 | | - $migrated / $total * 100.0 ); |
49 | | -} |
50 | | - |
51 | | -echo "CentralAuth migration pass 1:\n"; |
52 | | -echo "Finding accounts which can be migrated without interaction...\n"; |
53 | | -migratePassOne(); |
54 | | -echo "done.\n"; |
Index: trunk/extensions/CentralAuth/migrateStewards.php |
— | — | @@ -1,51 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
5 | | - |
6 | | -echo "Populating global groups table with stewards...\n"; |
7 | | - |
8 | | -// Fetch local stewards |
9 | | -$dbl = wfGetDB( DB_SLAVE ); // Get local database |
10 | | -$result = $dbl->select( |
11 | | - array( 'user', 'user_groups' ), |
12 | | - array( 'user_name' ), |
13 | | - array( |
14 | | - 'ug_group' => 'steward', |
15 | | - 'user_id = ug_user' |
16 | | - ), |
17 | | - 'migrateStewards.php' |
18 | | -); |
19 | | -$localStewards = array(); |
20 | | -foreach ( $result as $row ) { |
21 | | - $localStewards[] = $row->user_name; |
22 | | -} |
23 | | - |
24 | | -echo "Fetched " . count( $localStewards ) . " from local database... Checking for attached ones\n"; |
25 | | -$dbg = CentralAuthUser::getCentralDB(); |
26 | | -$globalStewards = array(); |
27 | | -$result = $dbg->select( |
28 | | - array( 'globaluser', 'localuser' ), |
29 | | - array( 'gu_name', 'gu_id' ), |
30 | | - array( |
31 | | - 'gu_name = lu_name', |
32 | | - 'lu_wiki' => wfWikiId(), |
33 | | - 'gu_name IN (' . $dbg->makeList( $localStewards ) . ')', |
34 | | - ), |
35 | | - 'migrateStewards.php' |
36 | | -); |
37 | | -foreach ( $result as $row ) { |
38 | | - $globalStewards[$row->gu_name] = $row->gu_id; |
39 | | -} |
40 | | - |
41 | | -echo "Fetched " . count( $localStewards ) . " SULed stewards... Adding them in group\n"; |
42 | | -foreach ( $globalStewards as $user => $id ) { |
43 | | - $dbg->insert( 'global_user_groups', |
44 | | - array( |
45 | | - 'gug_user' => $id, |
46 | | - 'gug_group' => 'steward' ), |
47 | | - 'migrateStewards.php' ); |
48 | | - echo "Added {$user}\n"; |
49 | | - |
50 | | - $u = new CentralAuthUser( $user ); |
51 | | - $u->quickInvalidateCache(); // Don't bother regenerating the steward's cache. |
52 | | -} |
Index: trunk/extensions/CentralAuth/maintenance/migratePass0.php |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +<?php |
| 3 | +// --> disable account creations, password changes |
| 4 | +// pass 0: |
| 5 | +// * generate 'globalnames' and 'localnames' entries for each user on each wiki |
| 6 | +// --> enable |
| 7 | + |
| 8 | +require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
| 9 | + |
| 10 | +/** |
| 11 | + * Copy user data for this wiki into the localuser table |
| 12 | + */ |
| 13 | +function migratePassZero() { |
| 14 | + global $wgDBname; |
| 15 | + $dbr = wfGetDB( DB_SLAVE ); |
| 16 | + $chunkSize = 1000; |
| 17 | + |
| 18 | + $start = microtime( true ); |
| 19 | + $migrated = 0; |
| 20 | + $users = array(); |
| 21 | + |
| 22 | + // List all user accounts on this wiki in the migration table |
| 23 | + // on the central authentication server. |
| 24 | + |
| 25 | + $lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __FUNCTION__ ); |
| 26 | + for ( $min = 0; $min <= $lastUser; $min += $chunkSize ) { |
| 27 | + $max = $min + $chunkSize; |
| 28 | + $result = $dbr->select( 'user', |
| 29 | + array( 'user_id', 'user_name' ), |
| 30 | + "user_id BETWEEN $min AND $max", |
| 31 | + __FUNCTION__ ); |
| 32 | + |
| 33 | + foreach( $result as $row ) { |
| 34 | + $users[intval( $row->user_id )] = $row->user_name; |
| 35 | + ++$migrated; |
| 36 | + } |
| 37 | + |
| 38 | + CentralAuthUser::storeMigrationData( $wgDBname, $users ); |
| 39 | + |
| 40 | + $delta = microtime( true ) - $start; |
| 41 | + $rate = ( $delta == 0.0 ) ? 0.0 : $migrated / $delta; |
| 42 | + printf( "%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n", |
| 43 | + $wgDBname, |
| 44 | + $migrated, |
| 45 | + min( $max, $lastUser ) / $lastUser * 100.0, |
| 46 | + $delta, |
| 47 | + $rate ); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * @param $userId |
| 53 | + * @return int |
| 54 | + */ |
| 55 | +function getEditCount( $userId ) { |
| 56 | + return countEdits( $userId, 'revision', 'rev_user' ); |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * @param $userId |
| 61 | + * @param $table |
| 62 | + * @param $field |
| 63 | + * @return int |
| 64 | + */ |
| 65 | +function countEdits( $userId, $table, $field ) { |
| 66 | + $dbr = wfGetDB( DB_SLAVE ); |
| 67 | + $count = $dbr->selectField( $table, 'COUNT(*)', |
| 68 | + array( $field => $userId ), |
| 69 | + __METHOD__ ); |
| 70 | + return intval( $count ); |
| 71 | +} |
| 72 | + |
| 73 | +echo "CentralAuth migration pass 0:\n"; |
| 74 | +echo "$wgDBname preparing migration data...\n"; |
| 75 | +migratePassZero(); |
| 76 | +echo "done.\n"; |
Property changes on: trunk/extensions/CentralAuth/maintenance/migratePass0.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 77 | + native |
Index: trunk/extensions/CentralAuth/maintenance/migratePass1.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +// pass 1: |
| 4 | +// * generate 'globaluser' entries for each username |
| 5 | +// * go through all usernames in 'globalnames' and for those |
| 6 | +// that can be automatically migrated, go ahead and do it. |
| 7 | + |
| 8 | +require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
| 9 | + |
| 10 | +function migratePassOne() { |
| 11 | + $migrated = 0; |
| 12 | + $total = 0; |
| 13 | + $chunkSize = 1000; |
| 14 | + $start = microtime( true ); |
| 15 | + |
| 16 | + $dbBackground = CentralAuthUser::getCentralSlaveDB(); |
| 17 | + $result = $dbBackground->select( |
| 18 | + 'globalnames', |
| 19 | + array( 'gn_name' ), |
| 20 | + '', |
| 21 | + __METHOD__ ); |
| 22 | + foreach( $result as $row ) { |
| 23 | + $name = $row->gn_name; |
| 24 | + $central = new CentralAuthUser( $name ); |
| 25 | + if ( $central->storeAndMigrate() ) { |
| 26 | + $migrated++; |
| 27 | + } |
| 28 | + if ( ++$total % $chunkSize == 0 ) { |
| 29 | + migratePassOneReport( $migrated, $total, $start ); |
| 30 | + } |
| 31 | + } |
| 32 | + migratePassOneReport( $migrated, $total, $start ); |
| 33 | + echo "DONE\n"; |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * @param $migrated |
| 38 | + * @param $total |
| 39 | + * @param $start |
| 40 | + */ |
| 41 | +function migratePassOneReport( $migrated, $total, $start ) { |
| 42 | + $delta = microtime( true ) - $start; |
| 43 | + printf( "%s processed %d usernames (%.1f/sec), %d (%.1f%%) fully migrated\n", |
| 44 | + wfTimestamp( TS_DB ), |
| 45 | + $total, |
| 46 | + $total / $delta, |
| 47 | + $migrated, |
| 48 | + $migrated / $total * 100.0 ); |
| 49 | +} |
| 50 | + |
| 51 | +echo "CentralAuth migration pass 1:\n"; |
| 52 | +echo "Finding accounts which can be migrated without interaction...\n"; |
| 53 | +migratePassOne(); |
| 54 | +echo "done.\n"; |
Property changes on: trunk/extensions/CentralAuth/maintenance/migratePass1.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |
Index: trunk/extensions/CentralAuth/maintenance/migrateStewards.php |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require dirname( __FILE__ ) . '/../../maintenance/commandLine.inc'; |
| 5 | + |
| 6 | +echo "Populating global groups table with stewards...\n"; |
| 7 | + |
| 8 | +// Fetch local stewards |
| 9 | +$dbl = wfGetDB( DB_SLAVE ); // Get local database |
| 10 | +$result = $dbl->select( |
| 11 | + array( 'user', 'user_groups' ), |
| 12 | + array( 'user_name' ), |
| 13 | + array( |
| 14 | + 'ug_group' => 'steward', |
| 15 | + 'user_id = ug_user' |
| 16 | + ), |
| 17 | + 'migrateStewards.php' |
| 18 | +); |
| 19 | +$localStewards = array(); |
| 20 | +foreach ( $result as $row ) { |
| 21 | + $localStewards[] = $row->user_name; |
| 22 | +} |
| 23 | + |
| 24 | +echo "Fetched " . count( $localStewards ) . " from local database... Checking for attached ones\n"; |
| 25 | +$dbg = CentralAuthUser::getCentralDB(); |
| 26 | +$globalStewards = array(); |
| 27 | +$result = $dbg->select( |
| 28 | + array( 'globaluser', 'localuser' ), |
| 29 | + array( 'gu_name', 'gu_id' ), |
| 30 | + array( |
| 31 | + 'gu_name = lu_name', |
| 32 | + 'lu_wiki' => wfWikiId(), |
| 33 | + 'gu_name IN (' . $dbg->makeList( $localStewards ) . ')', |
| 34 | + ), |
| 35 | + 'migrateStewards.php' |
| 36 | +); |
| 37 | +foreach ( $result as $row ) { |
| 38 | + $globalStewards[$row->gu_name] = $row->gu_id; |
| 39 | +} |
| 40 | + |
| 41 | +echo "Fetched " . count( $localStewards ) . " SULed stewards... Adding them in group\n"; |
| 42 | +foreach ( $globalStewards as $user => $id ) { |
| 43 | + $dbg->insert( 'global_user_groups', |
| 44 | + array( |
| 45 | + 'gug_user' => $id, |
| 46 | + 'gug_group' => 'steward' ), |
| 47 | + 'migrateStewards.php' ); |
| 48 | + echo "Added {$user}\n"; |
| 49 | + |
| 50 | + $u = new CentralAuthUser( $user ); |
| 51 | + $u->quickInvalidateCache(); // Don't bother regenerating the steward's cache. |
| 52 | +} |
Property changes on: trunk/extensions/CentralAuth/maintenance/migrateStewards.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |