This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Api/Jobs/EditUserJob.php

69 lines
1 KiB
PHP
Raw Normal View History

2014-05-04 13:39:00 +02:00
<?php
class EditUserJob extends AbstractUserEditJob
2014-05-04 13:39:00 +02:00
{
2014-05-04 16:27:15 +02:00
protected $subJobs;
2014-05-04 13:39:00 +02:00
2014-05-04 16:27:15 +02:00
public function __construct()
{
$this->subJobs =
2014-05-04 13:39:00 +02:00
[
2014-05-04 14:57:44 +02:00
new EditUserAccessRankJob(),
2014-05-04 13:39:00 +02:00
new EditUserNameJob(),
new EditUserPasswordJob(),
new EditUserEmailJob(),
];
2014-05-04 16:27:15 +02:00
}
public function canEditAnything($user)
{
$this->privileges = [];
foreach ($this->subJobs as $subJob)
{
try
{
$subJob->user = $user;
Api::checkPrivileges($subJob);
return true;
}
catch (SimpleException $e)
{
}
}
return false;
}
public function execute()
{
$user = $this->user;
LogHelper::bufferChanges();
2014-05-04 13:39:00 +02:00
foreach ($this->subJobs as $subJob)
2014-05-04 13:39:00 +02:00
{
if ($this->skipSaving)
$subJob->skipSaving();
2014-05-04 13:39:00 +02:00
$args = $this->getArguments();
$args[self::USER_ENTITY] = $user;
2014-05-04 13:39:00 +02:00
try
{
Api::run($subJob, $args);
}
catch (ApiMissingArgumentException $e)
{
}
}
if (!$this->skipSaving)
UserModel::save($user);
2014-05-04 13:39:00 +02:00
LogHelper::flush();
return $user;
}
2014-05-04 16:27:15 +02:00
public function requiresPrivilege()
{
return false;
}
2014-05-04 13:39:00 +02:00
}