|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kreta\AppBundle\Command; |
|
14
|
|
|
|
|
15
|
|
|
use Kreta\SharedKernel\Domain\Model\Identity\Slug; |
|
16
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\Organization; |
|
17
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId; |
|
18
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationName; |
|
19
|
|
|
use Kreta\TaskManager\Domain\Model\User\User; |
|
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
23
|
|
|
|
|
24
|
|
|
class OrganizationFixturesCommand extends ContainerAwareCommand |
|
25
|
|
|
{ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->setName('fixtures:organization'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$manager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
|
34
|
|
|
|
|
35
|
|
|
$users = $this->getContainer()->get('doctrine')->getRepository(User::class)->findAll(); |
|
36
|
|
|
|
|
37
|
|
|
$organizationId = OrganizationId::generate(); |
|
38
|
|
|
$organization = new Organization( |
|
39
|
|
|
$organizationId, |
|
40
|
|
|
new OrganizationName('Organization name'), |
|
41
|
|
|
new Slug('Organization name'), |
|
42
|
|
|
$users[0]->id() |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
$i = 0; |
|
46
|
|
|
foreach ($users as $user) { |
|
47
|
|
|
if ($i > 0) { |
|
48
|
|
|
$organization->addOrganizationMember($user->id()); |
|
49
|
|
|
} |
|
50
|
|
|
++$i; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$manager->persist($organization); |
|
54
|
|
|
$manager->flush(); |
|
55
|
|
|
$output->writeln('Population is successfully done'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|