Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Importer
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 6
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 addPostprocessor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPostprocessor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setLogger
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setAllowUnknownUsernames
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 import
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Flow\Import;
4
5use Flow\Data\ManagerGroup;
6use Flow\DbFactory;
7use Flow\Import\Postprocessor\Postprocessor;
8use Flow\Import\Postprocessor\ProcessorGroup;
9use Flow\Import\SourceStore\SourceStoreInterface;
10use Flow\OccupationController;
11use Flow\WorkflowLoaderFactory;
12use MediaWiki\Title\Title;
13use MediaWiki\User\User;
14use Psr\Log\LoggerInterface;
15use Psr\Log\NullLogger;
16use SplQueue;
17
18/**
19 * The import system uses a TalkpageImportOperation class.
20 * This class is essentially a factory class that makes the
21 * dependency injection less inconvenient for callers.
22 */
23class Importer {
24    /** @var ManagerGroup */
25    protected $storage;
26    /** @var WorkflowLoaderFactory */
27    protected $workflowLoaderFactory;
28    /** @var LoggerInterface|null */
29    protected $logger;
30    /** @var DbFactory */
31    protected $dbFactory;
32    /** @var bool */
33    protected $allowUnknownUsernames;
34    /** @var ProcessorGroup */
35    protected $postprocessors;
36    /** @var SplQueue Callbacks for DeferredUpdate that are queue'd up by the commit process */
37    protected $deferredQueue;
38    /** @var OccupationController */
39    protected $occupationController;
40
41    public function __construct(
42        ManagerGroup $storage,
43        WorkflowLoaderFactory $workflowLoaderFactory,
44        DbFactory $dbFactory,
45        SplQueue $deferredQueue,
46        OccupationController $occupationController
47    ) {
48        $this->storage = $storage;
49        $this->workflowLoaderFactory = $workflowLoaderFactory;
50        $this->dbFactory = $dbFactory;
51        $this->postprocessors = new ProcessorGroup;
52        $this->deferredQueue = $deferredQueue;
53        $this->occupationController = $occupationController;
54    }
55
56    public function addPostprocessor( Postprocessor $proc ) {
57        $this->postprocessors->add( $proc );
58    }
59
60    /**
61     * Returns the ProcessorGroup (calling this triggers all the postprocessors
62     *
63     * @return Postprocessor
64     */
65    public function getPostprocessor() {
66        return $this->postprocessors;
67    }
68
69    /**
70     * @param LoggerInterface $logger
71     */
72    public function setLogger( LoggerInterface $logger ) {
73        $this->logger = $logger;
74    }
75
76    /**
77     * @param bool $allowed When true allow usernames that do not exist on the wiki to be
78     *  stored in the _ip field. *DO*NOT*USE* in any production setting, this is
79     *  to allow for imports from production wiki api's to test machines for
80     *  development purposes.
81     */
82    public function setAllowUnknownUsernames( $allowed ) {
83        $this->allowUnknownUsernames = (bool)$allowed;
84    }
85
86    /**
87     * Imports topics from a data source to a given page.
88     *
89     * @param IImportSource $source
90     * @param Title $targetPage
91     * @param User $user User doing the conversion actions (e.g. initial description,
92     *    wikitext archive edit).  However, actions will be attributed to the original
93     *    user when possible (e.g. the user who did the original LQT reply)
94     * @param SourceStoreInterface $sourceStore
95     * @return bool True When the import completes with no failures
96     */
97    public function import(
98        IImportSource $source,
99        Title $targetPage,
100        User $user,
101        SourceStoreInterface $sourceStore
102    ) {
103        $operation = new TalkpageImportOperation( $source, $user, $this->occupationController );
104        $pageImportState = new PageImportState(
105            $this->workflowLoaderFactory
106                ->createWorkflowLoader( $targetPage )
107                ->getWorkflow(),
108            $this->storage,
109            $sourceStore,
110            $this->logger ?: new NullLogger,
111            $this->dbFactory,
112            $this->postprocessors,
113            $this->deferredQueue,
114            $this->allowUnknownUsernames
115        );
116        return $operation->import( $pageImportState );
117    }
118}