-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
18a7606
commit 8a33f39
Showing
22 changed files
with
2,570 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.