Skip to content

Commit f8394bb

Browse files
Adding space-id-to-space-key map
1 parent 1396aba commit f8394bb

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/Analyzer/ConfluenceAnalyzer.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function __construct( $config, Workspace $workspace, DataBuckets $buckets
9595
parent::__construct( $config, $workspace, $buckets );
9696
$this->customBuckets = new DataBuckets( [
9797
'space-id-to-prefix-map',
98+
'space-id-to-space-key-map',
9899
'space-key-to-prefix-map',
99100
'space-name-to-prefix-map',
100101
'space-id-to-name-map',
@@ -351,6 +352,9 @@ private function buildSpaceMaps( DOMDocument $dom ): void {
351352
$this->customBuckets->addData(
352353
'space-key-to-prefix-map', $spaceKey, $customSpacePrefix, false, true
353354
);
355+
$this->customBuckets->addData(
356+
'space-id-to-space-key-map', $spaceId, $spaceKey, false, true
357+
);
354358
$this->customBuckets->addData(
355359
'space-name-to-prefix-map', $spaceName, $customSpacePrefix, false, true
356360
);
@@ -619,6 +623,7 @@ private function buildUserMap( DOMDocument $dom ): void {
619623
*/
620624
private function buildPageMaps( DOMDocument $dom ): void {
621625
$spaceIdToPrefixMap = $this->customBuckets->getBucketData( 'space-id-to-prefix-map' );
626+
$spaceIdToSpaceKeyMap = $this->customBuckets->getBucketData( 'space-id-to-space-key-map' );
622627
$spaceIdHomepages = $this->customBuckets->getBucketData( 'space-id-homepages' );
623628
$pageIdParentPageIdMap = $this->customBuckets->getBucketData( 'page-id-to-parent-page-id-map' );
624629
$pageIdConfluendTitleMap = $this->customBuckets->getBucketData( 'page-id-to-confluence-title-map' );
@@ -643,13 +648,14 @@ private function buildPageMaps( DOMDocument $dom ): void {
643648
if ( $spaceId === null ) {
644649
return;
645650
}
646-
if ( !isset( $spaceIdToPrefixMap[$spaceId] ) ) {
651+
if ( !isset( $spaceIdToSpaceKeyMap[$spaceId] ) ) {
647652
return;
648653
}
649-
$prefix = $spaceIdToPrefixMap[$spaceId];
654+
$spaceKey = $spaceIdToSpaceKeyMap[$spaceId];
655+
650656
if (
651657
isset( $this->advancedConfig['analyzer-include-spacekey'] )
652-
&& !in_array( strtolower( $prefix ), $this->advancedConfig['analyzer-include-spacekey'] )
658+
&& !in_array( strtolower( $spaceKey ), $this->advancedConfig['analyzer-include-spacekey'] )
653659
) {
654660
return;
655661
}
@@ -1078,7 +1084,6 @@ private function makeAttachmentReference( XMLHelper $xmlHelper, DOMElement $atta
10781084
}
10791085

10801086
private function checkTitles(): void {
1081-
$spacePrefixMap = $this->customBuckets->getBucketData( 'space-id-to-prefix-map' );
10821087
$pagesTitlesMap = $this->customBuckets->getBucketData( 'pages-titles-map' );
10831088

10841089
$hasInvalidTitles = false;
@@ -1115,7 +1120,7 @@ private function checkTitles(): void {
11151120
$hasInvalidNamespaces = true;
11161121
}
11171122

1118-
if ( mb_strlen( urlencode( $text ) ) > 255 ) {
1123+
if ( strlen( $text ) > 255 ) {
11191124
$this->customBuckets->addData(
11201125
'invalid-titles',
11211126
'length', $title,
@@ -1124,7 +1129,7 @@ private function checkTitles(): void {
11241129
$hasInvalidTitles = true;
11251130
}
11261131
} else {
1127-
if ( mb_strlen( urlencode( $title ) ) > 255 ) {
1132+
if ( strlen( $title ) > 255 ) {
11281133
$this->customBuckets->addData(
11291134
'invalid-titles',
11301135
'length', $title,

src/Converter/ConfluenceConverter.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DOMXPath;
99
use HalloWelt\MediaWiki\Lib\Migration\Converter\PandocHTML;
1010
use HalloWelt\MediaWiki\Lib\Migration\DataBuckets;
11+
use HalloWelt\MediaWiki\Lib\Migration\ExecutionTime;
1112
use HalloWelt\MediaWiki\Lib\Migration\IOutputAwareInterface;
1213
use HalloWelt\MediaWiki\Lib\Migration\Workspace;
1314
use HalloWelt\MigrateConfluence\Converter\Postprocessor\FixImagesWithExternalUrl;
@@ -134,7 +135,8 @@ public function __construct( $config, Workspace $workspace ) {
134135

135136
$this->customBuckets = new DataBuckets( [
136137
'title-uploads',
137-
'title-uploads-fail'
138+
'title-uploads-fail',
139+
'converter-body-content-id-execution-time',
138140
] );
139141
}
140142

@@ -149,6 +151,7 @@ public function setOutput( Output $output ) {
149151
* @inheritDoc
150152
*/
151153
protected function doConvert( SplFileInfo $file ): string {
154+
$executionTime = new ExecutionTime();
152155
$this->output->writeln( $file->getPathname() );
153156
$this->dataLookup = ConversionDataLookup::newFromBuckets( $this->dataBuckets );
154157
$this->conversionDataWriter = ConversionDataWriter::newFromBuckets( $this->dataBuckets );
@@ -218,6 +221,15 @@ protected function doConvert( SplFileInfo $file ): string {
218221
$this->postProcessLinks();
219222
$this->postprocessWikiText();
220223

224+
$executionTimeString = $executionTime->getHumanReadableTime();
225+
$this->customBuckets->addData(
226+
'converter-body-content-id-execution-time',
227+
$bodyContentId,
228+
$executionTimeString,
229+
false,
230+
true
231+
);
232+
221233
$this->customBuckets->saveToWorkspace( $this->workspace );
222234

223235
return $this->wikiText;
@@ -782,7 +794,11 @@ private function buildMediaExcludeList( $wikiText ): array {
782794
* @return string
783795
*/
784796
private function getCurrentPageTitle(): string {
797+
$prefix = '';
785798
$spaceIdPrefixMap = $this->dataBuckets->getBucketData( 'space-id-to-prefix-map' );
799+
if ( !isset( $spaceIdPrefixMap[$this->currentSpace] ) ) {
800+
$this->output->writeln( "SpaceId {$this->currentSpace} not found in spaceIdPrefixMap" );
801+
}
786802
$prefix = $spaceIdPrefixMap[$this->currentSpace];
787803
$currentPageTitle = $this->currentPageTitle;
788804

0 commit comments

Comments
 (0)