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 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 | $this->addDescription( "Converts LiquidThreads data to Flow data. Destination page is determined by ConversionStrategy" ); |
33 | $this->addOption( 'dstpage', 'Page name of the destination page on the current wiki. Defaults to same as source', false, true ); |
34 | $this->addOption( 'srcpage', 'Page name of the source page to import from.', true, true ); |
35 | $this->addOption( 'remoteapi', 'Remote API URL to read from', true, true ); |
36 | $this->addOption( 'cacheremoteapidir', 'Cache remote api calls to the specified directory', true, true ); |
37 | $this->addOption( 'logfile', 'File to read and store associations between imported items and their sources', true, true ); |
38 | $this->addOption( 'debug', 'Include debug information to progress report' ); |
39 | $this->requireExtension( 'Flow' ); |
40 | } |
41 | |
42 | public function execute() { |
43 | $cacheDir = $this->getOption( 'cacheremoteapidir' ); |
44 | if ( !is_dir( $cacheDir ) ) { |
45 | if ( !mkdir( $cacheDir ) ) { |
46 | throw new FlowException( 'Provided dir for caching remote api calls is not creatable.' ); |
47 | } |
48 | } |
49 | if ( !is_writable( $cacheDir ) ) { |
50 | throw new FlowException( 'Provided dir for caching remote api calls is not writable.' ); |
51 | } |
52 | |
53 | $api = new RemoteApiBackend( $this->getOption( 'remoteapi' ), $cacheDir ); |
54 | |
55 | $importer = Container::get( 'importer' ); |
56 | $importer->setAllowUnknownUsernames( true ); |
57 | |
58 | /** @var OccupationController $occupationController */ |
59 | $occupationController = MediaWikiServices::getInstance()->getService( 'FlowTalkpageManager' ); |
60 | $talkPageManagerUser = $occupationController->getTalkpageManager(); |
61 | |
62 | $srcPageName = $this->getOption( 'srcpage' ); |
63 | if ( $this->hasOption( 'dstpage' ) ) { |
64 | $dstPageName = $this->getOption( 'dstpage' ); |
65 | } else { |
66 | $dstPageName = $srcPageName; |
67 | } |
68 | |
69 | $dstTitle = Title::newFromText( $dstPageName ); |
70 | $source = new ImportSource( |
71 | $api, |
72 | $srcPageName, |
73 | $talkPageManagerUser |
74 | ); |
75 | |
76 | $logFilename = $this->getOption( 'logfile' ); |
77 | $sourceStore = new FileImportSourceStore( $logFilename ); |
78 | |
79 | $logger = new MaintenanceDebugLogger( $this ); |
80 | if ( $this->getOption( 'debug' ) ) { |
81 | $logger->setMaximumLevel( LogLevel::DEBUG ); |
82 | } else { |
83 | $logger->setMaximumLevel( LogLevel::INFO ); |
84 | } |
85 | |
86 | $importer->setLogger( $logger ); |
87 | $api->setLogger( $logger ); |
88 | |
89 | $logger->info( "Starting LQT conversion of page $srcPageName" ); |
90 | |
91 | $importer->import( $source, $dstTitle, $talkPageManagerUser, $sourceStore ); |
92 | |
93 | $logger->info( "Finished LQT conversion of page $srcPageName" ); |
94 | } |
95 | } |
96 | |
97 | $maintClass = ConvertLqtPageFromRemoteApiForTesting::class; |
98 | require_once RUN_MAINTENANCE_IF_MAIN; |