Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConvertLqtPageOnLocalWiki
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Flow\Maintenance;
4
5use Flow\Container;
6use Flow\Import\Converter;
7use Flow\Import\LiquidThreadsApi\ConversionStrategy;
8use Flow\Import\LiquidThreadsApi\LocalApiBackend;
9use Flow\Import\SourceStore\FileImportSourceStore;
10use Flow\OccupationController;
11use MediaWiki\Maintenance\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 intended for use both in testing and in production.  It converts a single LQT
24 * page on the current wiki to a Flow page on the current wiki, handling archiving.
25 */
26class ConvertLqtPageOnLocalWiki extends Maintenance {
27    public function __construct() {
28        parent::__construct();
29        $this->addDescription( "Converts LiquidThreads data to Flow data on the current wiki, using a ConversionStrategy" );
30        $this->addOption( 'srcpage', 'Page name of the source page to import from.', true, true );
31        $this->addOption( 'logfile', 'File to read and store associations between imported items and their sources', true, true );
32        $this->addOption( 'debug', 'Include debug information to progress report' );
33        $this->addOption( 'dryrun', 'Show what would be converted, but do not make any changes.' );
34        $this->addOption( 'ignoreflowreadonly', 'Ignore $wgFlowReadOnly if set, allowing boards to be created.' );
35        $this->addOption( 'convertempty', 'Convert pages even if they have no threads.' );
36        $this->addOption( 'insert-ignore', 'Ignore duplicate key insert errors.' );
37        $this->requireExtension( 'Flow' );
38    }
39
40    public function execute() {
41        global $wgFlowReadOnly;
42
43        if ( $wgFlowReadOnly ) {
44            if ( $this->getOption( 'ignoreflowreadonly', false ) ) {
45                // Make Flow writable for the duration of the script
46                $wgFlowReadOnly = false;
47            } else {
48                $this->error( 'Flow is in read-only mode. Use --ignoreflowreadonly to continue.' );
49                return;
50            }
51        }
52
53        /** @var OccupationController $occupationController */
54        $occupationController = $this->getServiceContainer()->getService( 'FlowTalkpageManager' );
55        $talkPageManagerUser = $occupationController->getTalkpageManager();
56
57        $api = new LocalApiBackend( $talkPageManagerUser );
58
59        $importer = Container::get( 'importer' );
60
61        $srcPageName = $this->getOption( 'srcpage' );
62
63        $logFilename = $this->getOption( 'logfile' );
64        $sourceStore = new FileImportSourceStore( $logFilename );
65
66        $dbw = $this->getPrimaryDB();
67
68        $logger = new MaintenanceDebugLogger( $this );
69        if ( $this->getOption( 'debug' ) ) {
70            $logger->setMaximumLevel( LogLevel::DEBUG );
71        } else {
72            $logger->setMaximumLevel( LogLevel::INFO );
73        }
74
75        $strategy = new ConversionStrategy(
76            $dbw,
77            $sourceStore,
78            $api,
79            Container::get( 'url_generator' ),
80            $talkPageManagerUser,
81            Container::get( 'controller.notification' )
82        );
83
84        $importer->setLogger( $logger );
85        $api->setLogger( $logger );
86
87        $converter = new Converter(
88            $dbw,
89            $importer,
90            $logger,
91            $talkPageManagerUser,
92            $strategy
93        );
94
95        $logger->info( "Starting LQT conversion of page $srcPageName" );
96
97        $srcTitle = Title::newFromText( $srcPageName );
98        $dryRun = $this->getOption( 'dryrun', false );
99        $convertEmpty = $this->getOption( 'convertempty', false );
100
101        $converter->convertAll( [ $srcTitle ], $dryRun, $convertEmpty );
102
103        $logger->info( "Finished LQT conversion of page $srcPageName" );
104    }
105}
106
107$maintClass = ConvertLqtPageOnLocalWiki::class;
108require_once RUN_MAINTENANCE_IF_MAIN;