Permalink
Browse files

Add conversion infrastructure with LQT API source.

Modular design means we can read from the DB, an XML dump, a talk page
or any other potential source of historical Flow posts if we want to.

Supports history and headers.

Bug: 45088
Change-Id: If41b45908542bf68521c0b31388ca6d33fd818f0
  • Loading branch information...
werdnum authored and ebernhardson committed Jan 15, 2014
1 parent 18a7606 commit 8a33f396a3b5de4cb22868657deadda7106f7c65
View
@@ -160,6 +160,39 @@
$wgAutoloadClasses['Flow\\Formatter\\TopicListFormatter'] = __DIR__ . '/includes/Formatter/TopicListFormatter.php';
$wgAutoloadClasses['Flow\\Formatter\\TopicListQuery'] = __DIR__ . '/includes/Formatter/TopicListQuery.php';
$wgAutoloadClasses['Flow\\Formatter\\TopicRow'] = __DIR__ . '/includes/Formatter/TopicRow.php';
$wgAutoloadClasses['Flow\\Import\\FileImportSourceStore'] = __DIR__ . '/includes/Import/ImportSourceStore.php';
$wgAutoloadClasses['Flow\\Import\\HistoricalUIDGenerator'] = __DIR__ . '/includes/Import/Importer.php';
$wgAutoloadClasses['Flow\\Import\\IImportHeader'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IImportObject'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IImportPost'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IImportSource'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IImportSummary'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IImportTopic'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IObjectRevision'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\IRevisionableObject'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\ImportException'] = __DIR__ . '/includes/Import/ImportSource.php';
$wgAutoloadClasses['Flow\\Import\\ImportSourceStore'] = __DIR__ . '/includes/Import/ImportSourceStore.php';
$wgAutoloadClasses['Flow\\Import\\Importer'] = __DIR__ . '/includes/Import/Importer.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ApiBackend'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Source.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ApiNotFoundException'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Source.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\CachedApiData'] = __DIR__ . '/includes/Import/LiquidThreadsApi/CachedData.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\CachedData'] = __DIR__ . '/includes/Import/LiquidThreadsApi/CachedData.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\CachedPageData'] = __DIR__ . '/includes/Import/LiquidThreadsApi/CachedData.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\CachedThreadData'] = __DIR__ . '/includes/Import/LiquidThreadsApi/CachedData.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportHeader'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportPost'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportRevision'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportSource'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Source.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportSummary'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ImportTopic'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\PageRevisionedObject'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Objects.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\ReplyIterator'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Iterators.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\RevisionIterator'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Iterators.php';
$wgAutoloadClasses['Flow\\Import\\LiquidThreadsApi\\TopicIterator'] = __DIR__ . '/includes/Import/LiquidThreadsApi/Iterators.php';
$wgAutoloadClasses['Flow\\Import\\NullImportSourceStore'] = __DIR__ . '/includes/Import/ImportSourceStore.php';
$wgAutoloadClasses['Flow\\Import\\PageImportState'] = __DIR__ . '/includes/Import/Importer.php';
$wgAutoloadClasses['Flow\\Import\\TalkpageImportOperation'] = __DIR__ . '/includes/Import/Importer.php';
$wgAutoloadClasses['Flow\\Import\\TopicImportState'] = __DIR__ . '/includes/Import/Importer.php';
$wgAutoloadClasses['Flow\\LinksTableUpdater'] = __DIR__ . '/includes/LinksTableUpdater.php';
$wgAutoloadClasses['Flow\\Log\\Formatter'] = __DIR__ . '/includes/Log/Formatter.php';
$wgAutoloadClasses['Flow\\Log\\Logger'] = __DIR__ . '/includes/Log/Logger.php';
@@ -252,8 +285,17 @@
$wgAutoloadClasses['Flow\\Tests\\FlowTestCase'] = __DIR__ . '/tests/phpunit/FlowTestCase.php';
$wgAutoloadClasses['Flow\\Tests\\Formatter\\FormatterTest'] = __DIR__ . '/tests/phpunit/Formatter/FormatterTest.php';
$wgAutoloadClasses['Flow\\Tests\\HookTest'] = __DIR__ . '/tests/phpunit/HookTest.php';
$wgAutoloadClasses['Flow\\Tests\\Import\\HistoricalUIDGeneratorTest'] = __DIR__ . '/tests/phpunit/Import/HistoricalUIDGeneratorTest.php';
$wgAutoloadClasses['Flow\\Tests\\Import\\PageImportStateTest'] = __DIR__ . '/tests/phpunit/Import/PageImportStateTest.php';
$wgAutoloadClasses['Flow\\Tests\\Import\\TalkpageImportOperationTest'] = __DIR__ . '/tests/phpunit/Import/TalkpageImportOperationTest.php';
$wgAutoloadClasses['Flow\\Tests\\LinksTableTest'] = __DIR__ . '/tests/phpunit/LinksTableTest.php';
$wgAutoloadClasses['Flow\\Tests\\LocalBufferedBagOStuffTest'] = __DIR__ . '/tests/phpunit/Data/BagOStuff/LocalBufferedBagOStuffTest.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportHeader'] = __DIR__ . '/tests/phpunit/Mock/MockImportHeader.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportPost'] = __DIR__ . '/tests/phpunit/Mock/MockImportPost.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportRevision'] = __DIR__ . '/tests/phpunit/Mock/MockImportRevision.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportSource'] = __DIR__ . '/tests/phpunit/Mock/MockImportSource.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportSummary'] = __DIR__ . '/tests/phpunit/Mock/MockImportSummary.php';
$wgAutoloadClasses['Flow\\Tests\\Mock\\MockImportTopic'] = __DIR__ . '/tests/phpunit/Mock/MockImportTopic.php';
$wgAutoloadClasses['Flow\\Tests\\Model\\PostRevisionTest'] = __DIR__ . '/tests/phpunit/Model/PostRevisionTest.php';
$wgAutoloadClasses['Flow\\Tests\\Model\\UUIDTest'] = __DIR__ . '/tests/phpunit/Model/UUIDTest.php';
$wgAutoloadClasses['Flow\\Tests\\Model\\UserTupleTest'] = __DIR__ . '/tests/phpunit/Model/UserTupleTest.php';
@@ -282,4 +324,5 @@
$wgAutoloadClasses['Flow\\WorkflowLoaderFactory'] = __DIR__ . '/includes/WorkflowLoaderFactory.php';
$wgAutoloadClasses['LCRun3'] = __DIR__ . '/vendor/lightncandy.php';
$wgAutoloadClasses['LightnCandy'] = __DIR__ . '/vendor/lightncandy.php';
$wgAutoloadClasses['MaintenanceDebugLogger'] = __DIR__ . '/maintenance/MaintenanceDebugLogger.php';
$wgAutoloadClasses['Pimple'] = __DIR__ . '/vendor/Pimple.php';
View
@@ -1130,4 +1130,13 @@ function( array $row, $obj = null ) use( $c ) {
);
} );
$c['importer'] = $c->share( function( $c ) {
return new Flow\Import\Importer(
$c['storage'],
$c['factory.loader.workflow'],
$c['memcache.buffered'],
$c['db.factory']
);
} );
return $c;
@@ -0,0 +1,75 @@
<?php
namespace Flow\Import;
use Flow\Exception\FlowException;
use Iterator;
interface IImportSource {
/**
* @return Iterator<IImportTopic>
*/
function getTopics();
/**
* @return IImportHeader|null
*/
function getHeader();
}
interface IImportObject {
/**
* Returns an opaque string that uniquely identifies this object.
* Should uniquely identify this particular object every time it is imported.
*
* @return string
*/
function getObjectKey();
}
interface IRevisionableObject extends IImportObject {
/**
* @return Iterator<IObjectRevision>
*/
function getRevisions();
}
interface IObjectRevision extends IImportObject {
/**
* @return string Wikitext
*/
function getText();
/**
* @return string Timestamp compatible with wfTimestamp()
*/
function getTimestamp();
/**
* @return string The name of the user who created this summary.
*/
function getAuthor();
}
interface IImportPost extends IRevisionableObject {
/**
* @return Iterator<IImportPost>
*/
function getReplies();
}
interface IImportTopic extends IImportPost {
/**
* @return IImportSummary|null The summary, if any, for a topic
*/
function getTopicSummary();
}
interface IImportHeader extends IRevisionableObject {
}
interface IImportSummary extends IRevisionableObject {
}
class ImportException extends FlowException {
}
@@ -0,0 +1,84 @@
<?php
namespace Flow\Import;
use Flow\Model\UUID;
interface ImportSourceStore {
/**
* Stores the association between an object and where it was imported from.
*
* @param UUID $objectId ID for the object that was imported.
* @param string $importSourceKey String returned from IImportObject::getObjectKey()
*/
function setAssociation( UUID $objectId, $importSourceKey );
/**
* @param string $importSourceKey String returned from IImportObject::getObjectKey()
* @return UUID|boolean UUID of the imported object if appropriate; otherwise, false.
*/
function getImportedId( $importSourceKey );
/**
* Save any associations that have been added
*/
function save();
/**
* Forged any recorded associations since last save
*/
function rollback();
}
class FileImportSourceStore implements ImportSourceStore {
/** @var string **/
protected $filename;
/** @var array */
protected $data;
public function __construct( $filename ) {
$this->filename = $filename;
$this->load();
}
protected function load() {
if ( file_exists( $this->filename ) ) {
$this->data = json_decode( file_get_contents( $this->filename ), true );
} else {
$this->data = array();
}
}
public function save() {
file_put_contents( $this->filename, json_encode( $this->data ) );
}
public function rollback() {
$this->load();
}
public function setAssociation( UUID $objectId, $importSourceKey ) {
$this->data[$importSourceKey] = $objectId->getAlphadecimal();
}
public function getImportedId( $importSourceKey ) {
return isset( $this->data[$importSourceKey] )
? UUID::create( $this->data[$importSourceKey] )
: false;
}
}
class NullImportSourceStore implements ImportSourceStore {
public function setAssociation( UUID $objectId, $importSourceKey ) {
}
public function getImportedId( $importSourceKey ) {
return false;
}
public function save() {
}
public function rollback() {
}
}
Oops, something went wrong.

0 comments on commit 8a33f39

Please sign in to comment.