Skip to content

Commit e3ba973

Browse files
committed
Fix: rename class to follow new standard
1 parent 5ae2e14 commit e3ba973

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

packages/playground/data-liberation/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
require_once __DIR__ . '/src/entity-readers/WP_Entity_Reader.php';
6363
require_once __DIR__ . '/src/entity-readers/WP_HTML_Entity_Reader.php';
6464
require_once __DIR__ . '/src/entity-readers/WP_WXR_Entity_Reader.php';
65+
require_once __DIR__ . '/src/entity-readers/WP_WXR_Sorted_Entity_Reader.php';
6566
require_once __DIR__ . '/src/entity-readers/WP_Directory_Tree_Entity_Reader.php';
6667

6768
require_once __DIR__ . '/src/xml-api/WP_XML_Decoder.php';

packages/playground/data-liberation/plugin.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ function () {
7676

7777
function data_liberation_activate() {
7878
// Create tables and option.
79-
WP_WXR_Sorted_Reader::create_or_update_db();
80-
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Reader::DB_VERSION );
79+
WP_WXR_Sorted_Entity_Reader::create_or_update_db();
80+
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Entity_Reader::DB_VERSION );
8181
}
8282

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

8686
function data_liberation_deactivate() {
8787
// Flush away all data.
88-
WP_WXR_Sorted_Reader::delete_db();
88+
WP_WXR_Sorted_Entity_Reader::delete_db();
8989

9090
// Delete the option.
9191
delete_option( 'data_liberation_db_version' );
@@ -97,10 +97,10 @@ function data_liberation_deactivate() {
9797
register_deactivation_hook( __FILE__, 'data_liberation_deactivate' );
9898

9999
function data_liberation_load() {
100-
if ( WP_WXR_Sorted_Reader::DB_VERSION !== (int) get_site_option( 'data_liberation_db_version' ) ) {
100+
if ( WP_WXR_Sorted_Entity_Reader::DB_VERSION !== (int) get_site_option( 'data_liberation_db_version' ) ) {
101101
// Update the database with dbDelta, if needed in the future.
102-
WP_WXR_Sorted_Reader::create_or_update_db();
103-
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Reader::DB_VERSION );
102+
WP_WXR_Sorted_Entity_Reader::create_or_update_db();
103+
update_option( 'data_liberation_db_version', WP_WXR_Sorted_Entity_Reader::DB_VERSION );
104104
}
105105
}
106106

packages/playground/data-liberation/src/entity-readers/WP_WXR_Sorted_Reader.php renamed to packages/playground/data-liberation/src/entity-readers/WP_WXR_Sorted_Entity_Reader.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
use WordPress\ByteReader\WP_Byte_Reader;
44

55
/**
6-
* Data Liberation API: WP_WXR_Sorted_Reader class
6+
* Data Liberation API: WP_WXR_Sorted_Entity_Reader class
77
*
88
* The topological sorted WXR reader class. This is an extension of the
9-
* WP_WXR_Reader class that emits entities sorted topologically so that the
10-
* parents are always emitted before the children.
9+
* WP_WXR_Entity_Reader class that emits entities sorted topologically so that
10+
* the parents are always emitted before the children.
1111
*
1212
* ## Implementation
1313
*
1414
* We create a custom table that contains the IDs and the new IDs created in the
1515
* target system sorted in the parent-child order.
1616
*
17-
* This class extends the WP_WXR_Reader class and overrides the read_next_entity
17+
* This class extends the WP_WXR_Entity_Reader class and overrides the
18+
* read_next_entity function to emit the entities in the correct order.
1819
*
1920
* List of entities Sort order
2021
* entity 1 entity 1 3
@@ -40,7 +41,7 @@
4041
*
4142
* @since WP_VERSION
4243
*/
43-
class WP_WXR_Sorted_Reader extends WP_WXR_Reader {
44+
class WP_WXR_Sorted_Entity_Reader extends WP_WXR_Entity_Reader {
4445

4546
/**
4647
* The base name of the table used to store the IDs, the new IDs and the
@@ -92,10 +93,10 @@ class WP_WXR_Sorted_Reader extends WP_WXR_Reader {
9293
* @param mixed $cursor The cursor.
9394
* @param array $options The options.
9495
*
95-
* @return WP_WXR_Sorted_Reader The reader.
96+
* @return WP_WXR_Sorted_Entity_Reader The reader.
9697
*/
9798
public static function create( WP_Byte_Reader $upstream = null, $cursor = null, $options = array() ) {
98-
// Initialize WP_WXR_Reader.
99+
// Initialize WP_WXR_Entity_Reader.
99100
$reader = parent::create( $upstream, $cursor, $options );
100101

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

451452
/**
452453
* A new entity has been imported, so we need to update the mapped ID to be
453-
* reused later in the WP_WXR_Sorted_Reader::get_entity() calls. New entities
454+
* reused later in the WP_WXR_Sorted_Entity_Reader::get_entity() calls. New entities
454455
* imported need to refer to the existing parent entities and their newly
455456
* generated IDs.
456457
*

packages/playground/data-liberation/src/import/WP_Stream_Importer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public static function create_for_wxr_file( $wxr_path, $options = array(), $curs
133133
return static::create(
134134
function ( $cursor = null ) use ( $wxr_path, $options ) {
135135
if ( isset( $options['topo_sorted'] ) && false === $options['topo_sorted'] ) {
136-
return WP_WXR_Entity_Reader::create( new WP_File_Reader( $wxr_path ), $cursor );
136+
return WP_WXR_Entity_Reader::create( WP_File_Reader::create( $wxr_path ), $cursor );
137137
}
138138

139-
return WP_WXR_Sorted_Reader::create( new WP_File_Reader( $wxr_path ), $cursor, $options );
139+
return WP_WXR_Sorted_Entity_Reader::create( WP_File_Reader::create( $wxr_path ), $cursor, $options );
140140
},
141141
$options,
142142
$cursor
@@ -150,7 +150,7 @@ function ( $cursor = null ) use ( $wxr_url, $options ) {
150150
return WP_WXR_Entity_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor );
151151
}
152152

153-
return WP_WXR_Sorted_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor, $options );
153+
return WP_WXR_Sorted_Entity_Reader::create( new WP_Remote_File_Reader( $wxr_url ), $cursor, $options );
154154
},
155155
$options,
156156
$cursor

packages/playground/data-liberation/tests/WPWXRSortedReaderTests.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_once __DIR__ . '/PlaygroundTestCase.php';
44

55
/**
6-
* Tests for the WP_WXR_Sorted_Reader class.
6+
* Tests for the WP_WXR_Sorted_Entity_Reader class.
77
*/
88
class WPWXRSortedReaderTests extends PlaygroundTestCase {
99

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

1313
$this->delete_all_data();
1414
wp_cache_flush();
15-
WP_WXR_Sorted_Reader::create_or_update_db();
15+
WP_WXR_Sorted_Entity_Reader::create_or_update_db();
1616
}
1717

1818
protected function tearDown(): void {
19-
WP_WXR_Sorted_Reader::delete_db();
19+
WP_WXR_Sorted_Entity_Reader::delete_db();
2020

2121
parent::tearDown();
2222
}
@@ -34,17 +34,17 @@ public function test_count_entities_of_small_import() {
3434
}
3535

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

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

4343
foreach ( $types as $entity_type => $expected_count ) {
4444
$count = $wpdb->get_var(
4545
$wpdb->prepare(
4646
'SELECT COUNT(*) FROM %i WHERE entity_type = %d',
47-
WP_WXR_Sorted_Reader::get_table_name(),
47+
WP_WXR_Sorted_Entity_Reader::get_table_name(),
4848
$entity_type
4949
)
5050
);
@@ -86,7 +86,7 @@ public function test_small_import() {
8686
$this->assertEquals( $expected_pages, array_map( $map_id, $public_pages ) );
8787

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

9292
// All elements should be deleted.
@@ -234,11 +234,11 @@ public function test_unsorted_categories() {
234234
}
235235

236236
private function small_import_counts() {
237-
$types = WP_WXR_Sorted_Reader::ENTITY_TYPES;
237+
$types = WP_WXR_Sorted_Entity_Reader::ENTITY_TYPES;
238238

239239
return array(
240-
$types['category'] => 30,
241-
$types['post'] => 11,
240+
$types['category'] => 33,
241+
$types['post'] => 13,
242242
$types['term'] => 0,
243243
);
244244
}

0 commit comments

Comments
 (0)