~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to include/RenameUserJob.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * Custom job to perform updates on tables in busier environments
5
 
 */
6
 
class RenameUserJob extends Job {
7
 
 
8
 
        /**
9
 
         * Constructor
10
 
         *
11
 
         * @param Title $title Associated title
12
 
         * @param array $params Job parameters
13
 
         */
14
 
        public function __construct( $title, $params ) {
15
 
                parent::__construct( 'renameUser', $title, $params );
16
 
        }
17
 
 
18
 
        /**
19
 
         * Execute the job
20
 
         *
21
 
         * @return bool
22
 
         */
23
 
        public function run() {
24
 
                $dbw = wfGetDB( DB_MASTER );
25
 
                extract( $this->params );
26
 
                # Conditions like "*_user_text = 'x'
27
 
                $conds = array( $column => $oldname );
28
 
                # If user ID given, add that to condition to avoid rename collisions.
29
 
                if( isset($userID) ) {
30
 
                        $conds[$uidColumn] = $userID;
31
 
                }
32
 
                # Bound by timestamp if given
33
 
                if( isset($timestampColumn) ) {
34
 
                        $conds[] = "$timestampColumn >= '$minTimestamp'";
35
 
                        $conds[] = "$timestampColumn <= '$maxTimestamp'";
36
 
                # Otherwise, bound by key (B/C)
37
 
                } else if( isset($uniqueKey) ) {
38
 
                        $conds[$uniqueKey] = $keyId;
39
 
                } else {
40
 
                        wfDebug( 'RenameUserJob::run - invalid job row given' ); // this shouldn't happen
41
 
                        return false;
42
 
                }
43
 
                # Update a chuck of rows!
44
 
                $dbw->update( $table,
45
 
                        array( $column => $newname ),
46
 
                        $conds,
47
 
                        __METHOD__
48
 
                );
49
 
                # Special case: revisions may be deleted while renaming...
50
 
                if( $table == 'revision' && isset($timestampColumn) ) {
51
 
                        $actual = $dbw->affectedRows();
52
 
                        # If some revisions were not renamed, they may have been deleted.
53
 
                        # Do a pass on the archive table to get these straglers...
54
 
                        if( $actual < $count ) {
55
 
                                $dbw->update( 'archive',
56
 
                                        array( 'ar_user_text' => $newname ),
57
 
                                        array( 'ar_user_text' => $oldname,
58
 
                                                'ar_user' => $userID,
59
 
                                                // No user,rev_id index, so use timestamp to bound
60
 
                                                // the rows. This can use the user,timestamp index.
61
 
                                                "ar_timestamp >= '$minTimestamp'",
62
 
                                                "ar_timestamp <= '$maxTimestamp'"),
63
 
                                        __METHOD__
64
 
                                );
65
 
                        }
66
 
                }
67
 
                # Special case: revisions may be restored while renaming...
68
 
                if( $table == 'archive' && isset($timestampColumn) ) {
69
 
                        $actual = $dbw->affectedRows();
70
 
                        # If some revisions were not renamed, they may have been restored.
71
 
                        # Do a pass on the revision table to get these straglers...
72
 
                        if( $actual < $count ) {
73
 
                                $dbw->update( 'revision',
74
 
                                        array( 'rev_user_text' => $newname ),
75
 
                                        array( 'rev_user_text' => $oldname,
76
 
                                                'rev_user' => $userID,
77
 
                                                // No user,rev_id index, so use timestamp to bound
78
 
                                                // the rows. This can use the user,timestamp index.
79
 
                                                "rev_timestamp >= '$minTimestamp'",
80
 
                                                "rev_timestamp <= '$maxTimestamp'"),
81
 
                                        __METHOD__
82
 
                                );
83
 
                        }
84
 
                }
85
 
                return true;
86
 
        }
87
 
 
88
 
}
 
 
b'\\ No newline at end of file'