diff --git a/receiver.php b/receiver.php index dc72bf8..d7bf936 100644 --- a/receiver.php +++ b/receiver.php @@ -328,7 +328,7 @@ class WP_Webmention_Again_Receiver extends WP_Webmention_Again { // 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 @@ class WP_Webmention_Again_Receiver extends WP_Webmention_Again { 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); diff --git a/sender.php b/sender.php index a2cdc92..ecf5cdb 100644 --- a/sender.php +++ b/sender.php @@ -217,8 +217,8 @@ class WP_Webmention_Again_Sender extends WP_Webmention_Again { // 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 @@ class WP_Webmention_Again_Sender extends WP_Webmention_Again { // 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; diff --git a/wp-webmention-again.php b/wp-webmention-again.php index f14b1aa..c11e951 100644 --- a/wp-webmention-again.php +++ b/wp-webmention-again.php @@ -332,6 +332,8 @@ class WP_Webmention_Again { static::debug('Something went wrong: ' . $e->getMessage(), 4); } + //do_action ( 'wp_webmention_again_done', $id ); + return $req; } @@ -354,7 +356,7 @@ class WP_Webmention_Again { 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 ); @@ -405,6 +407,35 @@ class WP_Webmention_Again { 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 *