Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConvertLqtPageFromRemoteApiForTesting
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3namespace Flow\Maintenance;
4
5use Flow\Container;
6use Flow\Exception\FlowException;
7use Flow\Hooks;
8use Flow\Import\LiquidThreadsApi\ImportSource;
9use Flow\Import\LiquidThreadsApi\RemoteApiBackend;
10use Flow\Import\SourceStore\FileImportSourceStore;
11use Maintenance;
12use MediaWiki\Title\Title;
13use Psr\Log\LogLevel;
14
15$IP = getenv( 'MW_INSTALL_PATH' );
16if ( $IP === false ) {
17    $IP = __DIR__ . '/../../..';
18}
19
20require_once "$IP/maintenance/Maintenance.php";
21
22/**
23 * This is *only* for use in testing, not production.  The primary purpose is to exercise
24 * the API (production also uses the API, but with FauxRequest) and Parsoid.
25 *
26 * This also does not test redirects or notification conversion.
27 */
28class ConvertLqtPageFromRemoteApiForTesting extends Maintenance {
29    public function __construct() {
30        parent::__construct();
31        $this->addDescription( "Converts LiquidThreads data to Flow data.  Destination page is determined by ConversionStrategy" );
32        $this->addOption( 'dstpage', 'Page name of the destination page on the current wiki.  Defaults to same as source', false, true );
33        $this->addOption( 'srcpage', 'Page name of the source page to import from.', true, true );
34        $this->addOption( 'remoteapi', 'Remote API URL to read from', true, true );
35        $this->addOption( 'cacheremoteapidir', 'Cache remote api calls to the specified directory', true, true );
36        $this->addOption( 'logfile', 'File to read and store associations between imported items and their sources', true, true );
37        $this->addOption( 'debug', 'Include debug information to progress report' );
38        $this->requireExtension( 'Flow' );
39    }
40
41    public function execute() {
42        $cacheDir = $this->getOption( 'cacheremoteapidir' );
43        if ( !is_dir( $cacheDir ) ) {
44            if ( !mkdir( $cacheDir ) ) {
45                throw new FlowException( 'Provided dir for caching remote api calls is not creatable.' );
46            }
47        }
48        if ( !is_writable( $cacheDir ) ) {
49            throw new FlowException( 'Provided dir for caching remote api calls is not writable.' );
50        }
51
52        $api = new RemoteApiBackend( $this->getOption( 'remoteapi' ), $cacheDir );
53
54        $importer = Container::get( 'importer' );
55        $importer->setAllowUnknownUsernames( true );
56
57        $talkPageManagerUser = Hooks::getOccupationController()->getTalkpageManager();
58
59        $srcPageName = $this->getOption( 'srcpage' );
60        if ( $this->hasOption( 'dstpage' ) ) {
61            $dstPageName = $this->getOption( 'dstpage' );
62        } else {
63            $dstPageName = $srcPageName;
64        }
65
66        $dstTitle = Title::newFromText( $dstPageName );
67        $source = new ImportSource(
68            $api,
69            $srcPageName,
70            $talkPageManagerUser
71        );
72
73        $logFilename = $this->getOption( 'logfile' );
74        $sourceStore = new FileImportSourceStore( $logFilename );
75
76        $logger = new MaintenanceDebugLogger( $this );
77        if ( $this->getOption( 'debug' ) ) {
78            $logger->setMaximumLevel( LogLevel::DEBUG );
79        } else {
80            $logger->setMaximumLevel( LogLevel::INFO );
81        }
82
83        $importer->setLogger( $logger );
84        $api->setLogger( $logger );
85
86        $logger->info( "Starting LQT conversion of page $srcPageName" );
87
88        $importer->import( $source, $dstTitle, $talkPageManagerUser, $sourceStore );
89
90        $logger->info( "Finished LQT conversion of page $srcPageName" );
91    }
92}
93
94$maintClass = ConvertLqtPageFromRemoteApiForTesting::class;
95require_once RUN_MAINTENANCE_IF_MAIN;