aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2023-01-11 16:34:23 +0000
committerMario <mario@mariovavti.com>2023-01-11 16:34:23 +0000
commit16555b93bbe4ef69dbbce8085bb366134f8a5654 (patch)
treecf9364844857cef0c9e246eed7aa913a2a097ac1 /Zotlabs
parent2eb4f093be868ef6ce8372de0375b2e9a2685791 (diff)
downloadvolse-hubzilla-16555b93bbe4ef69dbbce8085bb366134f8a5654.tar.gz
volse-hubzilla-16555b93bbe4ef69dbbce8085bb366134f8a5654.tar.bz2
volse-hubzilla-16555b93bbe4ef69dbbce8085bb366134f8a5654.zip
fix race conditions when processing multiple choice polls
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/Activity.php28
1 files changed, 24 insertions, 4 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 8f4e0444c..4a14b1ba1 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2081,16 +2081,29 @@ class Activity {
}
- static function update_poll($item, $post) {
+ static function update_poll($item_id, $post) {
$multi = false;
$mid = $post['mid'];
$content = $post['title'];
+ if (!$item_id) {
+ return false;
+ }
+
+ dbq("START TRANSACTION");
+
+ $item = q("SELECT * FROM item WHERE id = %d FOR UPDATE",
+ intval($item_id)
+ );
+
if (!$item) {
+ dbq("COMMIT");
return false;
}
+ $item = $item[0];
+
$o = json_decode($item['obj'], true);
if ($o && array_key_exists('anyOf', $o)) {
$multi = true;
@@ -2162,16 +2175,23 @@ class Activity {
}
logger('updated_poll: ' . print_r($o, true), LOGGER_DATA);
if ($answer_found && !$found) {
- q("update item set obj = '%s', edited = '%s' where id = %d",
+ $u = q("update item set obj = '%s', edited = '%s' where id = %d",
dbesc(json_encode($o)),
dbesc(datetime_convert()),
intval($item['id'])
);
- Master::Summon(['Notifier', 'wall-new', $item['id'], $post['mid'] /* trick queueworker de-duplication */ ]);
- return true;
+ if ($u) {
+ dbq("COMMIT");
+ Master::Summon(['Notifier', 'wall-new', $item['id']/* , $post['mid'] trick queueworker de-duplication */ ]);
+ return true;
+ }
+
+ dbq("ROLLBACK");
+
}
+ dbq("COMMIT");
return false;
}