addArgument('mobile', InputArgument::OPTIONAL, 'System-owner mobile identifier', '0000000000') ->addOption('password', 'p', InputOption::VALUE_REQUIRED, 'Set/replace the login password') ->addOption('activate', null, InputOption::VALUE_NONE, 'Activate the account (status=1)') ->addOption('deactivate', null, InputOption::VALUE_NONE, 'Deactivate the account (status=0)'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $mobile = (string) $input->getArgument('mobile'); $password = $input->getOption('password'); $activate = (bool) $input->getOption('activate'); $deactiv = (bool) $input->getOption('deactivate'); if ($activate && $deactiv) { $io->error('--activate و --deactivate با هم مجاز نیستند.'); return Command::INVALID; } $repo = $this->em->getRepository(User::class); $user = $repo->findOneBy(['mobileNumber' => $mobile]); $existed = $user !== null; if (!$existed) { $user = new User($mobile); $user->setRealName('مالک سیستمی (کرالر نظام پزشکی)'); if ($password === null) { $io->error('برای ساخت کاربر جدید، --password الزامی است.'); return Command::INVALID; } } $roles = $user->getRoles(); if (!in_array('ROLE_ADMIN', $roles, true)) { $roles[] = 'ROLE_ADMIN'; $user->setRoles(array_values(array_unique($roles))); } if ($password !== null) { $user->setPasswordHash($this->hasher->hashPassword($user, (string) $password)); } // پیش‌فرضِ کاربرِ تازه: فعال، مگر آنکه --deactivate داده شده باشد. if ($activate) { $user->setStatus(1); } elseif ($deactiv) { $user->setStatus(0); } elseif (!$existed) { $user->setStatus(1); } $this->em->persist($user); $this->em->flush(); $io->success(sprintf( '%s system-owner %s (uuid=%s, status=%d, roles=%s)', $existed ? 'Updated' : 'Created', $mobile, $user->getUuid(), $user->getStatus(), implode(',', $user->getRoles()), )); return Command::SUCCESS; } }