entityManager->getRDBRepositoryByClass(User::class); $user = $repository ->where(['userName' => ApplicationUser::SYSTEM_USER_NAME]) ->findOne(); if ($user) { return; } // @todo If a user with the 'system' ID already exists, delete it from DB. /** @var array $attributes */ $attributes = $this->config->get('systemUserAttributes'); $user = $repository->getNew(); $user->set('id', ApplicationUser::SYSTEM_USER_ID); $user->set('userName', ApplicationUser::SYSTEM_USER_NAME); $user->set('type', User::TYPE_SYSTEM); $user->set($attributes); $repository->save($user); } }