2
2
3
3
namespace Shopware \Core \Framework \Adapter \Twig \NamespaceHierarchy ;
4
4
5
+ use Doctrine \DBAL \Connection ;
5
6
use Shopware \Core \Framework \Bundle ;
6
- use Shopware \Core \Framework \Context ;
7
- use Shopware \Core \Framework \DataAbstractionLayer \EntityRepositoryInterface ;
8
- use Shopware \Core \Framework \DataAbstractionLayer \Search \Aggregation \Bucket \TermsAggregation ;
9
- use Shopware \Core \Framework \DataAbstractionLayer \Search \AggregationResult \Bucket \TermsResult ;
10
- use Shopware \Core \Framework \DataAbstractionLayer \Search \Criteria ;
11
- use Shopware \Core \Framework \DataAbstractionLayer \Search \Filter \EqualsFilter ;
12
7
use Symfony \Component \HttpKernel \KernelInterface ;
13
8
14
9
class BundleHierarchyBuilder implements TemplateNamespaceHierarchyBuilderInterface
15
10
{
16
- /**
17
- * @var KernelInterface
18
- */
19
- private $ kernel ;
11
+ private KernelInterface $ kernel ;
20
12
21
- /**
22
- * @var EntityRepositoryInterface
23
- */
24
- private $ appRepository ;
13
+ private Connection $ connection ;
25
14
26
- public function __construct (KernelInterface $ kernel , EntityRepositoryInterface $ appRepository )
15
+ public function __construct (KernelInterface $ kernel , Connection $ connection )
27
16
{
28
17
$ this ->kernel = $ kernel ;
29
- $ this ->appRepository = $ appRepository ;
18
+ $ this ->connection = $ connection ;
30
19
}
31
20
32
21
public function buildNamespaceHierarchy (array $ namespaceHierarchy ): array
33
22
{
23
+ $ bundles = [];
24
+
34
25
foreach ($ this ->kernel ->getBundles () as $ bundle ) {
35
26
if (!$ bundle instanceof Bundle) {
36
27
continue ;
@@ -44,29 +35,26 @@ public function buildNamespaceHierarchy(array $namespaceHierarchy): array
44
35
continue ;
45
36
}
46
37
47
- array_unshift ($ namespaceHierarchy , $ bundle ->getName ());
48
-
49
- $ namespaceHierarchy = array_values (array_unique ($ namespaceHierarchy ));
38
+ // bundle or plugin version unknown at this point
39
+ $ bundles [$ bundle ->getName ()] = 1 ;
50
40
}
51
41
52
- return array_unique (array_merge ($ this ->getAppTemplateNamespaces (), $ namespaceHierarchy ));
42
+ $ bundles = array_reverse ($ bundles );
43
+
44
+ return array_merge (
45
+ $ this ->getAppTemplateNamespaces (),
46
+ $ bundles ,
47
+ $ namespaceHierarchy
48
+ );
53
49
}
54
50
55
- /**
56
- * @return string[]
57
- */
58
51
private function getAppTemplateNamespaces (): array
59
52
{
60
- $ criteria = new Criteria ();
61
- $ criteria ->addFilter (
62
- new EqualsFilter ('app.active ' , true ),
63
- new EqualsFilter ('app.templates.active ' , true )
53
+ return $ this ->connection ->fetchAllKeyValue (
54
+ 'SELECT `app`.`name`, `app`.`version`
55
+ FROM `app`
56
+ INNER JOIN `app_template` ON `app_template`.`app_id` = `app`.`id`
57
+ WHERE `app`.`active` = 1 AND `app_template`.`active` = 1 '
64
58
);
65
- $ criteria ->addAggregation (new TermsAggregation ('appNames ' , 'app.name ' ));
66
-
67
- /** @var TermsResult $appNames */
68
- $ appNames = $ this ->appRepository ->aggregate ($ criteria , Context::createDefaultContext ())->get ('appNames ' );
69
-
70
- return $ appNames ->getKeys ();
71
59
}
72
60
}
0 commit comments