-- ------------------------------------------
--- Friendica 2019.09-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1319
+-- Friendica 2019.09-rc (Dalmatian Bellflower)
+-- DB_UPDATE_VERSION 1321
-- ------------------------------------------
+--
+-- TABLE 2fa_app_specific_password
+--
+CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
+ `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
+ `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
+ `description` varchar(255) COMMENT 'Description of the usage of the password',
+ `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
+ `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
+ `last_used` datetime COMMENT 'Datetime the password was last used',
+ PRIMARY KEY(`id`),
+ INDEX `uid_description` (`uid`,`description`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
+
--
-- TABLE 2fa_recovery_codes
--
`inform` mediumtext COMMENT 'Additional receivers of the linked item',
`queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
`queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
+ `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
`activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
`dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
`legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
/**
* Defers the current worker entry
+ * @return boolean had the entry been deferred?
*/
public static function defer()
{
if (empty(BaseObject::getApp()->queue)) {
- return;
+ return false;
}
$queue = BaseObject::getApp()->queue;
if ($new_retrial > $max_level) {
Logger::info('The task exceeded the maximum retry count', ['id' => $id, 'max_level' => $max_level, 'retrial' => $new_retrial]);
- return;
+ return false;
}
// Calculate the delay until the next trial
DBA::update('workerqueue', $fields, ['id' => $id]);
self::$db_duration += (microtime(true) - $stamp);
self::$db_duration_write += (microtime(true) - $stamp);
+
+ return true;
}
/**
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
'event-summary', 'event-desc', 'event-location', 'event-type',
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
- 'delivery_queue_count', 'delivery_queue_done'
+ 'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
];
// Field list that is used to deliver items via the protocols
// New delivery fields with virtual field name in item fields
'queue_count' => 'delivery_queue_count',
'queue_done' => 'delivery_queue_done',
+ 'queue_failed' => 'delivery_queue_failed',
];
const ACTIVITYPUB = 1;
return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id);
}
+ /**
+ * Increments the queue_failed for the given item ID.
+ *
+ * Avoids racing condition between multiple delivery threads.
+ *
+ * @param integer $item_id
+ * @return bool
+ * @throws \Exception
+ */
+ public static function incrementQueueFailed($item_id)
+ {
+ return DBA::e('UPDATE `item-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `iid` = ?', $item_id);
+ }
+
/**
* Insert a new item delivery data entry
*
'return' => ($a->cmd) ? bin2hex($a->cmd) : '',
'delivery' => [
'queue_count' => $item['delivery_queue_count'],
- 'queue_done' => $item['delivery_queue_done'],
+ 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
'notifier_pending' => L10n::t('Notifier task is pending'),
'delivery_pending' => L10n::t('Delivery to remote servers is pending'),
'delivery_underway' => L10n::t('Delivery to remote servers is underway'),
}
}
- if (!$success) {
- Worker::defer();
+ if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
+ ItemDeliveryData::incrementQueueFailed($target_id);
}
}
}
Model\Contact::markForArchival($contact);
Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
- Worker::defer();
+ if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+ }
}
}
if (empty($contact['contact-type']) || ($contact['contact-type'] != Model\Contact::TYPE_RELAY)) {
Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
// defer message for redelivery
- Worker::defer();
+ if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+ }
} elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA);
}
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1320);
+ define('DB_UPDATE_VERSION', 1321);
}
return [
"inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
"queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
"queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
+ "queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
"activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
"dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
"legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],