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