fixing previously unchecked response code for sending; switched any code that earlier deleted database entries to done;
Peter Molnar hello@petermolnar.eu
Sun, 13 Mar 2016 22:09:17 +0000
3 files changed,
56 insertions(+),
6 deletions(-)
M
receiver.php
→
receiver.php
@@ -328,7 +328,7 @@
// too many retries, drop this mention and walk away if ( $received->tries >= static::retry() ) { static::debug( " this mention was tried earlier and failed too many times, drop it", 5); - static::queue_del ( $received->id ); + //static::queue_del ( $received->id ); continue; }@@ -349,7 +349,8 @@ $ins = static::insert_comment ( $post_id, $received->source, $received->target, $remote, $c );
if ( true === $ins ) { static::debug( " duplicate (or something similar): this queue element has to be ignored; deleting queue entry", 5); - static::queue_del ( $received->id ); + //static::queue_del ( $received->id ); + static::queue_done ( $received->id ); } elseif ( is_numeric( $ins ) ) { static::debug( " all went well, we have a comment id: {$ins}, deleting queue entry", 5);
M
sender.php
→
sender.php
@@ -217,8 +217,8 @@
// try sending $s = static::send( $send->source, $send->target ); - if ( is_wp_error ( $s ) ) { - static::debug( " sending failed: " . $s->get_error_message(), 5); + if ( false == $s ) { + static::debug( " sending failed: ", 5); } else { static::debug( " sending succeeded!", 5);@@ -274,7 +274,25 @@
// use the response to do something usefull // do_action( 'webmention_post_send', $response, $source, $target, $post_ID ); - return $response; + if ( is_wp_error( $response ) ) { + static::debug( "sending failed: " . $response->get_error_message(), 4); + return false; + } + + if ( ! is_array( $response ) || ! isset( $response['response'] ) || ! isset( $response['response']['code'] ) || empty( $response['response']['code'] ) ) { + static::debug( "sending failed: the response is empty", 4); + return false; + } + + if ( 200 <= $response['response']['code'] && 300 > $response['response']['code'] ) { + static::debug( "sending succeeded: ${$response['response']['code']}, message: {$response['response']['message']}", 5); + return true; + } + else { + static::debug( "wrong response code, this sending probably failed: {$response['response']['code']}, message: {$response['response']['message']}", 4); + return false; + } + } return false;
M
wp-webmention-again.php
→
wp-webmention-again.php
@@ -332,6 +332,8 @@ catch (Exception $e) {
static::debug('Something went wrong: ' . $e->getMessage(), 4); } + //do_action ( 'wp_webmention_again_done', $id ); + return $req; }@@ -354,7 +356,7 @@
global $wpdb; $dbname = $wpdb->prefix . static::tablename; - $q = $wpdb->prepare( "SELECT * FROM `{$dbname}` WHERE `direction` = '%s' and `status` = 0 LIMIT %d;", $direction, $limit ); + $q = $wpdb->prepare( "SELECT * FROM `{$dbname}` WHERE `direction` = '%s' and `status` = 0 and `tries` < ". static::retry() ." LIMIT %d;", $direction, $limit ); try { $req = $wpdb->get_results( $q );@@ -404,6 +406,35 @@ return true;
return false; } + + /** + * get a single webmention based on id + * + * @param int $id webmention id + * + * @return array of webmention + * + * + public static function webmention_get ( $id ) { + + global $wpdb; + $dbname = $wpdb->prefix . static::tablename; + + $q = $wpdb->prepare( "SELECT * FROM `{$dbname}` WHERE `id` = '%d'", $id ); + + try { + $req = $wpdb->get_results( $q ); + } + catch (Exception $e) { + static::debug('Something went wrong: ' . $e->getMessage(), 4); + } + + if ( ! empty ( $req ) ) + return $req; + + return false; + } + */ /** * extended wp_remote_get with debugging