Completed
Push — 6.7 ( caaa8b...485307 )
by
unknown
19:19
created

MigrationHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setIODataHandlersByIdentifiers() 0 13 1
A logError() 0 6 2
A logInfo() 0 6 2
A logMissingFile() 0 4 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishIOBundle\Migration;
8
9
use eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * The migration handler sets up from/to IO data handlers, and provides logging, for file migrators and listers.
14
 */
15
abstract class MigrationHandler implements MigrationHandlerInterface
16
{
17
    /** @var \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory */
18
    private $metadataHandlerFactory;
19
20
    /** @var \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory */
21
    private $binarydataHandlerFactory;
22
23
    /** @var \Psr\Log\LoggerInterface */
24
    private $logger;
25
26
    /** @var \eZ\Publish\Core\IO\IOMetadataHandler */
27
    protected $fromMetadataHandler;
28
29
    /** @var \eZ\Publish\Core\IO\IOBinarydataHandler */
30
    protected $fromBinarydataHandler;
31
32
    /** @var \eZ\Publish\Core\IO\IOMetadataHandler */
33
    protected $toMetadataHandler;
34
35
    /** @var \eZ\Publish\Core\IO\IOBinarydataHandler */
36
    protected $toBinarydataHandler;
37
38
    public function __construct(
39
        HandlerFactory $metadataHandlerFactory,
40
        HandlerFactory $binarydataHandlerFactory,
41
        LoggerInterface $logger = null
42
    ) {
43
        $this->metadataHandlerFactory = $metadataHandlerFactory;
44
        $this->binarydataHandlerFactory = $binarydataHandlerFactory;
45
        $this->logger = $logger;
46
    }
47
48
    final public function setIODataHandlersByIdentifiers(
49
        $fromMetadataHandlerIdentifier,
50
        $fromBinarydataHandlerIdentifier,
51
        $toMetadataHandlerIdentifier,
52
        $toBinarydataHandlerIdentifier
53
    ) {
54
        $this->fromMetadataHandler = $this->metadataHandlerFactory->getConfiguredHandler($fromMetadataHandlerIdentifier);
55
        $this->fromBinarydataHandler = $this->binarydataHandlerFactory->getConfiguredHandler($fromBinarydataHandlerIdentifier);
56
        $this->toMetadataHandler = $this->metadataHandlerFactory->getConfiguredHandler($toMetadataHandlerIdentifier);
57
        $this->toBinarydataHandler = $this->binarydataHandlerFactory->getConfiguredHandler($toBinarydataHandlerIdentifier);
58
59
        return $this;
60
    }
61
62
    final protected function logError($message)
63
    {
64
        if (isset($this->logger)) {
65
            $this->logger->error($message);
66
        }
67
    }
68
69
    final protected function logInfo($message)
70
    {
71
        if (isset($this->logger)) {
72
            $this->logger->info($message);
73
        }
74
    }
75
76
    final protected function logMissingFile($id)
77
    {
78
        $this->logInfo("File with id $id not found");
79
    }
80
}
81