Skip to content

Commit

Permalink
see #607: fix codeclimate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyan0v committed Sep 6, 2017
2 parents 4ebacbb + 5a56a2a commit 99fd51f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Expand Up @@ -22,6 +22,8 @@ engines:
enabled: false
WordPress VIP PostsPerPage posts_per_page_posts_per_page:
enabled: false
WordPress VIP RestrictedFunctions wp_remote_get_wp_remote_get:
enabled: false
fixme:
enabled: false

Expand Down
5 changes: 1 addition & 4 deletions src/includes/class-wordlift-autocomplete-adapter.php
Expand Up @@ -48,10 +48,7 @@ public function __construct( $autocomplete_service ) {
* @since 3.15.0
*/
public function wl_autocomplete() {
if (
! empty( $_REQUEST['_wpnonce'] ) &&
! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wordlift_autocomplete' )
) {
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wordlift_autocomplete' ) ) {
wp_send_json_error( array(
'message' => 'Nonce field doens\'t match'
) );
Expand Down
41 changes: 41 additions & 0 deletions src/includes/class-wordlift-batch-analysis-adapter.php
Expand Up @@ -35,6 +35,11 @@ public function __construct( $batch_analysis_service ) {

}

/**
* Submit all the auto selected posts, i.e. non annotated posts.
*
* @since 3.14.2
*/
public function submit_auto_selected_posts() {

if ( ! isset( $_REQUEST['link'] ) ) {
Expand All @@ -51,6 +56,32 @@ public function submit_auto_selected_posts() {

}

/**
* Submit all posts for analysis.
*
* @since 3.14.5
*/
public function submit_all_posts() {

if ( ! isset( $_REQUEST['link'] ) ) {
wp_die( 'The `link` parameter is required.' );
}

$count = $this->batch_analysis_service->submit_all_posts( $_REQUEST['link'] );

// Clear any buffer.
ob_clean();

// Send the response.
wp_send_json_success( array( 'count' => $count ) );

}

/**
* Submit the specified post for batch analysis.
*
* @since 3.14.2
*/
public function submit() {

if ( ! isset( $_REQUEST['link'] ) || ! isset( $_REQUEST['post'] ) ) {
Expand All @@ -67,6 +98,11 @@ public function submit() {

}

/**
* Cancel the batch analysis for the specified post.
*
* @since 3.14.0
*/
public function cancel() {

if ( ! isset( $_REQUEST['post'] ) ) {
Expand All @@ -83,6 +119,11 @@ public function cancel() {

}

/**
* Clear warnings for the specified post.
*
* @since 3.14.0
*/
public function clear_warning() {

if ( ! isset( $_REQUEST['post'] ) ) {
Expand Down
25 changes: 25 additions & 0 deletions src/includes/class-wordlift-batch-analysis-service.php
Expand Up @@ -259,6 +259,31 @@ public function submit_auto_selected_posts( $link ) {
return $count / 3;
}

/**
* Submit all posts for analysis.
*
* @since 3.14.5
*
* @param string $link The link setting.
*
* @return false|int The number of submitted {@link WP_Post}s or false on
* error.
*/
public function submit_all_posts( $link ) {
global $wpdb;

// Submit the posts/pages and return the number of affected results.
// We're using a SQL query here because we could have potentially
// thousands of rows.
$count = $wpdb->query( $this->get_sql( $link ) );

// Request Batch Analysis (the operation is handled asynchronously).
do_action( 'wl_batch_analysis_request' );

// Divide the count by 3 to get the number of posts/pages queued.
return $count / 3;
}

/**
* Submit the provided list of {@link WP_Post}s' ids for Batch Analysis.
*
Expand Down
1 change: 1 addition & 0 deletions src/includes/class-wordlift.php
Expand Up @@ -1326,6 +1326,7 @@ private function define_admin_hooks() {
/** Adapters. */
$this->loader->add_filter( 'mce_external_plugins', $this->tinymce_adapter, 'mce_external_plugins', 10, 1 );
$this->loader->add_action( 'wp_ajax_wl_batch_analysis_submit_auto_selected_posts', $this->batch_analysis_adapter, 'submit_auto_selected_posts', 10 );
$this->loader->add_action( 'wp_ajax_wl_batch_analysis_submit_all_posts', $this->batch_analysis_adapter, 'submit_all_posts', 10 );
$this->loader->add_action( 'wp_ajax_wl_batch_analysis_submit', $this->batch_analysis_adapter, 'submit', 10 );
$this->loader->add_action( 'wp_ajax_wl_batch_analysis_cancel', $this->batch_analysis_adapter, 'cancel', 10 );
$this->loader->add_action( 'wp_ajax_wl_batch_analysis_clear_warning', $this->batch_analysis_adapter, 'clear_warning', 10 );
Expand Down
5 changes: 4 additions & 1 deletion src/readme.txt
Expand Up @@ -137,8 +137,11 @@ You can open your datasets to the public, attaching to it a free or a commercial

== Changelog ==

= 3.14.5 (2017-08-31) =
* Enhancement: [#606](https://github.com/insideout10/wordlift-plugin/issues/606): Batch Analysis on all posts.

= 3.14.4 (2017-08-30) =
* Enhancement: [#527](https://github.com/insideout10/wordlift-plugin/issues/527): Error fetching angular-animate.min.js.
* Fix: [#527](https://github.com/insideout10/wordlift-plugin/issues/527): Error fetching angular-animate.min.js.

= 3.14.3 (2017-08-10) =
* Enhancement: [#603](https://github.com/insideout10/wordlift-plugin/issues/603): Rebuild the relations table.
Expand Down

0 comments on commit 99fd51f

Please sign in to comment.