Skip to content

Commit

Permalink
Fix: rename class to follow new standard
Browse files Browse the repository at this point in the history
  • Loading branch information
zaerl committed Jan 8, 2025
1 parent 5ae2e14 commit e3ba973
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/playground/data-liberation/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
require_once __DIR__ . '/src/entity-readers/WP_Entity_Reader.php';
require_once __DIR__ . '/src/entity-readers/WP_HTML_Entity_Reader.php';
require_once __DIR__ . '/src/entity-readers/WP_WXR_Entity_Reader.php';
require_once __DIR__ . '/src/entity-readers/WP_WXR_Sorted_Entity_Reader.php';
require_once __DIR__ . '/src/entity-readers/WP_Directory_Tree_Entity_Reader.php';

require_once __DIR__ . '/src/xml-api/WP_XML_Decoder.php';
Expand Down
12 changes: 6 additions & 6 deletions packages/playground/data-liberation/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ function () {

function data_liberation_activate() {
// Create tables and option.
WP_WXR_Sorted_Reader::create_or_update_db();
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Reader::DB_VERSION );
WP_WXR_Sorted_Entity_Reader::create_or_update_db();
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Entity_Reader::DB_VERSION );
}

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

function data_liberation_deactivate() {
// Flush away all data.
WP_WXR_Sorted_Reader::delete_db();
WP_WXR_Sorted_Entity_Reader::delete_db();

// Delete the option.
delete_option( 'data_liberation_db_version' );
Expand All @@ -97,10 +97,10 @@ function data_liberation_deactivate() {
register_deactivation_hook( __FILE__, 'data_liberation_deactivate' );

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
use WordPress\ByteReader\WP_Byte_Reader;

/**
* Data Liberation API: WP_WXR_Sorted_Reader class
* Data Liberation API: WP_WXR_Sorted_Entity_Reader class
*
* The topological sorted WXR reader class. This is an extension of the
* WP_WXR_Reader class that emits entities sorted topologically so that the
* parents are always emitted before the children.
* WP_WXR_Entity_Reader class that emits entities sorted topologically so that
* the parents are always emitted before the children.
*
* ## Implementation
*
* We create a custom table that contains the IDs and the new IDs created in the
* target system sorted in the parent-child order.
*
* This class extends the WP_WXR_Reader class and overrides the read_next_entity
* This class extends the WP_WXR_Entity_Reader class and overrides the
* read_next_entity function to emit the entities in the correct order.
*
* List of entities Sort order
* entity 1 entity 1 3
Expand All @@ -40,7 +41,7 @@
*
* @since WP_VERSION
*/
class WP_WXR_Sorted_Reader extends WP_WXR_Reader {
class WP_WXR_Sorted_Entity_Reader extends WP_WXR_Entity_Reader {

/**
* The base name of the table used to store the IDs, the new IDs and the
Expand Down Expand Up @@ -92,10 +93,10 @@ class WP_WXR_Sorted_Reader extends WP_WXR_Reader {
* @param mixed $cursor The cursor.
* @param array $options The options.
*
* @return WP_WXR_Sorted_Reader The reader.
* @return WP_WXR_Sorted_Entity_Reader The reader.
*/
public static function create( WP_Byte_Reader $upstream = null, $cursor = null, $options = array() ) {
// Initialize WP_WXR_Reader.
// Initialize WP_WXR_Entity_Reader.
$reader = parent::create( $upstream, $cursor, $options );

if ( array_key_exists( 'post_id', $options ) ) {
Expand Down Expand Up @@ -450,7 +451,7 @@ public function add_next_entity( $entity = null ) {

/**
* A new entity has been imported, so we need to update the mapped ID to be
* reused later in the WP_WXR_Sorted_Reader::get_entity() calls. New entities
* reused later in the WP_WXR_Sorted_Entity_Reader::get_entity() calls. New entities
* imported need to refer to the existing parent entities and their newly
* generated IDs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public static function create_for_wxr_file( $wxr_path, $options = array(), $curs
return static::create(
function ( $cursor = null ) use ( $wxr_path, $options ) {
if ( isset( $options['topo_sorted'] ) && false === $options['topo_sorted'] ) {
return WP_WXR_Entity_Reader::create( new WP_File_Reader( $wxr_path ), $cursor );
return WP_WXR_Entity_Reader::create( WP_File_Reader::create( $wxr_path ), $cursor );
}

return WP_WXR_Sorted_Reader::create( new WP_File_Reader( $wxr_path ), $cursor, $options );
return WP_WXR_Sorted_Entity_Reader::create( WP_File_Reader::create( $wxr_path ), $cursor, $options );
},
$options,
$cursor
Expand All @@ -150,7 +150,7 @@ function ( $cursor = null ) use ( $wxr_url, $options ) {
return WP_WXR_Entity_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor );
}

return WP_WXR_Sorted_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor, $options );
return WP_WXR_Sorted_Entity_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor, $options );
},
$options,
$cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . '/PlaygroundTestCase.php';

/**
* Tests for the WP_WXR_Sorted_Reader class.
* Tests for the WP_WXR_Sorted_Entity_Reader class.
*/
class WPWXRSortedReaderTests extends PlaygroundTestCase {

Expand All @@ -12,11 +12,11 @@ protected function setUp(): void {

$this->delete_all_data();
wp_cache_flush();
WP_WXR_Sorted_Reader::create_or_update_db();
WP_WXR_Sorted_Entity_Reader::create_or_update_db();
}

protected function tearDown(): void {
WP_WXR_Sorted_Reader::delete_db();
WP_WXR_Sorted_Entity_Reader::delete_db();

parent::tearDown();
}
Expand All @@ -34,17 +34,17 @@ public function test_count_entities_of_small_import() {
}

$count = $wpdb->get_var(
$wpdb->prepare( 'SELECT COUNT(*) FROM %i', WP_WXR_Sorted_Reader::get_table_name() )
$wpdb->prepare( 'SELECT COUNT(*) FROM %i', WP_WXR_Sorted_Entity_Reader::get_table_name() )
);

$this->assertEquals( 47, (int) $count );
$this->assertEquals( 65, (int) $count );
$types = $this->small_import_counts();

foreach ( $types as $entity_type => $expected_count ) {
$count = $wpdb->get_var(
$wpdb->prepare(
'SELECT COUNT(*) FROM %i WHERE entity_type = %d',
WP_WXR_Sorted_Reader::get_table_name(),
WP_WXR_Sorted_Entity_Reader::get_table_name(),
$entity_type
)
);
Expand Down Expand Up @@ -86,7 +86,7 @@ public function test_small_import() {
$this->assertEquals( $expected_pages, array_map( $map_id, $public_pages ) );

$count = $wpdb->get_var(
$wpdb->prepare( 'SELECT COUNT(*) FROM %i', WP_WXR_Sorted_Reader::get_table_name() )
$wpdb->prepare( 'SELECT COUNT(*) FROM %i', WP_WXR_Sorted_Entity_Reader::get_table_name() )
);

// All elements should be deleted.
Expand Down Expand Up @@ -234,11 +234,11 @@ public function test_unsorted_categories() {
}

private function small_import_counts() {
$types = WP_WXR_Sorted_Reader::ENTITY_TYPES;
$types = WP_WXR_Sorted_Entity_Reader::ENTITY_TYPES;

return array(
$types['category'] => 30,
$types['post'] => 11,
$types['category'] => 33,
$types['post'] => 13,
$types['term'] => 0,
);
}
Expand Down

0 comments on commit e3ba973

Please sign in to comment.