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