Skip to content

Commit

Permalink
Add new sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
zaerl committed Jan 8, 2025
1 parent 787c224 commit b11fe9b
Show file tree
Hide file tree
Showing 13 changed files with 925 additions and 994 deletions.
2 changes: 1 addition & 1 deletion packages/playground/data-liberation/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<file>tests/WPXMLProcessorTests.php</file>
<file>tests/UrldecodeNTests.php</file>
<file>tests/WPStreamImporterTests.php</file>
<file>tests/WPTopologicalSorterTests.php</file>
<file>tests/WPWXRSortedReaderTests.php</file>
</testsuite>
</testsuites>
</phpunit>
23 changes: 13 additions & 10 deletions packages/playground/data-liberation/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,20 @@ function data_liberation_init() {
add_action( 'init', 'data_liberation_init' );

function data_liberation_activate() {
// Activate the topological sorter. Create tables and options.
WP_Topological_Sorter::activate();
update_option( WP_Topological_Sorter::OPTION_NAME, WP_Topological_Sorter::DB_VERSION );
// Create tables and option.
WP_WXR_Sorted_Reader::create_or_update_db();
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Reader::DB_VERSION );
}

// Run when the plugin is activated.
register_activation_hook( __FILE__, 'data_liberation_activate' );

function data_liberation_deactivate() {
// Deactivate the topological sorter. Flush away all data.
WP_Topological_Sorter::deactivate();
// Flush away all data.
WP_WXR_Sorted_Reader::delete_db();

// Delete the option.
delete_option( 'data_liberation_db_version' );

// @TODO: Cancel any active import sessions and cleanup other data.
}
Expand All @@ -83,10 +86,10 @@ function data_liberation_deactivate() {
register_deactivation_hook( __FILE__, 'data_liberation_deactivate' );

function data_liberation_load() {
if ( WP_Topological_Sorter::DB_VERSION !== (int) get_site_option( WP_Topological_Sorter::OPTION_NAME ) ) {
if ( WP_WXR_Sorted_Reader::DB_VERSION !== (int) get_site_option( 'data_liberation_db_version' ) ) {
// Update the database with dbDelta, if needed in the future.
WP_Topological_Sorter::activate();
update_option( WP_Topological_Sorter::OPTION_NAME, WP_Topological_Sorter::DB_VERSION );
WP_WXR_Sorted_Reader::create_or_update_db();
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Reader::DB_VERSION );
}
}

Expand Down Expand Up @@ -458,15 +461,15 @@ function data_liberation_create_importer( $import ) {
}
$importer = WP_Stream_Importer::create_for_wxr_file(
$wxr_path,
array(),
$import,
$import['cursor'] ?? null
);
break;

case 'wxr_url':
$importer = WP_Stream_Importer::create_for_wxr_url(
$import['wxr_url'],
array(),
$import,
$import['cursor'] ?? null
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class WP_WXR_Entity_Reader extends WP_Entity_Reader {
* @since WP_VERSION
* @var WP_XML_Processor
*/
private $xml;
protected $xml;

/**
* The name of the XML tag containing information about the WordPress entity
Expand Down Expand Up @@ -206,23 +206,23 @@ class WP_WXR_Entity_Reader extends WP_Entity_Reader {
* @since WP_VERSION
* @var int|null
*/
private $last_post_id = null;
protected $last_post_id = null;

/**
* The ID of the last processed comment.
*
* @since WP_VERSION
* @var int|null
*/
private $last_comment_id = null;
protected $last_comment_id = null;

/**
* The ID of the last processed term.
*
* @since WP_VERSION
* @var int|null
*/
private $last_term_id = null;
protected $last_term_id = null;

/**
* Buffer for accumulating text content between tags.
Expand Down Expand Up @@ -367,7 +367,7 @@ class WP_WXR_Entity_Reader extends WP_Entity_Reader {
),
);

public static function create( WP_Byte_Reader $upstream = null, $cursor = null ) {
public static function create( WP_Byte_Reader $upstream = null, $cursor = null, $options = array() ) {
$xml_cursor = null;
if ( null !== $cursor ) {
$cursor = json_decode( $cursor, true );
Expand All @@ -383,7 +383,7 @@ public static function create( WP_Byte_Reader $upstream = null, $cursor = null )
}

$xml = WP_XML_Processor::create_for_streaming( '', $xml_cursor );
$reader = new WP_WXR_Entity_Reader( $xml );
$reader = new static( $xml );
if ( null !== $cursor ) {
$reader->last_post_id = $cursor['last_post_id'];
$reader->last_comment_id = $cursor['last_comment_id'];
Expand Down Expand Up @@ -416,10 +416,6 @@ protected function __construct( WP_XML_Processor $xml ) {
$this->xml = $xml;
}

public function get_last_xml_byte_offset_outside_of_entity() {
return $this->last_xml_byte_offset_outside_of_entity;
}

public function get_reentrancy_cursor() {
/**
* @TODO: Instead of adjusting the XML cursor internals, adjust the get_reentrancy_cursor()
Expand Down Expand Up @@ -593,7 +589,7 @@ public function next_entity() {
*
* @return bool Whether another entity was found.
*/
private function read_next_entity() {
protected function read_next_entity() {
if ( $this->xml->is_finished() ) {
$this->after_entity();
return false;
Expand Down
Loading

0 comments on commit b11fe9b

Please sign in to comment.