X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=maintenance%2FchangePassword.php;h=f276fc16370b25b8ade748d2a7ac770ed13ececf;hb=023b1dafd3a961bef261925e14e26554dd4e6c9d;hp=edc37de14cfd7ff2eec1c73c1bf8d3c2b52f98f1;hpb=d881d1fdcafd7510ef16281c8dec079db990e8cf;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/changePassword.php b/maintenance/changePassword.php index edc37de14c..f276fc1637 100644 --- a/maintenance/changePassword.php +++ b/maintenance/changePassword.php @@ -24,19 +24,31 @@ * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once( __DIR__ . '/Maintenance.php' ); +/** + * Maintenance script to change the password of a given user. + * + * @ingroup Maintenance + */ class ChangePassword extends Maintenance { public function __construct() { parent::__construct(); - $this->addOption( "user", "The username to operate on", true, true ); + $this->addOption( "user", "The username to operate on", false, true ); + $this->addOption( "userid", "The user id to operate on", false, true ); $this->addOption( "password", "The password to use", true, true ); $this->mDescription = "Change a user's password"; } - + public function execute() { - $user = User::newFromName( $this->getOption( 'user' ) ); - if ( !$user->getId() ) { + if ( $this->hasOption( "user" ) ) { + $user = User::newFromName( $this->getOption( 'user' ) ); + } elseif ( $this->hasOption( "userid" ) ) { + $user = User::newFromId( $this->getOption( 'userid' ) ); + } else { + $this->error( "A \"user\" or \"userid\" must be set to change the password for" , true ); + } + if ( !$user || !$user->getId() ) { $this->error( "No such user: " . $this->getOption( 'user' ), true ); } try { @@ -50,4 +62,4 @@ class ChangePassword extends Maintenance { } $maintClass = "ChangePassword"; -require_once( DO_MAINTENANCE ); +require_once( RUN_MAINTENANCE_IF_MAIN );