Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 61 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ConvertAllLqtPages | |
0.00% |
0 / 55 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
20 | |||
buildIterator | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Flow\Maintenance; |
4 | |
5 | use AppendIterator; |
6 | use Flow\Container; |
7 | use Flow\Hooks; |
8 | use Flow\Import\Converter; |
9 | use Flow\Import\LiquidThreadsApi\ConversionStrategy; |
10 | use Flow\Import\LiquidThreadsApi\LocalApiBackend; |
11 | use Flow\Import\SourceStore\FileImportSourceStore; |
12 | use Flow\Import\SourceStore\FlowRevisionsDb; |
13 | use Flow\Utils\NamespaceIterator; |
14 | use Flow\Utils\PagesWithPropertyIterator; |
15 | use Maintenance; |
16 | use Psr\Log\AbstractLogger; |
17 | use Psr\Log\LogLevel; |
18 | use Wikimedia\Rdbms\IDatabase; |
19 | |
20 | $IP = getenv( 'MW_INSTALL_PATH' ); |
21 | if ( $IP === false ) { |
22 | $IP = __DIR__ . '/../../..'; |
23 | } |
24 | |
25 | require_once "$IP/maintenance/Maintenance.php"; |
26 | |
27 | /** |
28 | * Converts all LiquidThreads pages on a wiki to Flow. When using the logfile |
29 | * option this process is idempotent.It may be run many times and will only import |
30 | * one copy of each item. |
31 | */ |
32 | class ConvertAllLqtPages extends Maintenance { |
33 | public function __construct() { |
34 | parent::__construct(); |
35 | $this->addDescription( "Converts LiquidThreads data to Flow data" ); |
36 | $this->addOption( 'logfile', 'File to read and store associations between imported items ' . |
37 | 'and their sources. This is required for the import to be idempotent.', false, true ); |
38 | $this->addOption( 'force-recovery-conversion', 'If a previous logfile was lost, this ' . |
39 | 'option can be set to attempt to map threads to topics that have already been ' . |
40 | 'imported to prevent doubles.' ); |
41 | $this->addOption( 'debug', 'Include debug information with progress report' ); |
42 | $this->requireExtension( 'Flow' ); |
43 | } |
44 | |
45 | public function execute() { |
46 | $logfile = $this->getOption( 'logfile' ); |
47 | if ( $logfile ) { |
48 | $sourceStore = new FileImportSourceStore( $logfile ); |
49 | } elseif ( $this->getOption( 'force-recovery-conversion' ) ) { |
50 | // fallback: if we don't have a sourcestore to go on, at least look |
51 | // at DB to figure out what's already imported... |
52 | $dbr = Container::get( 'db.factory' )->getDB( DB_REPLICA ); |
53 | $sourceStore = new FlowRevisionsDb( $dbr ); |
54 | } else { |
55 | $this->error( 'Param logfile or force-recovery-conversion required!' ); |
56 | $this->maybeHelp( true ); |
57 | die( 1 ); |
58 | } |
59 | |
60 | $logger = new MaintenanceDebugLogger( $this ); |
61 | if ( $this->getOption( 'debug' ) ) { |
62 | $logger->setMaximumLevel( LogLevel::DEBUG ); |
63 | } else { |
64 | $logger->setMaximumLevel( LogLevel::INFO ); |
65 | } |
66 | |
67 | $importer = Container::get( 'importer' ); |
68 | $talkpageManagerUser = Hooks::getOccupationController()->getTalkpageManager(); |
69 | |
70 | $dbw = $this->getPrimaryDB(); |
71 | $strategy = new ConversionStrategy( |
72 | $dbw, |
73 | $sourceStore, |
74 | new LocalApiBackend( $talkpageManagerUser ), |
75 | Container::get( 'url_generator' ), |
76 | $talkpageManagerUser, |
77 | Container::get( 'controller.notification' ) |
78 | ); |
79 | |
80 | $converter = new Converter( |
81 | $dbw, |
82 | $importer, |
83 | $logger, |
84 | $talkpageManagerUser, |
85 | $strategy |
86 | ); |
87 | |
88 | $titles = $this->buildIterator( $logger, $dbw ); |
89 | |
90 | $logger->info( "Starting full wiki LQT conversion of all LiquidThreads pages" ); |
91 | $converter->convertAll( $titles ); |
92 | $logger->info( "Finished conversion" ); |
93 | } |
94 | |
95 | /** |
96 | * @param AbstractLogger $logger |
97 | * @param IDatabase $dbw |
98 | * @return AppendIterator |
99 | */ |
100 | private function buildIterator( $logger, $dbw ) { |
101 | global $wgLqtTalkPages; |
102 | |
103 | $iterator = new AppendIterator(); |
104 | |
105 | $logger->info( "Considering for conversion: pages with the 'use-liquid-threads' property" ); |
106 | $withProperty = new PagesWithPropertyIterator( $dbw, 'use-liquid-threads' ); |
107 | $iterator->append( $withProperty->getIterator() ); |
108 | |
109 | if ( $wgLqtTalkPages ) { |
110 | foreach ( $this->getServiceContainer()->getNamespaceInfo()->getTalkNamespaces() as $ns ) { |
111 | $logger->info( "Considering for conversion: pages in namespace $ns" ); |
112 | $it = new NamespaceIterator( $dbw, $ns ); |
113 | $iterator->append( $it->getIterator() ); |
114 | } |
115 | } |
116 | |
117 | return $iterator; |
118 | } |
119 | } |
120 | |
121 | $maintClass = ConvertAllLqtPages::class; |
122 | require_once RUN_MAINTENANCE_IF_MAIN; |