diff --git a/includes/admin/abstract/class-rop-url-shortner-abstract.php b/includes/admin/abstract/class-rop-url-shortner-abstract.php index e207496b8..1f48f342c 100644 --- a/includes/admin/abstract/class-rop-url-shortner-abstract.php +++ b/includes/admin/abstract/class-rop-url-shortner-abstract.php @@ -170,7 +170,7 @@ protected final function callAPI( $url, $props = array(), $params = array(), $he } if ( $props && isset( $props['method'] ) ) { if ( in_array( $props['method'], array( 'post', 'put' ) ) ) { - curl_setopt( $conn, CURLOPT_POSTFIELDS, urldecode( http_build_query( $params ) ) ); + curl_setopt( $conn, CURLOPT_POSTFIELDS, $params ); } if ( $props['method'] === 'json' ) { curl_setopt( $conn, CURLOPT_POSTFIELDS, json_encode( $params ) ); @@ -183,13 +183,9 @@ protected final function callAPI( $url, $props = array(), $params = array(), $he $body = curl_exec( $conn ); $error = curl_getinfo( $conn, CURLINFO_HTTP_CODE ); } catch ( Exception $e ) { - $this->error->throw_exception( 'Exception ' . $e->getMessage() ); - } - if ( curl_errno( $conn ) ) { - var_dump( 'Error for request: ' . $url . ' : ' . curl_error( $conn ), 'error' ); - // self::addNotice("Error for request: " . $url . " : ". curl_error($conn), 'error'); - // self::writeDebug("curl_errno ".curl_error($conn)); + $this->error->throw_exception( 'Error', 'Exception ' . $e->getMessage() ); } + curl_close( $conn ); if ( $props && isset( $props['json'] ) && $props['json'] ) { $body = json_decode( $body, true ); diff --git a/includes/admin/class-rop-admin.php b/includes/admin/class-rop-admin.php index ab9c938c4..548983f08 100644 --- a/includes/admin/class-rop-admin.php +++ b/includes/admin/class-rop-admin.php @@ -242,21 +242,23 @@ public function rop_cron_job() { /** * Trigger share if we have an event in the past, and the timestamp of that event is in the last 15mins. */ - if ( $event['time'] <= Rop_Scheduler_Model::get_current_time() && ( Rop_Scheduler_Model::get_current_time() - $event['time'] ) < ( 15 * MINUTE_IN_SECONDS ) ) { + if ( $event['time'] <= Rop_Scheduler_Model::get_current_time() ) { $posts = $event['posts']; $queue->remove_from_queue( $event['time'], $account ); - $account_data = $services_model->find_account( $account ); - try { - $service = $service_factory->build( $account_data['service'] ); - $service->set_credentials( $account_data['credentials'] ); - foreach ( $posts as $post ) { - $post_data = $queue->prepare_post_object( $post, $account ); - $logger->info( 'Posting', array( 'extra' => $post_data ) ); - $service->share( $post_data, $account_data ); + if ( ( Rop_Scheduler_Model::get_current_time() - $event['time'] ) < ( 15 * MINUTE_IN_SECONDS ) ) { + $account_data = $services_model->find_account( $account ); + try { + $service = $service_factory->build( $account_data['service'] ); + $service->set_credentials( $account_data['credentials'] ); + foreach ( $posts as $post ) { + $post_data = $queue->prepare_post_object( $post, $account ); + $logger->info( 'Posting', array( 'extra' => $post_data ) ); + $service->share( $post_data, $account_data ); + } + } catch ( Exception $exception ) { + $error_message = sprintf( Rop_I18n::get_labels( 'accounts.service_error' ), $account_data['service'] ); + $logger->alert_error( $error_message . ' Error: ' . $exception->getTrace() ); } - } catch ( Exception $exception ) { - $error_message = sprintf( Rop_I18n::get_labels( 'accounts.service_error' ), $account_data['service'] ); - $logger->alert_error( $error_message . ' Error: ' . $exception->getTrace() ); } } } diff --git a/includes/admin/helpers/class-rop-cron-helper.php b/includes/admin/helpers/class-rop-cron-helper.php index 85d08217e..f7474caa2 100644 --- a/includes/admin/helpers/class-rop-cron-helper.php +++ b/includes/admin/helpers/class-rop-cron-helper.php @@ -35,7 +35,7 @@ class Rop_Cron_Helper { */ public static function rop_cron_schedules( $schedules ) { $schedules['5min'] = array( - 'interval' => 5 * 60, + 'interval' => 1 * 60, 'display' => Rop_I18n::get_labels( 'general.cron_interval' ), ); @@ -75,7 +75,9 @@ public function manage_cron( $request ) { */ public function create_cron( $first = true ) { if ( ! wp_next_scheduled( self::CRON_NAMESPACE ) ) { + if ( $first ) { + $this->fresh_start(); $settings = new Rop_Global_Settings(); $settings->update_start_time(); wp_schedule_single_event( time() + 30, self::CRON_NAMESPACE ); @@ -98,32 +100,7 @@ public function remove_cron() { if ( is_int( $timestamp ) ) { wp_clear_scheduled_hook( self::CRON_NAMESPACE ); } - /** - * Reset start time. - */ - $settings = new Rop_Global_Settings(); - $settings->reset_start_time(); - /** - * Reset timeline events. - */ - $scheduler = new Rop_Scheduler_Model(); - $scheduler->refresh_events(); - - /** - * Reset queue events. - */ - $scheduler = new Rop_Queue_Model(); - $scheduler->clear_queue(); - /** - * Clear buffer for all accounts. - */ - $selector = new Rop_Posts_Selector_Model(); - $selector->clear_buffer(); - // ** - // * Clear logs. - // */ - // $logger = new Rop_Logger(); - // $logger->clear_user_logs(); + $this->fresh_start(); return false; } @@ -133,6 +110,7 @@ public function remove_cron() { * @return bool Cron status. */ public function get_status() { + return is_int( wp_next_scheduled( self::CRON_NAMESPACE ) ); } @@ -224,4 +202,31 @@ private function convert_phpformat_to_js( $format ) { return $momentFormat; } + + /** + * Clear all queue related data. + */ + private function fresh_start() { + /** + * Reset start time. + */ + $settings = new Rop_Global_Settings(); + $settings->reset_start_time(); + /** + * Reset timeline events. + */ + $scheduler = new Rop_Scheduler_Model(); + $scheduler->refresh_events(); + + /** + * Reset queue events. + */ + $scheduler = new Rop_Queue_Model(); + $scheduler->clear_queue(); + /** + * Clear buffer for all accounts. + */ + $selector = new Rop_Posts_Selector_Model(); + $selector->clear_buffer(); + } } diff --git a/includes/admin/models/class-rop-settings-model.php b/includes/admin/models/class-rop-settings-model.php index 182402bb3..198734935 100644 --- a/includes/admin/models/class-rop-settings-model.php +++ b/includes/admin/models/class-rop-settings-model.php @@ -272,16 +272,12 @@ public function add_excluded_posts( $post_id ) { } $posts = $this->get_selected_posts(); $check = wp_list_pluck( $posts, 'value' ); - if ( is_numeric( $post_id ) ) { $post_id = intval( $post_id ); $post_id = array( - array( - 'value' => $post_id, - ), + $post_id, ); } - $post_id = array_map( function ( $value ) { return array( diff --git a/includes/class-rop-i18n.php b/includes/class-rop-i18n.php index a2aef61dd..defe59727 100644 --- a/includes/class-rop-i18n.php +++ b/includes/class-rop-i18n.php @@ -262,7 +262,7 @@ public static function get_labels( $key = '' ) { 'multiselect_not_found' => __( 'Nothing found matching', 'tweet-old-post' ), 'next_share' => __( 'Next share', 'tweet-old-post' ), 'sharing_now' => __( 'Sharing...', 'tweet-old-post' ), - 'cron_interval' => __( 'Once every 5 minutes', 'tweet-old-post' ), + 'cron_interval' => __( 'Once every 1 min', 'tweet-old-post' ), ), 'post_editor' => array( 'remove_message' => __( 'Remove Custom Message', 'tweet-old-post' ), diff --git a/languages/tweet-old-post.pot b/languages/tweet-old-post.pot index c62504e85..619fe9144 100644 --- a/languages/tweet-old-post.pot +++ b/languages/tweet-old-post.pot @@ -2,9 +2,9 @@ # This file is distributed under the no. msgid "" msgstr "" -"Project-Id-Version: Revive Old Posts (Former Tweet Old Post) 8.0.3\n" +"Project-Id-Version: Revive Old Posts (Former Tweet Old Post) 8.0.5\n" "Report-Msgid-Bugs-To: https://github.com/Codeinwp/tweet-old-post/issues\n" -"POT-Creation-Date: 2018-05-02 14:28:00+00:00\n" +"POT-Creation-Date: 2018-05-04 09:15:16+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -677,7 +677,7 @@ msgid "Sharing..." msgstr "" #: includes/class-rop-i18n.php:265 -msgid "Once every 5 minutes" +msgid "Once every 1 min" msgstr "" #: includes/class-rop-i18n.php:268