szurubooru/src/Api/Jobs/EditUserNameJob.php
Marcin Kurczewski 4ba83e6834 Changed job arguments convention back
Restored JobArgs approach. Previous introduction of hierarchic argument
definitions has backfired: it was confusing what class to take arguments
from, the concept of sharing arguments between different jobs was
unintelligible and one never knew where given argument was actually
defined.

This appraoch makes it easier to maintain the arguments list and
simplifies the code a lot.
2014-05-12 00:13:18 +02:00

39 lines
891 B
PHP

<?php
class EditUserNameJob extends AbstractUserJob
{
public function isSatisfied()
{
return $this->hasArgument(JobArgs::ARG_NEW_USER_NAME);
}
public function execute()
{
$user = $this->user;
$newName = $this->getArgument(JobArgs::ARG_NEW_USER_NAME);
$oldName = $user->getName();
if ($oldName == $newName)
return $user;
$user->setName($newName);
if ($this->getContext() == self::CONTEXT_NORMAL)
UserModel::save($user);
Logger::log('{user} renamed {old} to {new}', [
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
'old' => TextHelper::reprUser($oldName),
'new' => TextHelper::reprUser($newName)]);
return $user;
}
public function requiresPrivilege()
{
return new Privilege(
$this->getContext() == self::CONTEXT_BATCH_ADD
? Privilege::RegisterAccount
: Privilege::ChangeUserName,
Access::getIdentity($this->user));
}
}