N98\Magento\Command\Customer\CreateDummyCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer | void
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return integer | void
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->detectMagento($output, true);
        if (!$this->initMagento()) {
            return;
        }
        $res = $this->getCustomerModel()->getResource();
        $faker = \Faker\Factory::create($input->getArgument('locale'));
        $faker->addProvider(new \N98\Util\Faker\Provider\Internet($faker));
        $website = $this->getHelper('parameter')->askWebsite($input, $output);
        $res->beginTransaction();
        $count = $input->getArgument('count');
        $outputPlain = $input->getOption('format') === null;
        $table = array();
        for ($i = 0; $i < $count; $i++) {
            $customer = $this->getCustomerModel();
            $email = $faker->safeEmail;
            $customer->setWebsiteId($website->getId());
            $customer->loadByEmail($email);
            $password = $customer->generatePassword();
            if (!$customer->getId()) {
                $customer->setWebsiteId($website->getId());
                $customer->setEmail($email);
                $customer->setFirstname($faker->firstName);
                $customer->setLastname($faker->lastName);
                $customer->setPassword($password);
                if ($input->hasOption('with-addresses')) {
                    $address = $this->createAddress($faker);
                    $customer->addAddress($address);
                }
                $customer->save();
                $customer->setConfirmation(null);
                $customer->save();
                if ($outputPlain) {
                    $output->writeln('<info>Customer <comment>' . $email . '</comment> with password <comment>' . $password . '</comment> successfully created</info>');
                } else {
                    $table[] = array($email, $password, $customer->getFirstname(), $customer->getLastname());
                }
            } else {
                if ($outputPlain) {
                    $output->writeln('<error>Customer ' . $email . ' already exists</error>');
                }
            }
            if ($i % 1000 == 0) {
                $res->commit();
                $res->beginTransaction();
            }
        }
        $res->commit();
        if (!$outputPlain) {
            $this->getHelper('table')->setHeaders(array('email', 'password', 'firstname', 'lastname'))->renderByFormat($output, $table, $input->getOption('format'));
        }
    }