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 105 commits
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: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Press_Sync\\api\\": "includes/api"
},
"classmap": [
"includes/"
]
Expand Down
129 changes: 129 additions & 0 deletions includes/api/route/AbstractRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
namespace Press_Sync\api\route;

/**
* Class AbstractRoute
*
* @package Press_Sync\api\route
* @since NEXT
*/
abstract class AbstractRoute extends \WP_REST_Controller {
/**
* Namespace for this route.
*
* @var string
* @since NEXT
*/
protected $namespace = 'press-sync/v1';

/**
* Routes to register with the WP API.
*
* This should be an array where the keys are endpoints to be registered
* under {$this->namspace}/{$this->rest_base}/{$endpoint}. If you don't
* specify an endpoint, the route will point to the REST base.
*
* Example:
* ```
* $this->namespace = 'filemanager/v1';
* $this->rest_base = 'files';
* $this->routes[] = [ 'callback'=> [ $this, 'get_info' ] ];
* $this->routes['list'] = [ 'callback' => [ $this, 'list_items'] ];
* ```
* This registers two endpoints:
* - /filemanager/v1/files/ - This uses the get_info callback.
* - /filemanager/v1/files/list - This uses the list_items callback.
*
* Any configuration items that can be passed to the third parameter of `register_rest_route`
* may be used in the configuration array for each endpoint.
*
* @since NEXT
* @var array
*/
protected $routes = array();

/**
* Concrete classes should implement methods that hook into WordPress's rest_api_init event, at minimum.
*
* @since NEXT
* @return void
*/
abstract public function register_hooks();

/**
* Validate the supplied press_sync_key by the sending site.
* Target site can't receive data without a valid press_sync_key.
*
* @since 0.1.0
* @return bool
*/
public function validate_sync_key() {
// @TODO Check for valid nonce.
$press_sync_key_from_remote = '';

if ( isset( $_REQUEST['press_sync_key'] ) ) {
$press_sync_key_from_remote = filter_var( $_REQUEST['press_sync_key'], FILTER_SANITIZE_STRING );
}

$press_sync_key = get_option( 'ps_key' );

return $press_sync_key && ( $press_sync_key === $press_sync_key_from_remote );
}

/**
* Registers routes to the WP API.
*
* @since NEXT
*/
public function register_routes() {
$defaults = array(
'methods' => array( 'GET' ),
'callback' => '__return_false',
'permission_callback' => array( $this, 'validate_sync_key' ),
'args' => array(
'press_sync_key' => array(
'required' => true,
),
),
);


foreach ( $this->routes as $endpoint => $route_config ) {
$config = wp_parse_args( $route_config, $defaults );

if ( is_numeric( $endpoint ) ) {
$endpoint = '';
}

register_rest_route(
$this->namespace,
"{$this->rest_base}/{$endpoint}",
$config
);
}
}

/**
* Get remote data from an API request.
*
* @since NEXT
*
* @param string $request The requested datapoint.
*
* @return array
*/
public function get_data( $request ) {
$request = ltrim( $request, '/' );
$url = \Press_Sync\API::get_remote_url( '', "{$this->rest_base}/{$request}", [
'request' => $request,
] );

$response = \Press_Sync\API::get_remote_response( $url );

if ( empty( $response['body']['success'] ) ) {
return [];
}

return $response['body']['data'];
}
}
9 changes: 9 additions & 0 deletions includes/api/route/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Press_Sync\api\route;


class Status
{

}
9 changes: 9 additions & 0 deletions includes/api/route/Sync.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Press_Sync\api\route;


class Sync
{

}
57 changes: 57 additions & 0 deletions includes/api/route/Validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace Press_Sync\api\route;

use Press_Sync\api\route\validation\Post;
use Press_Sync\api\route\validation\User;
use Press_Sync\api\route\validation\Taxonomy;

