Passed
Push — master ( 8a455a...42a228 )
by Craig
07:01
created

ThemeHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\Bundle\CoreInstallerBundle\Helper;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use Zikula\ThemeModule\Entity\Repository\ThemeEntityRepository;
18
use Zikula\ThemeModule\Entity\ThemeEntity;
19
use Zikula\ThemeModule\Helper\BundleSyncHelper;
20
21
class ThemeHelper
22
{
23
    /**
24
     * @var BundleSyncHelper
25
     */
26
    private $themeSyncHelper;
27
28
    /**
29
     * @var EntityManagerInterface
30
     */
31
    private $em;
32
33
    /**
34
     * ThemeHelper constructor.
35
     */
36
    public function __construct(
37
        BundleSyncHelper $themeSyncHelper,
38
        EntityManagerInterface $em
39
    ) {
40
        $this->themeSyncHelper = $themeSyncHelper;
41
        $this->em = $em;
42
    }
43
44
    public function regenerateThemes(): bool
45
    {
46
        // regenerate the themes list
47
        $this->themeSyncHelper->regenerate();
48
        // set all themes as active @todo this is probably overkill
49
        $themes = $this->em->getRepository('ZikulaThemeModule:ThemeEntity')->findAll();
50
        /** @var ThemeEntity $theme */
51
        foreach ($themes as $theme) {
52
            $theme->setState(ThemeEntityRepository::STATE_ACTIVE);
53
        }
54
        $this->em->flush();
55
56
        return true;
57
    }
58
}
59