GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b5dfb6...a568a9 )
by Mario
40:05
created

DatabaseAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Action;
6
7
use Doctrine\DBAL\DBALException;
8
use eZ\Publish\API\Repository\Repository;
9
use eZ\Publish\Core\Repository\Values\Content\Content;
10
use Netgen\InformationCollection\Doctrine\Entity\EzInfoCollection;
11
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
12
use Netgen\InformationCollection\API\Exception\ActionFailedException;
13
use Netgen\InformationCollection\Core\Factory\FieldDataFactory;
14
use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionAttributeRepository;
15
use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionRepository;
16
17
use Netgen\InformationCollection\API\Action\ActionInterface;
18
use Netgen\InformationCollection\API\Action\CrucialActionInterface;
19
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;
20
21
class DatabaseAction implements ActionInterface, CrucialActionInterface
22
{
23
    /**
24
     * @var FieldDataFactory
25
     */
26
    protected $factory;
27
28
    /**
29
     * @var EzInfoCollectionRepository
30
     */
31
    protected $infoCollectionRepository;
32
33
    /**
34
     * @var EzInfoCollectionAttributeRepository
35
     */
36
    protected $infoCollectionAttributeRepository;
37
38
    /**
39
     * @var Repository
40
     */
41
    protected $repository;
42
43
    /**
44
     * PersistToDatabaseAction constructor.
45
     *
46
     * @param FieldDataFactory $factory
47
     * @param EzInfoCollectionRepository $infoCollectionRepository
48
     * @param EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository
49
     * @param Repository $repository
50
     */
51
    public function __construct(
52
        FieldDataFactory $factory,
53
        EzInfoCollectionRepository $infoCollectionRepository,
54
        EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository,
55
        Repository $repository
56
    ) {
57
        $this->factory = $factory;
58
        $this->infoCollectionRepository = $infoCollectionRepository;
59
        $this->infoCollectionAttributeRepository = $infoCollectionAttributeRepository;
60
        $this->repository = $repository;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function act(InformationCollected $event): void
67
    {
68
        $struct = $event->getInformationCollectionStruct();
69
        $contentType = $event->getContentType();
70
        $location = $event->getLocation();
71
72
        /** @var Content $content */
73
        $content = $this->repository->getContentService()->loadContent($location->contentInfo->id);
74
75
        $currentUser = $this->repository->getCurrentUser();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
        $dt = new \DateTimeImmutable();
77
78
        /** @var EzInfoCollection $ezInfo */
79
        $ezInfo = $this->infoCollectionRepository->getInstance();
80
81
        $ezInfo->setContentObjectId($location->getContentInfo()->id);
82
        $ezInfo->setUserIdentifier($currentUser->login);
83
        $ezInfo->setCreatorId($currentUser->id);
84
        $ezInfo->setCreated($dt->getTimestamp());
85
        $ezInfo->setModified($dt->getTimestamp());
86
87
        try {
88
            $this->infoCollectionRepository->save($ezInfo);
89
        } catch (DBALException $e) {
90
            throw new ActionFailedException('database', $e->getMessage());
91
        }
92
93
        /**
94
         * @var string
95
         * @var \eZ\Publish\Core\FieldType\Value $value
96
         */
97
        foreach ($struct->getCollectedFields() as $fieldDefIdentifier => $value) {
98
            if ($value === null) {
99
                continue;
100
            }
101
102
            $value = $this->factory->getLegacyValue($value, $contentType->getFieldDefinition($fieldDefIdentifier));
103
104
            $ezInfoAttribute = $this->infoCollectionAttributeRepository->getInstance();
105
106
            /* @var LegacyData $value */
107
            $ezInfoAttribute->setContentObjectId($location->getContentInfo()->id);
108
            $ezInfoAttribute->setInformationCollectionId($ezInfo->getId());
109
            $ezInfoAttribute->setContentClassAttributeId($value->getContentClassAttributeId());
110
            $ezInfoAttribute->setContentObjectAttributeId($content->getField($fieldDefIdentifier)->id);
111
            $ezInfoAttribute->setDataInt($value->getDataInt());
112
            $ezInfoAttribute->setDataFloat($value->getDataFloat());
113
            $ezInfoAttribute->setDataText($value->getDataText());
114
115
            try {
116
                $this->infoCollectionAttributeRepository->save($ezInfoAttribute);
117
            } catch (DBALException $e) {
118
                throw new ActionFailedException('database', $e->getMessage());
119
            }
120
        }
121
    }
122
}
123