/**
* Class Validation
*
* @package Press_Sync\api\route
*/
class Validation extends \WP_REST_Controller {
/**
* The endpoint for the validator.
*
* This should be set in your extending class and will make the API
* request route something like /press-sync/v1/{$route}/{$endpoint}.
*
* @since NEXT
* @var string
*/
protected static $endpoint;

/**
* @var
*/
protected $routes = array(
User::class,
Taxonomy::class,
Post::class,
);

/**
* Validation constructor.
*/
public function __construct() {
$this->rest_base = 'validation';
}

/**
* Registers API endpoints for the extending class.
*
* This registers an API endpoint at /namespace/route/endpoint/ based on the extending
* class's properties. The class should implement a static public method called
* get_api_response that can parse the request parameters and return the desired data.
*
* @since NEXT
*/
public function register_routes() {
foreach ( $this->routes as $route ) {
/* @var AbstractRoute $class */
$class = new $route();
$class->register_hooks();
}
}
}
79 changes: 79 additions & 0 deletions includes/api/route/validation/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
namespace Press_Sync\api\route\validation;

use Press_Sync\api\route\AbstractRoute;

/**
* Class Post
*
* @package Press_Sync\api\route\validation
* @since NEXT
*/
class Post extends AbstractRoute {
/**
* @var \Press_Sync\validation\Post
*
* @since NEXT
*/
protected $data_source;

/**
* Post constructor.
*
* @since NEXT
*/
public function __construct() {
$this->rest_base = 'validation/post';
$this->data_source = new \Press_Sync\validation\Post();
$this->routes = array(
'count' => array(
'callback' => array( $this->data_source, 'get_count' ),
),
'sample' => array(
'callback' => array( $this, 'get_sample' ),
'args' => array(
'type' => array( 'required' => true ),
'count' => array( 'required' => false ),
'ids' => array( 'required' => false ),
'press_sync_key' => array( 'required' => true ),
),
),
);
}

/**
* Register hooks for Post validation.
*
* @since NEXT
*/
public function register_hooks() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}

/**
* Get a sample of post data.
*
* @param \WP_REST_Request $request
*
* @return array
*/
public function get_sample( \WP_REST_Request $request ) {
$params = array(
'count' => $request->get_param( 'count' ),
'ids' => $request->get_param( 'ids' ),
'type' => $request->get_param( 'type' ),
);

if ( $params['count'] ) {
$callback = "get_sample_{$params['type']}_data";
return $this->data_source->{$callback}( $params['count'] );
}

if ( $params['ids'] ) {
$callback = "get_comparison_{$params['type']}";
return $this->data_source->{$callback}( $params['ids'] );
}

return [];
}
}
67 changes: 67 additions & 0 deletions includes/api/route/validation/Taxonomy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
namespace Press_Sync\api\route\validation;

use Press_Sync\api\route\AbstractRoute;

/**
* Class Taxonomy
*
* @package Press_Sync\api\route\validation
* @since NEXT
*/
class Taxonomy extends AbstractRoute {
/**
* Data source for the API.
*
* @var \Press_Sync\validation\Taxonomy
* @since NEXT
*/
protected $data_source;

/**
* Taxonomy validation constructor.
*
* @since NEXT
*/
public function __construct() {
$this->rest_base = 'validation/taxonomy';
$this->data_source = new \Press_Sync\validation\Taxonomy();
$this->routes = array(
'count' => array(
'callback' => array( $this->data_source, 'get_count' ),
),
'sample' => array(
'callback' => array( $this, 'get_sample' ),
'args' => array(
'type' => array( 'required' => true ),
),
),
);
}

/**
* Register hooks for Taxonomy validation.
*
* @since NEXT
*/
public function register_hooks() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}

/**
* Get sample taxonomy data.
*
* @param \WP_REST_Request $request The API request.
*
* @return array|\WP_Error
*/
public function get_sample( \WP_REST_Request $request ) {
$type = filter_var( $request->get_param( 'type' ), FILTER_SANITIZE_STRING );

if ( 'meta' === $type ) {
return $this->data_source->get_sample_meta();
}

return new \WP_Error( 'taxonomy_type_not_found', 'Invalid type parameter.', array( 'status' => 404 ) );
}
}
Loading