56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\HannahBundle\Admin\Actions;
|
|
|
|
use External\HannahBundle\SAP\Synchronizer\UserSynchronizer;
|
|
use KupShop\AdminBundle\Admin\Actions\AbstractAction;
|
|
use KupShop\AdminBundle\Admin\Actions\ActionResult;
|
|
use KupShop\AdminBundle\Admin\Actions\IAction;
|
|
use Query\Operator;
|
|
|
|
class UserSAPUpdateAction extends AbstractAction implements IAction
|
|
{
|
|
private UserSynchronizer $userSynchronizer;
|
|
|
|
public function __construct(UserSynchronizer $userSynchronizer)
|
|
{
|
|
$this->userSynchronizer = $userSynchronizer;
|
|
}
|
|
|
|
public function getTypes(): array
|
|
{
|
|
return ['users'];
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return '[SAP] Aktualizovat uživatele';
|
|
}
|
|
|
|
public function execute(&$data, array $config, string $type): ActionResult
|
|
{
|
|
$item = sqlQueryBuilder()
|
|
->select('u.id, su.id_sap')
|
|
->from('users', 'u')
|
|
->leftJoin('u', 'sap_users', 'su', 'u.id = su.id_user')
|
|
->andWhere(Operator::equals(['u.id' => $this->getId()]))
|
|
->execute()->fetchAssociative();
|
|
|
|
if ($item) {
|
|
if ($result = $this->userSynchronizer->updateUserToSAP($item, true)) {
|
|
[$user, $isNewlyAdded] = $result;
|
|
|
|
if ($isNewlyAdded) {
|
|
$this->userSynchronizer->updateNewlyAddedUserFromSAP($user);
|
|
}
|
|
|
|
return new ActionResult(true);
|
|
}
|
|
}
|
|
|
|
return new ActionResult(false, 'Uživatele se nepodařilo aktualizovat.');
|
|
}
|
|
}
|