<commit_before><?php
namespace UserBundle\Command;

use Doctrine\ORM\EntityManager;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use UserBundle\Entity\User;
use UserBundle\Repository\UserRepository;


class UserBulkPasswordMailerCommand extends ContainerAwareCommand
{

    /* @var EntityManager */
    private $em;

    /* @var $encoder EncoderFactory */
    private $encoder;

    /* @var $usersRepository UserRepository */
    private $usersRepository;

    private $mailer;

    /* @var $templating TwigEngine */
    private $templating;

    protected function configure()
    {

        $this
            ->setName('user:password:mail')
            ->setDescription('This regenerates all user passwords and mails them');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    protected function initialize(InputInterface $input, OutputInterface $output)
    {

        /* Get all of the services */
        $this->em = $this->getContainer()->get('doctrine')->getManager();
        $this->encoder = $this->getContainer()->get('security.encoder_factory');
        $this->mailer = $this->getContainer()->get('mailer');
        $this->templating = $this->getContainer()->get('templating');

        /* Get all of the repositories */
        $this->usersRepository = $this->em->getRepository('UserBundle:User');
    }

    /**
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int|null|void
     * @throws \Exception
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {

        try {

            $csvUsers = [
                [ "first_name" => "Michael","last_name" => "Magumise","email_address" => "<EMAIL>"],
                [ "first_name" => "Lear","last_name" => "Pather","email_address" => "<EMAIL>"],
                [ "first_name" => "Walter","last_name" => "<NAME>","email_address" => "<EMAIL>"],
                [ "first_name" => "Ryan","last_name" => "Lumsden","email_address" => "<EMAIL>"],
                [ "first_name" => "Jonathan","last_name" => "Potgieter","email_address" => "<EMAIL>"],
                [ "first_name" => "Jailosi","last_name" => "Phiri","email_address" => "<EMAIL>"],
                [ "first_name" => "James","last_name" => "Mohono","email_address" => "<EMAIL>"],
                [ "first_name" => "Fortune","last_name" => "Maseko","email_address" => "<EMAIL>"],
                [ "first_name" => "Mawande","last_name" => "Nxumalo","email_address" => "<EMAIL>"],
                [ "first_name" => "Nkululeko","last_name" => "Dube","email_address" => "<EMAIL>"],
                [ "first_name" => "Kendall","last_name" => "Jordaan","email_address" => "<EMAIL>"],
                [ "first_name" => "Sanushen","last_name" => "Govender","email_address" => "<EMAIL>"],
                [ "first_name" => "Dowayne","last_name" => "Breedt","email_address" => "<EMAIL>"],
                [ "first_name" => "Kudzaishe","last_name" => "Chitonga","email_address" => "<EMAIL>c<EMAIL>"],
                [ "first_name" => "Thabo","last_name" => "Nkgweng","email_address" => "<EMAIL>"],
                [ "first_name" => "Thandaninkosi","last_name" => "Moyo","email_address" => "<EMAIL>"],
                [ "first_name" => "Sizwe","last_name" => "Mkhonto","email_address" => "<EMAIL>"],
                [ "first_name" => "Matthew","last_name" => "Ketley","email_address" => "<EMAIL>"],
                [ "first_name" => "Sabelo","last_name" => "Mbokazi","email_address" => "<EMAIL>"],
                [ "first_name" => "Koketso","last_name" => "Polorie","email_address" => "<EMAIL>"],
                [ "first_name" => "Larry","last_name" => "Nxumalo","email_address" => "<EMAIL>"],
                [ "first_name" => "Asaph","last_name" => "Mulaisi","email_address" => "<EMAIL>"],
                [ "first_name" => "Edward","last_name" => "Stroebel","email_address" => "<EMAIL>"],
                [ "first_name" => "Ruan","last_name" => "Prinsloo","email_address" => "<EMAIL>"]
            ];

            foreach($csvUsers as $csvUser) {

                $user = $this->usersRepository->findOneBy(['email' => $csvUser['email_address']]);

                if(!$user instanceof User) {

                    $username = str_replace('.', '', explode('@', $csvUser['email_address'])[0]);

                    $user = new User();
                    $user->setFirstName($csvUser['first_name']);
                    $user->setLastName($csvUser['last_name']);
                    $user->setEmail($csvUser['email_address']);
                    $user->setUsername($username);
                    $user->setIsActive(true);

                }

                $newPassword = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<PASSWORD>56789') , 0 , 10);

                $user->setPassword($this->encodePassword($user, $newPassword));

                $message = \Swift_Message::newInstance()
                    ->setSubject('Afrihost Code Camp :: Password Reminder')
                    ->setFrom('<EMAIL>')
                    ->setTo($csvUser['email_address'])
                    ->setBody(
                        $this->templating->render(
                            'UserBundle:mails:forgot_password.html.twig',
                            [
                                'first_name' => $user->getFirstName(),
                                'username' => $user->getUsername(),
                                'password' => <PASSWORD>
                            ]
                        ), 'text/html' );

                $this->em->persist($user);
                $this->mailer->send($message);
<commit_msg>Updated bulk mailing script list<commit_after><?php
namespace UserBundle\Command;

use Doctrine\ORM\EntityManager;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use UserBundle\Entity\User;
use UserBundle\Repository\UserRepository;


class UserBulkPasswordMailerCommand extends ContainerAwareCommand
{

    /* @var EntityManager */
    private $em;

    /* @var $encoder EncoderFactory */
    private $encoder;

    /* @var $usersRepository UserRepository */
    private $usersRepository;

    private $mailer;

    /* @var $templating TwigEngine */
    private $templating;

    protected function configure()
    {

        $this
            ->setName('user:password:mail')
            ->setDescription('This regenerates all user passwords and mails them');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    protected function initialize(InputInterface $input, OutputInterface $output)
    {

        /* Get all of the services */
        $this->em = $this->getContainer()->get('doctrine')->getManager();
        $this->encoder = $this->getContainer()->get('security.encoder_factory');
        $this->mailer = $this->getContainer()->get('mailer');
        $this->templating = $this->getContainer()->get('templating');

        /* Get all of the repositories */
        $this->usersRepository = $this->em->getRepository('UserBundle:User');
    }

    /**
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int|null|void
     * @throws \Exception
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {

        try {

            $csvUsers = [
                [ "first_name" => "Sarel", "last_name" => "<NAME>","email_address" => "<EMAIL>"],
                [ "first_name" => "Sacheen", "last_name" => "Dhanjie","email_address" => "<EMAIL>"],
                [ "first_name" => "Gavin", "last_name" => "McLeland","email_address" => "<EMAIL>"],
                [ "first_name" => "Lee", "last_name" => "Pelser","email_address" => "<EMAIL>"],
                [ "first_name" => "John", "last_name" => "Kosmetos","email_address" => "<EMAIL>"],
                [ "first_name" => "Johnathan", "last_name" => "Dell","email_address" => "<EMAIL>"],
                [ "first_name" => "Dale", "last_name" => "Attree","email_address" => "<EMAIL>"],
                [ "first_name" => "Brad", "last_name" => "Mostert","email_address" => "<EMAIL>"],
                [ "first_name" => "Michael","last_name" => "Magumise","email_address" => "<EMAIL>"],
                [ "first_name" => "Lear","last_name" => "Pather","email_address" => "<EMAIL>"],
                [ "first_name" => "Walter","last_name" => "<NAME>","email_address" => "<EMAIL>"],
                [ "first_name" => "Ryan","last_name" => "Lumsden","email_address" => "<EMAIL>"],
                [ "first_name" => "Jonathan","last_name" => "Potgieter","email_address" => "<EMAIL>"],
                [ "first_name" => "Jailosi","last_name" => "Phiri","email_address" => "<EMAIL>"],
                [ "first_name" => "James","last_name" => "Mohono","email_address" => "<EMAIL>"],
                [ "first_name" => "Fortune","last_name" => "Maseko","email_address" => "<EMAIL>"],
                [ "first_name" => "Mawande","last_name" => "Nxumalo","email_address" => "<EMAIL>"],
                [ "first_name" => "Nkululeko","last_name" => "Dube","email_address" => "<EMAIL>"],
                [ "first_name" => "Kendall","last_name" => "Jordaan","email_address" => "<EMAIL>"],
                [ "first_name" => "Sanushen","last_name" => "Govender","email_address" => "<EMAIL>"],
                [ "first_name" => "Dowayne","last_name" => "Breedt","email_address" => "<EMAIL>"],
                [ "first_name" => "Kudzaishe","last_name" => "Chitonga","email_address" => "<EMAIL>"],
                [ "first_name" => "Thabo","last_name" => "Nkgweng","email_address" => "<EMAIL>"],
                [ "first_name" => "Thandaninkosi","last_name" => "Moyo","email_address" => "<EMAIL>"],
                [ "first_name" => "Sizwe","last_name" => "Mkhonto","email_address" => "<EMAIL>"],
                [ "first_name" => "Matthew","last_name" => "Ketley","email_address" => "<EMAIL>"],
                [ "first_name" => "Sabelo","last_name" => "Mbokazi","email_address" => "<EMAIL>"],
                [ "first_name" => "Koketso","last_name" => "Polorie","email_address" => "<EMAIL>"],
                [ "first_name" => "Larry","last_name" => "Nxumalo","email_address" => "<EMAIL>"],
                [ "first_name" => "Asaph","last_name" => "Mulaisi","email_address" => "<EMAIL>"],
                [ "first_name" => "Edward","last_name" => "Stroebel","email_address" => "<EMAIL>"],
                [ "first_name" => "Ruan","last_name" => "Prinsloo","email_address" => "<EMAIL>"]
            ];

            foreach($csvUsers as $csvUser) {

                $user = $this->usersRepository->findOneBy(['email' => $csvUser['email_address']]);

                if(!$user instanceof User) {

                    $username = <EMAIL>_replace('.', '', explode('@', $csvUser['email_address'])[0]);

                    $user = new User();
                    $user->setFirstName($csvUser['first_name']);
                    $user->setLastName($csvUser['last_name']);
                    $user->setEmail($csvUser['email_address']);
                    $user->setUsername($username);
                    $user->setIsActive(true);

                }

                $newPassword = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV<PASSWORD>') , 0 , 10);

                $user->setPassword($this->encodePassword($user, $newPassword));

                $message = \Swift_Message::newInstance()
                    ->setSubject('Afrihost Code Camp :: Password Reminder')
                    ->setFrom('<EMAIL>')
                    ->setReplyTo('<EMAIL>')
                    ->setSender('<EMAIL>')
                    ->setTo($csvUser['email_address'])
                    ->setBody(
                        $this->templating->render(
                            'UserBundle:mails:forgot_password.html.twig',
                            [
                                'first_name' => $user->getFirstName(),
                                'username' => $user->getUsername(),
                                'password' => <PASSWORD>
                            ]
                        ), 'text/html' );
                
                $this->em->persist($user);
                $this->mailer->send($message);

{'fraction_non_alphanumeric': 0.18346804941284123, 'fraction_numerical': 0.0009913070001525087, 'mean_word_length': 2.470494839904737, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 328, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6076866', 'n_tokens_mistral': 4035, 'n_tokens_neox': 3816, 'n_words': 568}