예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $creationDate = new \DateTime();
     $creationDate->setTimezone(self::timezoneUTC());
     $arrays_of_user_data = array(array('qa_user', 'password', 'Quality', 'Assurance User', '*****@*****.**', 'ROLE_ADMINISTRATOR', '8f45fa58-4664-b11b-82ee-7a737df7afb7'), array('admin', 'admin123', 'Admin', 'Admin123', '*****@*****.**', 'ROLE_ADMINISTRATOR', '12345678-4664-b11b-82ee-7a737df7afb7'));
     $count = 0;
     foreach ($arrays_of_user_data as $array_of_user_data) {
         //Generate an aPI KEY//
         $count += 1;
         $rolename = $array_of_user_data[5];
         $role = $manager->getRepository('UserBundle:Role')->findOneByName($rolename);
         // $api_key = Uuid::uuid4()->toString();
         $originalUser = new User();
         $originalUser->setCreatedAt($creationDate);
         $originalUser->setUpdatedAt($creationDate);
         $originalUser->setEnabled(1);
         $originalUser->setLocked(0);
         $originalUser->setExpired(0);
         $originalUser->setCredentialsExpired(0);
         $originalUser->setOffice('New York');
         $originalUser->setTitle('noTitleInformationyet');
         $originalUser->setConfirmationToken('GeneratedOriginalUser');
         $originalUser->addRole($role->getName());
         $originalUser->setUsername($array_of_user_data[0]);
         $originalUser->setEmail($array_of_user_data[4]);
         $originalUser->setUsernameCanonical($array_of_user_data[0]);
         $originalUser->setEmailCanonical($array_of_user_data[4]);
         $originalUser->setPassword(md5($array_of_user_data[1]));
         $originalUser->setApiKey($array_of_user_data[6]);
         $originalUser->setFirstname($array_of_user_data[2]);
         $originalUser->setLastname($array_of_user_data[3]);
         $originalUser->setPhone('2126057000');
         $manager->persist($originalUser);
         //    THIS MUST BE DISABLED.
         //            //ADD USERACCESS TO TEMP CLIENT FOR EACH OF THIS USERS
         //
         //            $temp_client = $manager->getRepository('CampaignBundle:Client')->findOneByName('temp_client');
         //            $global_region = $manager->getRepository('CampaignBundle:Region')->find(1);
         //            $temp_useraccess = new Useraccess();
         //            $temp_useraccess->setUser($originalUser);
         //            $temp_useraccess->setClient($temp_client);
         //            $temp_useraccess->setRegion($global_region);
         //            $temp_useraccess->setAllCountries(true);
         //            $manager->persist($temp_useraccess);
         //END ADD USERACCESS
     }
     echo 'Loaded ' . $count . ' Original Users Successfully.';
     $manager->flush();
     //Set all the default users to have the "created by" set as John Gladysz's Username.
     //        $john = $manager->getRepository('UserBundle:User')->findOneByUsername('jgladysz');
     //        if ($john) {
     //            foreach ($arrays_of_user_data as $userdata) {
     //
     //                $user = $manager->getRepository('UserBundle:User')->findOneByUsername($userdata[0]);
     //                if ($user) {
     //                    $user->setCreatedBy($john);
     //                    $manager->persist($user);
     //                    $manager->flush();
     //                }
     //            }
     //        }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = $this->getContainer()->get('doctrine')->getManager();
     $creationDate = new \DateTime();
     $creationDate->setTimezone(new \DateTimeZone('UTC'));
     /*         * **********************************************************************************************************************************************
      * ******************************************************************************************************************************************************** 
      * 
      *          THE TEST DATA INSERTION PART STARTS HERE  ||||       THE TEST DATA INSERTION PART STARTS HERE 
      *          FIRST WE CHECK / MAKE SURE THE TEST USER IS ADDED IN THE DATABASE.
      * 
      * ******************************************************************************************************************************************************** 
      * ******************************************************************************************************************************************************** 
      */
     if ($input->getOption('add')) {
         $number = $input->getArgument('number');
         //CHECK THE EXISTENCE OF THE TEST USER.
         //IF EXISTS , USE HIM
         //IF NOT EXIST , CREATE AND USE HIM.
         $user = $manager->getRepository('UserBundle:User')->findOneByUsername('test_user_1_test');
         if ($user) {
             $output->writeln('Using existing test user from database. ( ApiKey = testuser1 )');
         } else {
             $user = new User();
             $user->setUsername('test_user_1_test');
             $user->setApiKey('testuser1');
             $user->setEmail('*****@*****.**');
             $user->setPassword(md5('password'));
             $user->setEnabled(true);
             $user->setCreatedAt($creationDate);
             $user->setUpdatedAt($creationDate);
             $user->addRole('ROLE_VIEWER');
             $manager->persist($user);
             $manager->flush();
             $output->writeln(' ');
             $output->writeln('Testuser was missing so it has been added. (ApiKey =  testuser1 )');
         }
         // WE MUST CHECK THAT THE USER ALREADY HAS ACCESS TO THIS REGION || COUNTRY COMBINATIONS
         $accessclient = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
         $access1_country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA');
         $access1_region = $access1_country->getRegion();
         $access2_region = $manager->getRepository('CampaignBundle:Region')->find(2);
         $already_has_access_to_Unilever_USA = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $accessclient, 'country' => $access1_country, 'all_countries' => false]);
         $already_has_access_to_Unilever_ASIA_PACIFIC_REGION = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $accessclient, 'region' => $access2_region, 'all_countries' => true]);
         //If not already exist , add the access
         //If not already exist , add the access
         if ($already_has_access_to_Unilever_USA) {
             $output->writeln('Test user already has access to Unilever country USA , proceeding further.');
         } else {
             $access1 = new Useraccess();
             $access1->setUser($user);
             $access1->setClient($accessclient);
             $access1->setRegion($access1_region);
             $access1->setCountry($access1_country);
             $access1->setAllCountries(FALSE);
             $manager->persist($access1);
             $output->writeln('Test user has been granted access  to client Unilever country USA, proceeding.');
         }
         if ($already_has_access_to_Unilever_ASIA_PACIFIC_REGION) {
             $output->writeln('Test user already has access to Unilever region ASIA PACIFIC , proceeding further.');
         } else {
             $access2 = new Useraccess();
             $access2->setUser($user);
             $access2->setClient($accessclient);
             $access2->setRegion($access2_region);
             $access2->setAllCountries(TRUE);
             $manager->persist($access2);
             $output->writeln('Test user has been granted access  to client Unilever region ASIA PACIFIC, proceeding.');
         }
         $manager->flush();
         $output->writeln(' ');
         //End adding of the access
         //End adding of the access
         $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
         switch ($number) {
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE FIRST CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = USA , STATUS = BUILD.
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 1:
                 //FIND THE CAMPAIGN , IF UNABLE TO FIND IT , CREATE IT !
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(1);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case1.Client=Unilever.Country=USA.Status=Build');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case1.Client=Unilever.Country=USA.Status=Build');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 /// END ADD TASKS FOR THIS CAMPAIGN
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(true);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln('The test user has been added as a normal teammember for this campaign. He is NOT reviewer.');
                     $output->writeln(' ');
                 }
                 //IF NOT , ADD HIM TO THIS CAMPAIGN ONLY AS A TEAMMEMBER
                 $output->writeln('This case should work as intended. All data is availlable.');
                 $output->writeln(' ');
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE SECOND CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = USA , STATUS = APPROVED.
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE SECOND CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = USA , STATUS = APPROVED.
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 2:
                 //CAMPAIGN2 IS where test user is taskowner for at least 2 tasks
                 //and the campaign_status is approved. Clien is still Unilever and Country = USA
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(2);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case2.Client=Unilever.Country=USA.Status=Approved');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case2.Client=Unilever.Country=USA.Status=Approved');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 //Randomly assign the user as a taskowner for at leat two tasks.
                 $random_ids = array();
                 $random_number_of_tasks = 6;
                 for ($i = 2; $i < $random_number_of_tasks; $i++) {
                     $random_ids[] = rand(1, 9);
                 }
                 $unique_random_ids = array_unique($random_ids);
                 $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId());
                 foreach ($all_tasks_of_this_campaign as $task) {
                     $task->setOwner(NULL);
                     if (in_array($task->getTaskname()->getId(), $unique_random_ids)) {
                         ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER.
                         $task->setOwner($user);
                         $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName());
                     }
                     $manager->persist($task);
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE THIRD CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED.
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE THIRD CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED.
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 3:
                 //CAMPAIGN3 IS where test user is taskowner for at least 1 tasks
                 //and the campaign_status is COMPLETE . Clien is still Unilever and Country = CHINA
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(3);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 3] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case3.Client=Unilever.Country=China.Status=Completed');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //   $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case3.Client=Unilever.Country=China.Status=Completed');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 //Randomly assign the user as a taskowner for at leat two tasks.
                 $random_ids = array();
                 $random_number_of_tasks = 6;
                 for ($i = 2; $i < $random_number_of_tasks; $i++) {
                     $random_ids[] = rand(1, 9);
                 }
                 $unique_random_ids = array_unique($random_ids);
                 $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId());
                 foreach ($all_tasks_of_this_campaign as $task) {
                     $task->setOwner(NULL);
                     if (in_array($task->getTaskname()->getId(), $unique_random_ids)) {
                         ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER.
                         $task->setOwner($user);
                         $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName());
                     }
                     $manager->persist($task);
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  *  
                  *          THE FOURTH CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = CANCELLED.
                  *          The test user is a taskowner for at least 1 task
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              *  
              *          THE FOURTH CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = CANCELLED.
              *          The test user is a taskowner for at least 1 task
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 4:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 4] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case4.Client=Unilever.Country=China.Status=Cancelled');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //   $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     for ($i = 1; $i < 50; $i++) {
                         print_r($campaign_creator->getUsername());
                     }
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case4.Client=Unilever.Country=China.Status=Cancelled');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 //Randomly assign the user as a taskowner for at leat two tasks.
                 $random_ids = array();
                 $random_number_of_tasks = 6;
                 for ($i = 2; $i < $random_number_of_tasks; $i++) {
                     $random_ids[] = rand(1, 9);
                 }
                 $unique_random_ids = array_unique($random_ids);
                 $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId());
                 foreach ($all_tasks_of_this_campaign as $task) {
                     $task->setOwner(NULL);
                     if (in_array($task->getTaskname()->getId(), $unique_random_ids)) {
                         ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER.
                         $task->setOwner($user);
                         $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName());
                     }
                     $manager->persist($task);
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE FIFTH CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = BUILD.
                  *          THE TEST USER IS IN THE CAMPAIGN'S TEAM , BUT HE IS NOT REVIEWER , AND NOT OWNER OF ANY TASK.
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE FIFTH CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = BUILD.
              *          THE TEST USER IS IN THE CAMPAIGN'S TEAM , BUT HE IS NOT REVIEWER , AND NOT OWNER OF ANY TASK.
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 5:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(1);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case5.Client=Unilever.Country=China.Status=Build']);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 5] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case5.Client=Unilever.Country=China.Status=Build');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //  $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case5.Client=Unilever.Country=China.Status=Build');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 $output->writeln('In this campaign , the user is NOT reviewer , and does not own any task.');
                 $output->writeln(' ');
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE SIXTH CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED.
                  *          TEST USER IS NOT REVIEWER NOT TASK OWNER 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE SIXTH CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED.
              *          TEST USER IS NOT REVIEWER NOT TASK OWNER 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 6:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case6.Client=Unilever.Country=China.Status=Cancelled']);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 6] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case6.Client=Unilever.Country=China.Status=Cancelled');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //      $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case6.Client=Unilever.Country=China.Status=Cancelled');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE SEVENTH CAMPAIGN CASE
                  *          CLIENT = testclientforcase7 , COUNTRY = CHINA , STATUS = CANCELLED.
                  * 
                  *          This test data should be just like case 6 , the difference is only the CLIENT ID. using client with name "testclientforcase7"
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE SEVENTH CAMPAIGN CASE
              *          CLIENT = testclientforcase7 , COUNTRY = CHINA , STATUS = CANCELLED.
              * 
              *          This test data should be just like case 6 , the difference is only the CLIENT ID. using client with name "testclientforcase7"
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 7:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('testclientforcase7');
                 if ($client) {
                     $output->writeln('Found testclientforcase7 in the database. Proceeding..');
                 } else {
                     $client = new Client();
                     $client->setName('testclientforcase7');
                     $client->setDbid(0);
                     $client->setCreatedAt($creationDate);
                     $client->setUpdatedAt($creationDate);
                     $manager->persist($client);
                     $output->writeln('A new client , testclientforcase7 has been addeed. Proceeding...');
                     $manager->flush();
                 }
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['name' => 'Case7.Client=testclientforcase7.Country=China.Status=Cancelled']);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 7] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case7.Client=testclientforcase7.Country=China.Status=Cancelled');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //       $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case7.Client=testclientforcase7.Country=China.Status=Cancelled');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE EIGHTH CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = CANCELLED.
                  * 
                  *          This test data should be just like case 6 , the difference is only the COUNTRY.
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE EIGHTH CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = CANCELLED.
              * 
              *          This test data should be just like case 6 , the difference is only the COUNTRY.
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 8:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('Portugal');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case8.Client=Unilever.Country=Portugal.Status=Cancelled']);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 8] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case8.Client=Unilever.Country=Portugal.Status=Cancelled');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case8.Client=Unilever.Country=Portugal.Status=Cancelled');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE NINETH CAMPAIGN CASE
                  *          CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = COMPLETED.
                  * 
                  *          This test data should be just like case 3 , the difference is only COUNTRY
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
             /*                 * **************************************************************************************************************************************
              * ******************************************************************************************************************************************************** 
              * 
              *          THE NINETH CAMPAIGN CASE
              *          CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = COMPLETED.
              * 
              *          This test data should be just like case 3 , the difference is only COUNTRY
              * 
              * ******************************************************************************************************************************************************** 
              * ******************************************************************************************************************************************************** 
              */
             case 9:
                 $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('Portugal');
                 $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever');
                 $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(3);
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]);
                 if ($campaign) {
                     $existing_campaign_name = $campaign->getName();
                     $existing_campaign_id = $campaign->getId();
                     $output->writeln('A campaign for this specs already exists. [case 9] ');
                     $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id);
                     $output->writeln('It is not the case to add another duplicate of this.');
                 } else {
                     $campaign = new Campaign();
                     $campaign_key = Uuid::uuid4()->toString();
                     $campaign->setId($campaign_key);
                     $campaign->setName('Case9.Client=Unilever.Country=Portugal.Status=Completed');
                     $campaign->setCampaignstatus($status);
                     $campaign->setCountry($country);
                     $product = $manager->getRepository('CampaignBundle:Product')->find(25);
                     $campaign->setProduct($product);
                     $productline = $product->getProductline();
                     $campaign->setProductline($productline);
                     $brand = $productline->getBrand();
                     $campaign->setBrand($brand);
                     $division = $brand->getDivision();
                     $campaign->setDivision($division);
                     $client = $division->getClient();
                     $campaign->setClient($client);
                     $campaign->setCampaignidea('ninecampaignstest');
                     //        $campaign_creator = $manager->getRepository('UserBundle:User')->find(5);
                     $campaign->setUser($campaign_creator);
                     $campaign->setClientPresentation(true);
                     $campaign->setNotVisible(false);
                     $campaign->setCompleteness(0);
                     $campaign->setCreatedAt($creationDate);
                     $campaign->setUpdatedAt($creationDate);
                     $data = new \DateTime();
                     $timestamp = $data->getTimestamp();
                     $completion_min_days = 1;
                     $completion_max_days = 15;
                     $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400);
                     $random_completion_timestamp = $timestamp + $random_completion_time;
                     $rand_completion_timestamp_object = new \DateTime();
                     $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp);
                     $deliverable_min_days = 15;
                     $deliverable_max_days = 30;
                     $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400);
                     $random_deliverable_timestamp = $timestamp + $random_deliverable_time;
                     $random_deliverable_timestamp_object = new \DateTime();
                     $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp);
                     $campaign->setClientDeliverabledate($random_deliverable_timestamp_object);
                     $campaign->setCompletionDate($rand_completion_timestamp_object);
                     $manager->persist($campaign);
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($campaign_creator);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Created a Campaign with following combination Case9.Client=Unilever.Country=Portugal.Status=Completed');
                     //ADD THE TASKS FOR THIS CAMPAIGN
                     //Fetch all the task types
                     $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll();
                     //Fetch the default task status
                     $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1);
                     //For each task type , add to this campaign
                     foreach ($task_types as $tasktype) {
                         $new_task = new Task();
                         $new_task->setCampaign($campaign);
                         $new_task->setTaskname($tasktype);
                         $new_task->setOwner($campaign_creator);
                         $new_task->setTaskmessage(NULL);
                         $new_task->setMatrixfileversion(0);
                         $new_task->setTaskstatus($default_task_status);
                         $new_task->setPhase($tasktype->getPhaseid());
                         $new_task->setCreatedAt($creationDate);
                         $new_task->setCreatedby($campaign_creator);
                         $new_task->setUpdatedAt($creationDate);
                         $manager->persist($new_task);
                     }
                     $output->writeln(' ');
                     $output->writeln('Created the tasks for the campaign ' . $campaign->getName());
                     $output->writeln(' ');
                 }
                 //VERIFY USER IS IN THIS CAMPAIGN'S TEAM
                 $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]);
                 if ($is_teammember) {
                     $output->writeln('The user is already set as a teammember for this campaign.');
                 } else {
                     $teammember = new Teammember();
                     $teammember->setCampaign($campaign);
                     $teammember->setMember($user);
                     $teammember->setIsReviewer(false);
                     $manager->persist($teammember);
                     $output->writeln('The test user has been added as a normal teammember for this campaign.');
                     $output->writeln(' ');
                 }
                 $manager->flush();
                 //Randomly assign the user as a taskowner for at leat two tasks.
                 $random_ids = array();
                 $random_number_of_tasks = 6;
                 for ($i = 2; $i < $random_number_of_tasks; $i++) {
                     $random_ids[] = rand(1, 9);
                 }
                 $unique_random_ids = array_unique($random_ids);
                 $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId());
                 foreach ($all_tasks_of_this_campaign as $task) {
                     $task->setOwner(NULL);
                     if (in_array($task->getTaskname()->getId(), $unique_random_ids)) {
                         ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER.
                         $task->setOwner($user);
                         $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName());
                     }
                     $manager->persist($task);
                 }
                 $manager->flush();
                 break;
                 /*                 * **************************************************************************************************************************************
                  * ******************************************************************************************************************************************************** 
                  * 
                  *          THE TEST DATA REMOVAL PART STARTS HERE  ||||       THE TEST DATA REMOVAL PART STARTS HERE 
                  * 
                  * ******************************************************************************************************************************************************** 
                  * ******************************************************************************************************************************************************** 
                  */
         }
     } elseif ($input->getOption('removecampaign')) {
         $number = $input->getArgument('number');
         switch ($number) {
             case 1:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case1.Client=Unilever.Country=USA.Status=Build');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case1.Client=Unilever.Country=USA.Status=Build. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case1.Client=Unilever.Country=USA.Status=Build');
                     $output->writeln(' ');
                 }
                 break;
             case 2:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case2.Client=Unilever.Country=USA.Status=Approved');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case2.Client=Unilever.Country=USA.Status=Approved. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case2.Client=Unilever.Country=USA.Status=Approved');
                     $output->writeln(' ');
                 }
                 break;
             case 3:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case3.Client=Unilever.Country=China.Status=Completed');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case3.Client=Unilever.Country=China.Status=Completed. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case3.Client=Unilever.Country=China.Status=Completed');
                     $output->writeln(' ');
                 }
                 break;
             case 4:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case4.Client=Unilever.Country=China.Status=Cancelled');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case4.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case4.Client=Unilever.Country=China.Status=Cancelled');
                     $output->writeln(' ');
                 }
                 break;
             case 5:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case5.Client=Unilever.Country=China.Status=Build');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case5.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case5.Client=Unilever.Country=China.Status=Cancelled');
                     $output->writeln(' ');
                 }
                 break;
             case 6:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case6.Client=Unilever.Country=China.Status=Cancelled');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case6.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case6.Client=Unilever.Country=China.Status=Cancelled');
                     $output->writeln(' ');
                 }
                 break;
             case 7:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case7.Client=testclientforcase7.Country=China.Status=Cancelled');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('testclientforcase7');
                     $manager->remove($client);
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case7.Client=testclientforcase7.Country=China.Status=Cancelled. And the teammembers of this campaign.');
                     $output->writeln('Also removed the testclientforcase7 client. ');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case7.Client=testclientforcase7.Country=China.Status=Cancelled');
                     $output->writeln(' ');
                 }
                 break;
             case 8:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case8.Client=Unilever.Country=Portugal.Status=Cancelled');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case8.Client=Unilever.Country=Portugal.Status=Cancelled. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case8.Client=Unilever.Country=Portugal.Status=Cancelled');
                     $output->writeln(' ');
                 }
                 break;
             case 9:
                 $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case9.Client=Unilever.Country=Portugal.Status=Completed');
                 //WHEN WE REMOVE CASE 1 ,
                 if ($campaign) {
                     //1. We must remove any teammember relationship related to the specified campaign before removing the campaign.
                     $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign);
                     foreach ($teammembers as $teammember) {
                         $manager->remove($teammember);
                     }
                     $manager->remove($campaign);
                     $manager->flush();
                     $output->writeln(' ');
                     $output->writeln('Removed campaign Case9.Client=Unilever.Country=Portugal.Status=Completed. And the teammembers of this campaign.');
                     $output->writeln(' ');
                 } else {
                     $output->writeln(' ');
                     $output->writeln('There was no campaign Case9.Client=Unilever.Country=Portugal.Status=Completed');
                     $output->writeln(' ');
                 }
                 break;
         }
     } else {
     }
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = $this->getContainer()->get('doctrine')->getManager();
     $creationDate = new \DateTime();
     $creationDate->setTimezone(new \DateTimeZone('UTC'));
     if ($input->getOption('add')) {
         $existing_users = $manager->getRepository('UserBundle:User')->findByConfirmationToken('deletable');
         if (count($existing_users) > 0) {
             $output->writeln('Found test users in database. Will delete ' . count($existing_users) . ' test users from database.');
             sleep(1);
             foreach ($existing_users as $user) {
                 if ($user->hasRole('ROLE_ADMINISTRATOR')) {
                     $client = $manager->getRepository('CampaignBundle:Client')->find(1);
                     $region = $manager->getRepository('CampaignBundle:Region')->find(1);
                     $useraccess = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $client, 'region' => $region]);
                     if ($useraccess) {
                         $manager->remove($useraccess);
                     }
                 }
                 $manager->remove($user);
                 $temp_client = $manager->getRepository('CampaignBundle:Client')->find(2);
                 $temp_useraccess = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $temp_client]);
                 $manager->remove($temp_useraccess);
             }
             $manager->flush();
             sleep(1);
             $output->writeln('Succesfully deleted ' . count($existing_users) . ' test users from database.');
         }
         $number = $input->getArgument('number');
         for ($i = 1; $i <= $number; $i++) {
             $user = new User();
             $role = 'ROLE_VIEWER';
             if ($i % 4 == 0) {
                 $role = 'ROLE_CONTRIBUTOR';
             }
             if ($i % 20 == 0) {
                 $role = 'ROLE_ADMINISTRATOR';
             }
             $user->setCreatedAt($creationDate);
             $user->setUpdatedAt($creationDate);
             $user->setUsername('testuser' . $i);
             $user->setEmail('testuser' . $i . '*****@*****.**');
             $user->setUsernameCanonical('testuser' . $i);
             $user->setEmailCanonical('testuser' . $i . '*****@*****.**');
             $user->setEnabled(1);
             $user->setPassword(md5('password' . $i));
             $user->setLocked(0);
             $user->addRole($role);
             $user->setExpired(0);
             $user->setConfirmationToken('deletable');
             $user->setCredentialsExpired(0);
             $user->setApiKey($i);
             $user->setFirstname('testuser' . $i . '_FN');
             $user->setLastname('testuser' . $i . '_LN');
             $user->setPhone('01234567890');
             $user->setOffice('testuser' . $i);
             $user->setTitle('testuser' . $i);
             $manager->persist($user);
             if ($i % 20 == 0) {
                 $all_clients = $manager->getRepository('CampaignBundle:Client')->find(1);
                 $global_region = $manager->getRepository('CampaignBundle:Region')->find(1);
                 $useraccess = new Useraccess();
                 $useraccess->setUser($user);
                 $useraccess->setClient($all_clients);
                 $useraccess->setRegion($global_region);
                 $useraccess->setAllCountries(true);
                 $manager->persist($useraccess);
             }
             //ADD USERACCESS TO TEMP CLIENT REGARDLESS OF THE USER ROLE
             $temp_client = $manager->getRepository('CampaignBundle:Client')->findOneByName('temp_client');
             $global_region = $manager->getRepository('CampaignBundle:Region')->find(1);
             $temp_useraccess = new Useraccess();
             $temp_useraccess->setUser($user);
             $temp_useraccess->setClient($temp_client);
             $temp_useraccess->setRegion($global_region);
             $temp_useraccess->setAllCountries(true);
             $manager->persist($temp_useraccess);
             //
             $manager->flush();
             $output->writeln('Created user ' . $i . ' role : ' . $role . '     Userid:' . $user->getId());
         }
     } elseif ($input->getOption('remove')) {
         $existing_users = $manager->getRepository('UserBundle:User')->findByConfirmationToken('deletable');
         $count = 0;
         foreach ($existing_users as $user) {
             if ($user->hasRole('ROLE_ADMINISTRATOR')) {
                 $client = $manager->getRepository('CampaignBundle:Client')->find(1);
                 $region = $manager->getRepository('CampaignBundle:Region')->find(1);
                 $useraccess = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $client, 'region' => $region]);
                 if ($useraccess) {
                     $manager->remove($useraccess);
                 }
             }
             $temp_client = $manager->getRepository('CampaignBundle:Client')->find(2);
             $temp_useraccess = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $temp_client]);
             $manager->remove($temp_useraccess);
             $manager->remove($user);
             $count += 1;
         }
         $manager->flush();
         $output->writeln(' ');
         $output->writeln('Removed ' . $count . ' test users.');
         $output->writeln(' ');
     } else {
         $number = $input->getArgument('number');
         $output->writeln(' ');
         $output->writeln(' ');
         $output->writeln('You can use --add / --remove options to change what the command should do.The command is for testing purposes only.');
         $output->writeln(' ');
         $output->writeln(' ');
     }
 }
