Merge pull request #496 from zeroadam/bugFix-Twitter

Bug fix for Addons using queue_fn
pull/498/head
Hypolite Petovan 2018-01-22 18:02:44 -05:00 committed by GitHub
commit 3ae390c6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 24 deletions

View File

@ -12,6 +12,7 @@ require_once("addon/diaspora/Diaspora_Connection.php");
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Queue;
function diaspora_install() { function diaspora_install() {
Addon::registerHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); Addon::registerHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local');
@ -53,8 +54,6 @@ function diaspora_queue_hook(&$a,&$b) {
if(! count($qi)) if(! count($qi))
return; return;
require_once('include/queue_fn.php');
foreach($qi as $x) { foreach($qi as $x) {
if($x['network'] !== NETWORK_DIASPORA2) if($x['network'] !== NETWORK_DIASPORA2)
continue; continue;
@ -94,20 +93,21 @@ function diaspora_queue_hook(&$a,&$b) {
$conn->provider = $hostname; $conn->provider = $hostname;
$conn->postStatusMessage($post, $aspect); $conn->postStatusMessage($post, $aspect);
logger('diaspora_queue: send '.$userdata['uid'].' success', LOGGER_DEBUG); logger('diaspora_queue: send '.$userdata['uid'].' success', LOGGER_DEBUG);
$success = true; $success = true;
remove_queue_item($x['id']); Queue::removeItem($x['id']);
} catch (Exception $e) { } catch (Exception $e) {
logger("diaspora_queue: Send ".$userdata['uid']." failed: ".$e->getMessage(), LOGGER_DEBUG); logger("diaspora_queue: Send ".$userdata['uid']." failed: ".$e->getMessage(), LOGGER_DEBUG);
} }
} else } else {
logger('diaspora_queue: send '.$userdata['uid'].' missing username or password', LOGGER_DEBUG); logger('diaspora_queue: send '.$userdata['uid'].' missing username or password', LOGGER_DEBUG);
}
if (!$success) { if (!$success) {
logger('diaspora_queue: delayed'); logger('diaspora_queue: delayed');
update_queue_time($x['id']); Queue::updateTime($x['id']);
} }
} }
} }
@ -366,8 +366,8 @@ function diaspora_send(&$a,&$b) {
$a->contact = $r[0]["id"]; $a->contact = $r[0]["id"];
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $body]); $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $body]);
require_once('include/queue_fn.php');
add_to_queue($a->contact,NETWORK_DIASPORA2,$s); Queue::add($a->contact, NETWORK_DIASPORA2, $s);
notice(t('Diaspora post failed. Queued for retry.').EOL); notice(t('Diaspora post failed. Queued for retry.').EOL);
} }
} }

View File

@ -14,6 +14,7 @@ use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Queue;
require 'addon/pumpio/oauth/http.php'; require 'addon/pumpio/oauth/http.php';
require 'addon/pumpio/oauth/oauth_client.php'; require 'addon/pumpio/oauth/oauth_client.php';
@ -551,11 +552,10 @@ function pumpio_send(&$a,&$b) {
$a->contact = $r[0]["id"]; $a->contact = $r[0]["id"];
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]); $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]);
require_once('include/queue_fn.php');
add_to_queue($a->contact,NETWORK_PUMPIO,$s); Queue::add($a->contact, NETWORK_PUMPIO, $s);
notice(t('Pump.io post failed. Queued for retry.').EOL); notice(t('Pump.io post failed. Queued for retry.').EOL);
} }
} }
} }
@ -628,8 +628,8 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") {
$a->contact = $r[0]["id"]; $a->contact = $r[0]["id"];
$s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]); $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]);
require_once('include/queue_fn.php');
add_to_queue($a->contact,NETWORK_PUMPIO,$s); Queue::add($a->contact, NETWORK_PUMPIO, $s);
notice(t('Pump.io like failed. Queued for retry.').EOL); notice(t('Pump.io like failed. Queued for retry.').EOL);
} }
} }
@ -1433,8 +1433,6 @@ function pumpio_queue_hook(&$a,&$b) {
if(! count($qi)) if(! count($qi))
return; return;
require_once('include/queue_fn.php');
foreach($qi as $x) { foreach($qi as $x) {
if($x['network'] !== NETWORK_PUMPIO) if($x['network'] !== NETWORK_PUMPIO)
continue; continue;
@ -1494,7 +1492,7 @@ function pumpio_queue_hook(&$a,&$b) {
intval($z['item']) intval($z['item'])
); );
} }
remove_queue_item($x['id']); Queue::removeItem($x['id']);
} else } else
logger('pumpio_queue: send '.$username.': '.$url.' general error: ' . print_r($user,true)); logger('pumpio_queue: send '.$username.': '.$url.' general error: ' . print_r($user,true));
} else } else
@ -1502,7 +1500,7 @@ function pumpio_queue_hook(&$a,&$b) {
if (!$success) { if (!$success) {
logger('pumpio_queue: delayed'); logger('pumpio_queue: delayed');
update_queue_time($x['id']); Queue::updateTime($x['id']);
} }
} }
} }

View File

@ -69,6 +69,7 @@ use Friendica\Core\Worker;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Queue;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
@ -627,8 +628,9 @@ function twitter_post_hook(App $a, &$b)
} }
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]); $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]);
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_TWITTER, $s); Queue::add($a->contact, NETWORK_TWITTER, $s);
notice(t('Twitter post failed. Queued for retry.') . EOL); notice(t('Twitter post failed. Queued for retry.') . EOL);
} elseif ($iscomment) { } elseif ($iscomment) {
logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']);
@ -925,8 +927,6 @@ function twitter_queue_hook(App $a, &$b)
return; return;
} }
require_once 'include/queue_fn.php';
foreach ($qi as $x) { foreach ($qi as $x) {
if ($x['network'] !== NETWORK_TWITTER) { if ($x['network'] !== NETWORK_TWITTER) {
continue; continue;
@ -972,7 +972,7 @@ function twitter_queue_hook(App $a, &$b)
logger('twitter_queue: Send to Twitter failed: "' . print_r($result->errors, true) . '"'); logger('twitter_queue: Send to Twitter failed: "' . print_r($result->errors, true) . '"');
} else { } else {
$success = true; $success = true;
remove_queue_item($x['id']); Queue::removeItem($x['id']);
} }
} else { } else {
logger("twitter_queue: Error getting tokens for user " . $user['uid']); logger("twitter_queue: Error getting tokens for user " . $user['uid']);
@ -980,7 +980,7 @@ function twitter_queue_hook(App $a, &$b)
if (!$success) { if (!$success) {
logger('twitter_queue: delayed'); logger('twitter_queue: delayed');
update_queue_time($x['id']); Queue::updateTime($x['id']);
} }
} }
} }