Skip to content

Commit

Permalink
Merge pull request #169 from Codeinwp/minor-fixes
Browse files Browse the repository at this point in the history
Fix issue with common hashtags using post content.
Fix issue with add service when an account was removed from the list.
Fix issue with cron lag between shares
Improve disable state for pro services.
Fix exclude posts inconsistency. 
Fix incomplete UTM tags on certain shortners. 
Fix refresh queue on start sharing. 
Fix freezing message in frontend when the sharing is happening. 
Fix Facebook limits regarding the number of accounts fetched. 
Fix compatibility with PRO version regarding sharing on LinkedIn.
  • Loading branch information
selul authored May 4, 2018
2 parents a442a6c + 792e7f8 commit 162a8fe
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
10 changes: 3 additions & 7 deletions includes/admin/abstract/class-rop-url-shortner-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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 );
Expand Down
26 changes: 14 additions & 12 deletions includes/admin/class-rop-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
}
Expand Down
59 changes: 32 additions & 27 deletions includes/admin/helpers/class-rop-cron-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
);

Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}

Expand All @@ -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 ) );
}

Expand Down Expand Up @@ -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();
}
}
6 changes: 1 addition & 5 deletions includes/admin/models/class-rop-settings-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
6 changes: 3 additions & 3 deletions languages/tweet-old-post.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 162a8fe

Please sign in to comment.