예제 #4
0
 /**
  * @Route("/users/registration", name="_users_registration")
  * @Method("POST")
  *
  * @ApiDoc(
  *      deprecated=TRUE,
  * 		description = "no longer used.  Was used to create users with very limited data.",
  *      section="Users",
  * 		statusCodes = {
  * 			201 = "User added to the database.",
  * 			403 = "Returned when parameters used for registration are not valid."
  * 		},
  * 		parameters = {
  *                      {"name" = "active",    "dataType"="boolean",   "required"=true, "format"="true/false","description"="User is active or disabled."},
  *                      {"name" = "username",   "dataType"="text",      "required"=true, "description"="username description"},
  *                      {"name" = "lastname",   "dataType"="text",      "required"=true, "description"="lastname description"},
  *                      {"name" = "firstname",  "dataType"="text",      "required"=true, "description"="firstname description"},
  *                      {"name" = "email",      "dataType"="text",      "required"=true, "description"="email description"},
  *                      {"name" = "phone",      "dataType"="text",      "required"=true, "description"="phone description"},
  *                      {"name" = "title",      "dataType"="text",      "required"=true, "description"="title description"},
  *                      {"name" = "office",     "dataType"="text",      "required"=true, "description"="office description"},
  *                      {"name" = "profile_picture", "dataType"="text", "required"=true, "description"="profile_picture description"},
  *                      {"name" = "role_id", "dataType"="text", "required"=true, "description"="role for this user (1 , 2 or 3 )"},
  *                      {"name" = "password",   "dataType"="text",      "required"=true, "description"="password description"},
  *                      
  * 			
  * 		}
  * )
  *
  */
 public function postUsersAction(Request $request)
 {
     $response = new Response();
     $createDate = new \DateTime();
     $createDate->setTimezone(self::timezoneUTC());
     // Create User instance and set property values:
     $user = new User();
     $user->setEnabled($request->get('active'));
     $user->setUsername($request->get('username'));
     $user->setLastname($request->get('lastname'));
     $user->setFirstname($request->get('firstname'));
     $user->setEmail($request->get('email'));
     $user->setPhone($request->get('phone'));
     $user->setTitle($request->get('title'));
     $user->setOffice($request->get('office'));
     $user->setProfilepicture($request->get('profile_picture'));
     $user->setPassword($request->get('password'));
     if ($request->get('role_id') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field role_id must have a value!')));
         return $response;
     }
     $role_id = $request->get('role_id');
     $role = $this->getDoctrine()->getRepository('UserBundle:Role')->findOneById($role_id);
     if (!$role) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'You provided an invalid role id / No role_id provided.')));
         return $response;
     }
     if ($request->get('active') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field active must have a value!')));
         return $response;
     }
     if ($request->get('username') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field username must have a value!')));
         return $response;
     }
     $username_already_exists = $this->getDoctrine()->getRepository('UserBundle:User')->findOneByUsername($request->get('username'));
     if ($username_already_exists) {
         $response->setStatusCode(400);
         $response->setContent(json_encode(array('success' => false, 'message' => 'The username provided is already in use.')));
         return $response;
     }
     if ($request->get('lastname') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field lastname must have a value!')));
         return $response;
     }
     if ($request->get('firstname') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field firstname must have a value!')));
         return $response;
     }
     if ($request->get('email') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field email must have a value!')));
         return $response;
     }
     if ($request->get('phone') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field phone must have a value!')));
         return $response;
     }
     if ($request->get('title') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field title must have a value!')));
         return $response;
     }
     if ($request->get('office') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field office must have a value!')));
         return $response;
     }
     if ($request->get('profile_picture') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field profile_picture must have a value!')));
         return $response;
     }
     if ($request->get('password') == null) {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('success' => false, 'message' => 'Field password must have a value!')));
         return $response;
     }
     $role_name = $role->getName();
     $user->addRole($role_name);
     $user->setCreatedAt($createDate);
     $user->setUpdatedAt($createDate);
     //   $response->headers->set('Content-Type', 'application/json');
     //  $serializer = $this->get('jms_serializer');
     // Get validator service to check for errors:
     $validator = $this->get('validator');
     $errors = $validator->validate($user);
     ////
     //IN ORDER TO BE A OK RESPONSE < HERE WE MUST RETURN A RESPONSE NOT A VIEW
     if (count($errors) > 0) {
         // Return $errors in JSON format:
         $view = $this->view($errors, 400);
         return $this->handleView($view);
     }
     // End of IF errors check.
     $user->setPassword(md5($request->request->get('password')));
     $key = Uuid::uuid4()->toString();
     $user->setApiKey($key);
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     ///SET THE USER TO HAVE USERACCESS TO TEMP_CLIENT
     $temp_client = $this->getDoctrine()->getRepository('CampaignBundle:Client')->findOneByName('temp_client');
     $global_region = $this->getDoctrine()->getRepository('CampaignBundle:Region')->findOneByName('Global');
     $temp_useraccess = new Useraccess();
     $temp_useraccess->setClient($temp_client);
     $temp_useraccess->setRegion($global_region);
     $temp_useraccess->setAllCountries(true);
     $temp_useraccess->setUser($user);
     $em->persist($temp_useraccess);
     //END SET USER FOR USERACCESS
     $em->flush();
     $response->setStatusCode(201);
     $response->setContent(json_encode(array('success' => true, 'message' => 'User added to the database.')));
     return $response;
 }