$revision->insertOn( $dbw );
$changed = $page->updateIfNewerOn( $dbw, $revision );
+ $tags = $importableRevision->getTags();
+ if ( $tags !== [] ) {
+ ChangeTags::addTags( $tags, null, $revision->getId() );
+ }
+
if ( $changed !== false && $this->doUpdates ) {
$this->logger->debug( __METHOD__ . ": running updates\n" );
// countable/oldcountable stuff is handled in WikiImporter::finishImportPage
*/
public $sha1base36 = false;
+ /**
+ * @since 1.34
+ * @var string[]
+ */
+ protected $tags = [];
+
/**
* @since 1.17
* @var string
$this->sha1base36 = $sha1base36;
}
+ /**
+ * @since 1.34
+ * @param string[] $tags
+ */
+ public function setTags( array $tags ) {
+ $this->tags = $tags;
+ }
+
/**
* @since 1.12.2
* @param string $filename
return false;
}
+ /**
+ * @since 1.34
+ * @return string[]
+ */
+ public function getTags() {
+ return $this->tags;
+ }
+
/**
* @since 1.17
* @return string
--- /dev/null
+<?php
+
+use MediaWiki\MediaWikiServices;
+use Psr\Log\NullLogger;
+
+/**
+ * @group Database
+ * @coversDefaultClass ImportableOldRevisionImporter
+ */
+class ImportableOldRevisionImporterTest extends MediaWikiIntegrationTestCase {
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->tablesUsed[] = 'change_tag';
+ $this->tablesUsed[] = 'change_tag_def';
+
+ ChangeTags::defineTag( 'tag1' );
+ }
+
+ public function provideTestCases() {
+ yield [ [] ];
+ yield [ [ "tag1" ] ];
+ }
+
+ /**
+ * @covers ::import
+ * @param $expectedTags
+ * @dataProvider provideTestCases
+ */
+ public function testImport( $expectedTags ) {
+ $services = MediaWikiServices::getInstance();
+
+ $title = Title::newFromText( __CLASS__ . rand() );
+ $revision = new WikiRevision( $services->getMainConfig() );
+ $revision->setTitle( $title );
+ $revision->setTags( $expectedTags );
+ $revision->setText( "dummy edit" );
+
+ $importer = new ImportableOldRevisionImporter(
+ true,
+ new NullLogger(),
+ $services->getDBLoadBalancer()
+ );
+ $result = $importer->import( $revision );
+ $this->assertTrue( $result );
+
+ $page = WikiPage::factory( $title );
+ $tags = ChangeTags::getTags(
+ $services->getDBLoadBalancer()->getConnection( DB_MASTER ),
+ null,
+ $page->getLatest()
+ );
+ $this->assertSame( $expectedTags, $tags );
+ }
+}