示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $command = $this->getApplication()->find('orm:schema-tool:create');
         $returnCode = $command->run($input, $output);
     } catch (\Exception $e) {
         $output->writeln("<error>Your database alread have the schema!</error>");
     }
     $this->input = $input;
     $this->output = $output;
     $em = $this->getEm();
     $userRepo = $this->getEm()->getRepository('Orcamentos\\Model\\User');
     $users = $userRepo->findAll();
     if (count($users)) {
         $output->writeln("<error>Your database alread have users!</error>");
         return;
     }
     // Inserting types
     $equipmentType = new EquipmentType();
     $equipmentType->setName('Computador');
     $em->persist($equipmentType);
     $serviceType = new ServiceType();
     $serviceType->setName('Conta');
     $em->persist($serviceType);
     $humanType = new HumanType();
     $humanType->setName('Funcionário');
     $em->persist($humanType);
     // Company Questions
     $output->writeln("<info>Company setup:</info>");
     $companyName = $this->askFor('What is your company name', 'Demo');
     $companyTelephone = $this->askFor('Company phone number', '99 9999999');
     $companyEmail = $this->askFor('Company e-mail address', '*****@*****.**');
     $company = new Company();
     $company->setName($companyName);
     $company->setTelephone($companyTelephone);
     $company->setEmail($companyEmail);
     $company->setTaxes(6);
     $em->persist($company);
     // User questions
     $output->writeln("\n<info>User setup</info>");
     $userName = $this->askFor('Full name of the user', 'Administrator');
     $userEmail = $this->askFor('User\'s e-mail address', $companyEmail);
     $userPassword = $this->askForPassword();
     $userAdmin = true;
     $userCompany = $company->getId();
     $user = new User();
     $user->setName($userName);
     $user->setEmail($userEmail);
     $user->setPassword((new Bcrypt())->create($userPassword));
     $user->setAdmin(true);
     $user->setCompany($company);
     $em->persist($user);
     // Plan questions
     $output->writeln("\n<info>Plan setup:</info>");
     $planName = $this->askFor('Enter a name for the default plan', 'Default');
     $planPrice = 0 + $this->askFor('Enter the price for this plan', '0');
     $plan = new Plan();
     $plan->setName($planName);
     $plan->setPrice($planPrice);
     $plan->setQuoteLimit(null);
     $em->persist($plan);
     $company->setPlan($plan);
     try {
         $em->flush();
         $output->writeln("<info>Initial setup complete!<info>");
     } catch (\Exception $e) {
         $output->writeln("<error>Failed to initialize the database</error>");
     }
 }
示例#2
0
<?php

require_once '../app.php';
use Orcamentos\Model\Plan;
// php firstPlan.php "Plano beta" 49.90 null
$em = $app['orm.em'];
$alreadyDone = $em->getRepository('Orcamentos\\Model\\Plan')->findAll();
if (count($alreadyDone) == 0) {
    $planName = $argv[1];
    $planPrice = $argv[2];
    $planQuoteLimit = $argv[3];
    $plan = new Plan();
    $plan->setName($planName);
    $plan->setPrice($planPrice);
    $plan->setQuoteLimit($planQuoteLimit);
    $em->persist($plan);
    $companies = $em->getRepository('Orcamentos\\Model\\Company')->findAll();
    foreach ($companies as $company) {
        $company->setPlan($plan);
        $em->persist($company);
    }
    $em->flush();
}
return true;