Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket/aotech 6694 data validation #46

Open
wants to merge 132 commits into
base: ticket/AOTECH-6694-data-validation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
d606137
Basic beginning for validation.
phatsk Jan 25, 2018
78e2e28
Stub out validation and result formatting in the Dashboard.
phatsk Jan 25, 2018
71cbbc5
Stub out validation tab for Dashboard.
phatsk Jan 25, 2018
bbb1740
Add Validators
phatsk Jan 25, 2018
197dfcf
Add main Validation class.
phatsk Jan 25, 2018
0aa26e4
Merge branch 'master' into ticket/AOTECH-6694-data-validation
phatsk Feb 1, 2018
2f9fb46
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:thema…
phatsk Feb 1, 2018
298fc8e
Make API namespace a constant.
phatsk Feb 5, 2018
fdb247b
Remove commented code.
phatsk Feb 5, 2018
4c5ca3b
Initial work on validation API responses.
phatsk Feb 5, 2018
4c5066f
Add base API validation class.
phatsk Feb 5, 2018
d931188
Flesh out initial validators
phatsk Feb 5, 2018
1a8611f
Use NAMESPACE constant in the API class.
phatsk Feb 5, 2018
8356c41
Move URL building and remote request methods to API class.
phatsk Feb 5, 2018
887a0c2
Properly address users without roles.
phatsk Feb 5, 2018
e0d55a0
Reverse logic of last sync check to be more logical.
phatsk Feb 5, 2018
fdc1e83
Add methods for getting local and destination data.
phatsk Feb 5, 2018
4e76f45
Move API-specific code to proper file. Actually use Validator_API cla…
phatsk Feb 5, 2018
a0a0c4d
Refactor file structure in prep for validation work
Feb 5, 2018
3e01efb
Add User model class and update User validation endpoint to access it.
Feb 5, 2018
31c79d3
Update User Validation endpoint constructor and other minor fixes.
Feb 5, 2018
e7e5ad8
Set up initial taxonomy validation based on work from AOTECH-6699 tic…
Feb 5, 2018
8aad00c
Sanitize press_sync_key value, update to-do to check for valid nonces.
Feb 6, 2018
824de03
Give the Taxonomy API validation class a data source property so it c…
Feb 6, 2018
5a48fff
Merge pull request #31 from jmichaelward/ticket/AOTECH-6713-taxonomy-…
phatsk Feb 6, 2018
48b54bb
Build out CLI scaffolding for Validation command.
Feb 6, 2018
7536579
Updates for validation endpoints
phatsk Feb 6, 2018
6c545d1
Testing out CLI integration with API service to request remote data.
Feb 6, 2018
15fa56d
First pass at sample CLI output for term counts.
Feb 6, 2018
5d79622
Add check for URL parameter on multisite.
Feb 6, 2018
6c60ab0
Add throws PHPDoc to taxonomies method.
Feb 6, 2018
9c3548f
Rearrange logic for press sync key validation.
phatsk Feb 6, 2018
4fb643d
Break some lines to make things cleaner.
phatsk Feb 6, 2018
51df232
Update user classes
phatsk Feb 6, 2018
2db04eb
Extract count methods into interface, update CLI command to match API…
Feb 6, 2018
b88371e
Initial scaffold of post validation.
Feb 6, 2018
7846d5b
Actually add post route to API.
Feb 6, 2018
103281a
Add initial comparison for post counts.
Feb 6, 2018
41d5e8f
Add options information to validate method.
Feb 7, 2018
8963bdd
Update comments in ValidationCommand class. Pass associative argument…
Feb 7, 2018
aa338ad
Work on outputting post data for local and remote sites.
Feb 7, 2018
95b6971
Refactor command setup for posts.
Feb 8, 2018
03a3368
Create TaxonomyValidator class and extend interface.
Feb 8, 2018
9e43eab
Restructure validation interfaces and change validation utility from …
Feb 8, 2018
2a34fc8
Class cleanup and documentation.
Feb 8, 2018
3c30788
Cleanup validators.
Feb 8, 2018
939f5f9
Add @since statements to Taxonomy model.
Feb 8, 2018
0c3ee9a
Refactor validators out of CLI client commands.
Feb 8, 2018
82c96e4
Add abstract validator to use compare method.
Feb 8, 2018
ce76df9
Merge pull request #37 from jmichaelward/ticket/AOTECH-6694-data-vali…
phatsk Feb 8, 2018
26c9697
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:thema…
phatsk Feb 8, 2018
09c73c8
Merge remote-tracking branch 'marcus/master' into ticket/AOTECH-6694-…
phatsk Feb 8, 2018
d8581f4
stub out user validation classes.
phatsk Feb 8, 2018
facace7
Update for user validation on CLI
phatsk Feb 8, 2018
ad22cbd
Add logic and output for taxonomy term post counts.
Feb 8, 2018
986adaf
Merge pull request #38 from jmichaelward/ticket/AOTECH-6713-taxonomy-…
phatsk Feb 9, 2018
e8a01cb
pass request args to API call.
phatsk Feb 9, 2018
df53951
Remove test count
phatsk Feb 9, 2018
82845ad
Slice out the proper user from the results.
phatsk Feb 9, 2018
2350385
Return base destination data.
phatsk Feb 9, 2018
560ff1b
Update API side of getting user samples.
phatsk Feb 9, 2018
55be9f7
Move match highlight args to validate method.
phatsk Feb 9, 2018
0808219
Remove line reset from subcommand.
phatsk Feb 9, 2018
60731dc
Document the find_sample_matches method.
phatsk Feb 9, 2018
9a7dcff
Add interface for output formatting.
phatsk Feb 9, 2018
f4ce4a6
Abstract CLI commands now implement a formatter.
phatsk Feb 9, 2018
19952c5
Refactor CLI User command.
phatsk Feb 9, 2018
54f8baf
Update User Validation model data formats.
phatsk Feb 9, 2018
589fc1a
Abstract method for getting outout formatting.'
phatsk Feb 9, 2018
09cf55d
Move diff comparison to abstract validator.
phatsk Feb 9, 2018
20efbd9
Consolidate and refactor the User Validator.
phatsk Feb 9, 2018
4c7f5ea
Merge branch 'feature/validation-enhancements' into ticket/AOTECH-669…
phatsk Feb 9, 2018
e855338
Implement colorization on post count validation tables.
Feb 9, 2018
b5ab6a4
Initial pass at sample post route setup.
Feb 12, 2018
2e4dc7c
Build out get_sample return data.
Feb 12, 2018
9d57dd7
Fix TaxonomySubcommand to pass TaxonomyValidator required arguments.
Feb 12, 2018
4441781
Fix output_comparison_statements methods to accommodate latest changes.
Feb 12, 2018
8b8259b
Add logic for retrieving comparison sample data from destination site.
Feb 12, 2018
5941433
Merge branch 'master' into ticket/AOTECH-6694-data-validation
Feb 12, 2018
e77ccd7
Update API to run meta query against post ids from source.
Feb 12, 2018
5fa6862
Add 'dumb' table to output for sample.
Feb 12, 2018
bd9dc08
Add temporary error message for differing post counts in sample.
Feb 12, 2018
56f7a00
Set up API callbacks for sample post terms.
Feb 12, 2018
15476eb
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:jmich…
Feb 12, 2018
d35459d
Remove superfluous variable assignment in get_sample method.
Feb 12, 2018
b1d27be
Remove superfluous method from Post validation API route.
Feb 12, 2018
24549fe
Refactor Post route to match Taxonomy and User.
Feb 13, 2018
cf6103a
Add logic for getting sample taxonomy term meta.
Feb 13, 2018
8ea30f2
Modify data structure in taxonomy term meta response.
Feb 13, 2018
d6b9b2c
Merge branch 'master' into ticket/AOTECH-6694-data-validation
Feb 14, 2018
a508d94
Refactor client output into separate classes.
Feb 14, 2018
344e31f
Add client output architecture to project, fix validation of posts, u…
Feb 14, 2018
e1fd739
Remove redundant line from API class.
Feb 14, 2018
4fe899e
Sort sample posts by ID and fix API endpoint error.
Feb 14, 2018
fdd0b96
Fix issue with mismatched sample post IDs getting compared.
Feb 14, 2018
69e0038
Revert to using post IDs for comparison.
Feb 14, 2018
b042713
Add a key to sample post comparison that indicates whether a post ID …
Feb 14, 2018
4690cd5
Update post model for returning formatted terms data.
Feb 15, 2018
529d432
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:jmich…
Feb 15, 2018
4c2d610
WIP on SampleTax output, update post taxonomy output to use same post…
Feb 15, 2018
c1848ec
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:jmich…
Feb 15, 2018
8b5df5a
WIP to normalize source and destination data counts.
Feb 15, 2018
4e877f1
Finish generalizing data normalization and comparison indexing.
Feb 15, 2018
42ea243
Add post taxonomy validation output for CLI.
Feb 15, 2018
9183625
Merge remote-tracking branch 'github/master' into ticket/AOTECH-6694-…
phatsk Feb 15, 2018
81061ac
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:thema…
Feb 15, 2018
2a2e8e4
Merge branch 'ticket/AOTECH-6694-data-validation' of github.com:jmich…
Feb 15, 2018
8a0e542
Move source_data and destination_data properties into the AbstractVal…
Feb 15, 2018
f717e34
Assign get_terms to variable before using in foreach.
Feb 15, 2018
baf01ee
Replace get_term_slugs helper method with wp_list_pluck.
Feb 15, 2018
9e87846
Assign get_terms to variable before use in foreach in another method …
Feb 15, 2018
dee6a76
WIP shifting taxonomy validation output responsibilities to rendering…
Feb 15, 2018
05aeecb
Continued WIP shift to moving display responsibilities to concrete im…
Feb 15, 2018
93d5b9d
Change call on taxonomy source data model to get_data from get_count.
Feb 15, 2018
3c73d31
Fix double-nested count array indices.
Feb 15, 2018
8f63cf3
Additional fixes in shift to moving output responsibility to concrete…
Feb 15, 2018
38d80af
Finish unstyled taxonomy count comparison table output.
Feb 15, 2018
ede2eaa
Finalized rendered comparision table in cli for taxonomy counts.
Feb 15, 2018
524df9b
Refine the count output a bit.
Feb 15, 2018
ecdfb0a
WIP refactoring post counts by term.
Feb 16, 2018
b45b87f
WIP setting up post_terms endpoint.
Feb 16, 2018
2b37021
Simply and randomize output for taxonomy term post count data in CLI.
Feb 16, 2018
698f145
Fix migration data in taxonomy post count table.
Feb 16, 2018
480f7f1
Give additional line spacing between tables.
Feb 16, 2018
1ed06cb
Clarify message before table output of sample taxonomy post counts.
Feb 16, 2018
26df553
Index arrays by term-taxonomy key instead of term_id, since they may …
Feb 16, 2018
907adb6
Add optional third parameter for colorizing output to allow for alter…
Feb 16, 2018
06a567a
Remove iconography from post count sample tables.
Feb 16, 2018
ebbdfbe
Replace emoji in validation count tables with colorized yes/no values.
Feb 16, 2018
18ae69d
Remove emoji from post sample table.
Feb 16, 2018
c6d8201
Replace emoji in sample post taxonomies table with yes/no values.
Feb 16, 2018
c50ea7e
Update array fields in PostSampleTax.php.
Feb 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions includes/client/cli/output/TaxonomyCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ private function output( $data, $message = '' ) {
$formatter = new Formatter( $assoc_args );
$formatter->display_items( $data, true );

// \WP_CLI\Utils\format_items( 'table', $data['term_count_by_taxonomy'], array( 'taxonomy_name', 'number_of_terms' ) );
// \WP_CLI\Utils\format_items( 'table', $data['post_terms'], array( 'taxonomy', 'term', 'post_count' ) );
// \WP_CLI::line( "Unique taxonomies: {$data['unique_taxonomies']}" );
}
Expand All @@ -48,7 +47,7 @@ private function output( $data, $message = '' ) {
* Prepare the data for rendering.
*
* @param array $data Data to prepare for rendering.
*
*Ø
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a weird character like a crossed-through zero.

* @return array
*/
public function prepare( array $data ) {
Expand Down
2 changes: 2 additions & 0 deletions includes/client/cli/output/TaxonomyRenderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static function create( string $key, array $data ) {
switch ( $key ) {
case 'count':
return new TaxonomyCount( $data );
case 'post_terms':
return new TaxonomySample( $data );
default:
return new \WP_Error( 'data_not_found', 'Taxonomy data provided for processing does not adhere to contract.' );
}
Expand Down
26 changes: 26 additions & 0 deletions includes/client/cli/output/TaxonomySample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Press_Sync\client\output;

/**
* Class TaxonomySample
*
* @package Press_Sync\client\output
*/
class TaxonomySample extends AbstractOutput {
/**
* Render data to the client.
*
* @since NEXT
* @return mixed
*/
public function render() {
$this->output( $this->data['comparison'], 'Post counts by taxonomy term:' );
}
/**
* @param array $data
* @param string $message
*/
public function output( array $data, $message = '' ) {
\WP_CLI\Utils\format_items( 'table', $data['term_count_by_taxonomy'], array( 'taxonomy_name', 'number_of_terms' ) );
}
}
40 changes: 12 additions & 28 deletions includes/validation/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Taxonomy implements CountInterface {
*/
public function get_data() {
return array(
'count' => $this->get_count(),
'count' => $this->get_count(),
'post_terms' => $this->get_post_count_by_taxonomy_term(),
);
}

Expand Down Expand Up @@ -67,43 +68,27 @@ public function get_post_count_by_taxonomy_term() {
$taxonomies = array();

foreach ( get_taxonomies() as $name => $taxonomy ) {
$taxonomies[ $name ] = array();
$taxonomy_terms = get_terms( array(
'taxonomy' => $taxonomy,
$term_query = new \WP_Term_Query( array(
'taxonomy' => $name,
'hide_empty' => false,
) );

foreach ( $taxonomy_terms as $term ) {
$query = new \WP_Query(
array(
'fields' => 'ids',
'post_type' => 'any',
'posts_per_page' => - 1,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
),
),
)
);

$taxonomies[ $name ][ $term->slug ] = count( $query->get_posts() );
$terms = $term_query->get_terms();

foreach ( $terms as $term ) {
$taxonomies[ $name ][ $term->slug ] = $term->count;

wp_reset_postdata();
}
}

$indexed_array = array();

foreach ( $taxonomies as $tax_name => $taxonomy ) {
foreach ( $taxonomies as $taxonomy_name => $taxonomy ) {
$indexed_array[ $taxonomy_name ] = array();

foreach ( $taxonomy as $term_name => $post_count ) {
$indexed_array[] = array(
'taxonomy' => $tax_name,
'term' => $term_name,
'post_count' => $post_count,
);
$indexed_array[ $taxonomy_name ][ $term_name ] = $post_count;
}
}

Expand All @@ -121,7 +106,6 @@ public function get_count() {
return array(
'unique_taxonomies' => $this->get_unique_taxonomy_count(),
'term_count_by_taxonomy' => $this->get_term_count_by_taxonomy(),
'post_terms' => $this->get_post_count_by_taxonomy_term(),
);
}

Expand Down
15 changes: 14 additions & 1 deletion includes/validators/TaxonomyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ public function get_source_data() {
* @since NEXT
*/
public function get_destination_data() {
$count = API::get_remote_data( 'validation/taxonomy/count' );

return array(
'count' => API::get_remote_data( 'validation/taxonomy/count' ),
'count' => array(
'unique_taxonomies' => $count['unique_taxonomies'],
'term_count_by_taxonomy' => $count['term_count_by_taxonomy'],
),
'post_terms' => $count['post_terms'],
);
}

Expand All @@ -63,6 +69,7 @@ public function get_destination_data() {
public function get_comparison_data( array $source, array $destination ) {
return array(
'count' => $this->compare_count( $source['count'], $destination['count'] ),
'post_terms' => $this->compare_post_terms( $source['post_terms'], $destination['post_terms'] ),
);
}

Expand Down Expand Up @@ -102,4 +109,10 @@ private function compare_count( $source, $destination ) {

return $data;
}

private function compare_post_terms( $source, $destination ) {
$data = array();

return $data;
}
}