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