From 08abf65f7b325020ea52512c61afa82d99079e76 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 9 Apr 2018 21:34:23 +0000 Subject: [PATCH] Old database functions had been replaced in the workers --- src/Worker/Delivery.php | 6 ++---- src/Worker/DiscoverPoCo.php | 13 +++++++------ src/Worker/Notifier.php | 4 ++-- src/Worker/PubSubPublish.php | 10 ++++------ src/Worker/Queue.php | 2 +- src/Worker/TagUpdate.php | 18 ++++++++---------- 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 523bde4db..88085357a 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -208,7 +208,7 @@ class Delivery { $atom = DFRN::mail($item, $owner); } elseif ($fsuggest) { $atom = DFRN::fsuggest($item, $owner); - q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id'])); + dba::delete('fsuggest', ['id' => $item['id']]); } elseif ($relocate) { $atom = DFRN::relocate($owner, $uid); } elseif ($followup) { @@ -290,9 +290,7 @@ class Delivery { if ($x && count($x)) { $write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false); if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) { - q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d", - intval($x[0]['id']) - ); + dba::update('contact', ['writable' => true], ['id' => $x[0]['id']]); $x[0]['writable'] = 1; } diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index a82fa1208..f0335bc8e 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -13,6 +13,7 @@ use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use dba; class DiscoverPoCo { /// @todo Clean up this mess of a parameter hell and split it in several classes @@ -158,8 +159,8 @@ class DiscoverPoCo { $urlparts = parse_url($user["url"]); if (!isset($urlparts["scheme"])) { - q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'", - dbesc(NETWORK_PHANTOM), dbesc(normalise_link($user["url"]))); + dba::update('gcontact', ['network' => NETWORK_PHANTOM], + ['nurl' => normalise_link($user["url"])]); continue; } @@ -171,8 +172,8 @@ class DiscoverPoCo { "identi.ca" => NETWORK_PUMPIO, "alpha.app.net" => NETWORK_APPNET]; - q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'", - dbesc($networks[$urlparts["host"]]), dbesc(normalise_link($user["url"]))); + dba::update('gcontact', ['network' => $networks[$urlparts["host"]]], + ['nurl' => normalise_link($user["url"])]); continue; } @@ -194,8 +195,8 @@ class DiscoverPoCo { return; } } else { - q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", - dbesc(DateTimeFormat::utcNow()), dbesc(normalise_link($user["url"]))); + dba::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()], + ['nurl' => normalise_link($user["url"])]); } // Quit the loop after 3 minutes diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 49fd5e318..e4e720236 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -541,8 +541,8 @@ class Notifier { if ($push_notify) { // Set push flag for PuSH subscribers to this topic, // they will be notified in queue.php - q("UPDATE `push_subscriber` SET `push` = 1 ". - "WHERE `nickname` = '%s' AND `push` = 0", dbesc($owner['nickname'])); + $condition = ['push' => false, 'nickname' => $owner['nickname']]; + dba::update('push_subscriber', ['push' => true], $condition); logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG); diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index 03608bea6..de26eab9c 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -12,6 +12,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Protocol\OStatus; use Friendica\Util\Network; +use dba; require_once 'include/items.php'; @@ -76,9 +77,8 @@ class PubSubPublish { logger('successfully pushed to '.$rr['callback_url']); // set last_update to the "created" date of the last item, and reset push=0 - q("UPDATE `push_subscriber` SET `push` = 0, last_update = '%s' WHERE id = %d", - dbesc($last_update), - intval($rr['id'])); + $fields = ['push' => 0, 'last_update' => $last_update]; + dba::update('push_subscriber', $fields, ['id' => $rr['id']]); } else { logger('error when pushing to '.$rr['callback_url'].' HTTP: '.$ret); @@ -90,9 +90,7 @@ class PubSubPublish { if ($new_push > 30) // OK, let's give up $new_push = 0; - q("UPDATE `push_subscriber` SET `push` = %d WHERE id = %d", - $new_push, - intval($rr['id'])); + dba::update('push_subscriber', ['push' => $new_push], ['id' => $rr['id']]); } } } diff --git a/src/Worker/Queue.php b/src/Worker/Queue.php index 46f6faf95..5c8942db2 100644 --- a/src/Worker/Queue.php +++ b/src/Worker/Queue.php @@ -36,7 +36,7 @@ class Queue // Handling the pubsubhubbub requests Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'PubSubPublish'); - $r = dba::inArray(dba::p("SELECT `id` FROM `queue` WHERE `next` < UTC_TIMESTAMP()")); + $r = dba::inArray(dba::p("SELECT `id` FROM `queue` WHERE `next` < UTC_TIMESTAMP() ORDER BY `batch`, `cid`")); Addon::callHooks('queue_predeliver', $r); diff --git a/src/Worker/TagUpdate.php b/src/Worker/TagUpdate.php index fa3079731..f6a141ad6 100644 --- a/src/Worker/TagUpdate.php +++ b/src/Worker/TagUpdate.php @@ -2,6 +2,8 @@ namespace Friendica\Worker; +use dba; + class TagUpdate { public static function execute() @@ -13,18 +15,14 @@ class TagUpdate if ($message['uid'] == 0) { $global = true; - q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'", - intval(TERM_OBJ_POST), dbesc($message['guid'])); + dba::update('term', ['global' => true], ['otype' => TERM_OBJ_POST, 'guid' => $message['guid']]); } else { - $isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'", - intval(TERM_OBJ_POST), dbesc($message['guid'])); - - $global = (count($isglobal) > 0); + $global = (dba::count('term', ['uid' => 0, 'otype' => TERM_OBJ_POST, 'guid' => $message['guid']]) > 0); } - q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s', `global` = %d WHERE `otype` = %d AND `oid` = %d", - dbesc($message['guid']), dbesc($message['created']), dbesc($message['received']), - intval($global), intval(TERM_OBJ_POST), intval($message['oid'])); + $fields = ['guid' => $message['guid'], 'created' => $message['created'], + 'received' => $message['received'], 'global' => $global]; + dba::update('term', $fields, ['otype' => TERM_OBJ_POST, 'oid' => $message['oid']]); } dba::close($messages); @@ -33,7 +31,7 @@ class TagUpdate logger('fetched messages: ' . dba::num_rows($messages)); while ($message = dba::fetch(messages)) { - q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message['guid'])); + dba::update('item', ['global' => true], ['guid' => $message['guid']]); } dba::close($messages);