1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Tenant\Loader; |
4
|
|
|
|
5
|
|
|
use AppBundle\Service\BusinessUnitService; |
6
|
|
|
use Ds\Component\Tenant\Entity\Tenant; |
7
|
|
|
use Ds\Component\Tenant\Loader\Loader; |
8
|
|
|
use Symfony\Component\Yaml\Yaml; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class BusinessUnitLoader |
12
|
|
|
*/ |
13
|
|
|
class BusinessUnitLoader implements Loader |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var \AppBundle\Service\BusinessUnitService |
17
|
|
|
*/ |
18
|
|
|
protected $businessUnitService; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
* |
23
|
|
|
* @param \AppBundle\Service\BusinessUnitService $businessUnitService |
24
|
|
|
*/ |
25
|
|
|
public function __construct(BusinessUnitService $businessUnitService) |
26
|
|
|
{ |
27
|
|
|
$this->businessUnitService = $businessUnitService; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function load(Tenant $tenant) |
34
|
|
|
{ |
35
|
|
|
$yml = file_get_contents('/srv/api-platform/src/AppBundle/Resources/tenant/business_units.yml'); |
36
|
|
|
|
37
|
|
|
// @todo Figure out how symfony does parameter binding and use the same technique |
38
|
|
|
$yml = strtr($yml, [ |
39
|
|
|
'%business_unit.administration.uuid%' => $tenant->getData()['business_unit']['administration']['uuid'], |
40
|
|
|
'%tenant.uuid%' => $tenant->getUuid() |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$businessUnits = Yaml::parse($yml, YAML::PARSE_OBJECT_FOR_MAP); |
44
|
|
|
$manager = $this->businessUnitService->getManager(); |
45
|
|
|
|
46
|
|
|
foreach ($businessUnits->objects as $object) { |
47
|
|
|
$object = (object) array_merge((array) $businessUnits->prototype, (array) $object); |
48
|
|
|
$businessUnit = $this->businessUnitService->createInstance(); |
49
|
|
|
$businessUnit |
50
|
|
|
->setUuid($object->uuid) |
51
|
|
|
->setOwner($object->owner) |
52
|
|
|
->setOwnerUuid($object->owner_uuid) |
53
|
|
|
->setTitle((array) $object->title) |
54
|
|
|
->setTenant($object->tenant); |
55
|
|
|
$manager->persist($businessUnit); |
56
|
|
|
$manager->flush(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|