|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
17
|
|
|
|
|
18
|
|
|
/* |
|
19
|
|
|
* |
|
20
|
|
|
* @author Thomas Rabaix <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class AddAuditEntityCompilerPass implements CompilerPassInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function process(ContainerBuilder $container) |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$container->hasDefinition('simplethings_entityaudit.config')) { |
|
30
|
|
|
return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$auditedEntities = $container->getParameter('simplethings.entityaudit.audited_entities'); |
|
34
|
|
|
$force = $container->getParameter('sonata_doctrine_orm_admin.audit.force'); |
|
35
|
|
|
|
|
36
|
|
|
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) { |
|
37
|
|
|
|
|
38
|
|
|
if ($attributes[0]['manager_type'] != 'orm') { |
|
39
|
|
|
continue; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (true === $force && isset($attributes[0]['audit']) && false === $attributes[0]['audit']) { |
|
43
|
|
|
continue; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (false === $force && (!isset($attributes[0]['audit']) || false === $attributes[0]['audit'])) { |
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$definition = $container->getDefinition($id); |
|
51
|
|
|
$auditedEntities[] = $this->getModelName($container, $definition->getArgument(1)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$auditedEntities = array_unique($auditedEntities); |
|
55
|
|
|
|
|
56
|
|
|
$container->setParameter('simplethings.entityaudit.audited_entities', $auditedEntities); |
|
57
|
|
|
$container->getDefinition('sonata.admin.audit.manager')->addMethodCall('setReader', array('sonata.admin.audit.orm.reader', $auditedEntities)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
private function getModelName(ContainerBuilder $container, $name) |
|
67
|
|
|
{ |
|
68
|
|
|
if ($name[0] == '%') { |
|
69
|
|
|
return $container->getParameter(substr($name, 1, -1)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $name; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|