MediaWiki  1.34.0
UserOptionsUpdateJob.php
Go to the documentation of this file.
1 <?php
33 class UserOptionsUpdateJob extends Job implements GenericParameterJob {
34  public function __construct( array $params ) {
35  parent::__construct( 'userOptionsUpdate', $params );
36  $this->removeDuplicates = true;
37  }
38 
39  public function run() {
40  if ( !$this->params['options'] ) {
41  return true; // nothing to do
42  }
43 
44  $user = User::newFromId( $this->params['userId'] );
45  $user->load( $user::READ_EXCLUSIVE );
46  if ( !$user->getId() ) {
47  return true;
48  }
49 
50  foreach ( $this->params['options'] as $name => $value ) {
51  $user->setOption( $name, $value );
52  }
53 
54  $user->saveSettings();
55 
56  return true;
57  }
58 }
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:539
UserOptionsUpdateJob\__construct
__construct(array $params)
Definition: UserOptionsUpdateJob.php:34
UserOptionsUpdateJob\run
run()
Run the job.
Definition: UserOptionsUpdateJob.php:39
Job\$params
array $params
Array of job parameters.
Definition: Job.php:35
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:30
UserOptionsUpdateJob
Job that updates a user's preferences.
Definition: UserOptionsUpdateJob.php:33
GenericParameterJob
Interface for generic jobs only uses the parameters field and are JSON serializable.
Definition: GenericParameterJob.php:29