From 289ec34ae6890a2d82071b61a12fad866be9f0d0 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 16:35:06 -0700 Subject: take off the kid gloves --- include/deliver.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 0ad008c23..6edf3d60f 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -20,6 +20,20 @@ function deliver_run($argv, $argc) { dbesc($argv[$x]) ); if($r) { + if($r[0]['outq_driver'] === 'post') { + $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); + if($result['success'] && $result['status_code'] < 300) { + logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); + } + else { + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + dbesc(datetime_convert()), + dbesc($argv[$x]) + ); + } + continue; + } + if($r[0]['outq_posturl'] === z_root() . '/post') { logger('deliver: local delivery', LOGGER_DEBUG); // local delivery -- cgit v1.2.3 From 6a42d6fe3b1e50af16942d0f22e8cfa01abfde39 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 18:58:48 -0700 Subject: works one way sort of - now to go the other way - which will require fixing a whole slew of FIXMEs --- include/deliver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 6edf3d60f..08c4f9b64 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -22,7 +22,7 @@ function deliver_run($argv, $argc) { if($r) { if($r[0]['outq_driver'] === 'post') { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); - if($result['success'] && $result['status_code'] < 300) { + if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); } else { -- cgit v1.2.3 From 8a62b824f98ca55c94a2fc04afbea0c118d44486 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 21:49:13 -0700 Subject: lots of little Diaspora issues --- include/deliver.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 08c4f9b64..6f8bf0c98 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -24,6 +24,9 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); + $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + dbesc($argv[$x]) + ); } else { $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", -- cgit v1.2.3 From c6b67518d64fc74524938510ad15e49538847179 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 22:55:40 -0700 Subject: more queue tweaks --- include/deliver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 6f8bf0c98..2693fe165 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -24,7 +24,7 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]) ); } -- cgit v1.2.3 From 88f8900ac52aa1b4bba90d000691dfa311ad2a92 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 29 Aug 2014 17:31:40 -0700 Subject: various diaspora issues --- include/deliver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 2693fe165..f4fae6061 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -29,6 +29,7 @@ function deliver_run($argv, $argc) { ); } else { + logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]) -- cgit v1.2.3 From 28a35261dbc8c21e27ca4a449ff5cd6cb0501c8a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 30 Oct 2014 19:15:03 -0700 Subject: What this checkin does is catch the case where a comment arrived and there's a missing top-level post to match it with. So we'll send a request back to the sender that you've never seen this thread and please send a fresh copy of the entire conversation to date. We could soon have posts in the matrix from different platforms from days gone by, which have been migrated into the modern world. We'll be polite and not deliver these to everybody. However, if someone comments on one of these antique threads we wouldn't be able to see it in our own matrix because we won't have a copy of the parent post. So this rectifies that situation. Be aware that item deletion may need to change to keep "hard deleted" items indefinitely so that they don't keep coming back. We'll have to null out the important data of the former item to accomplish the deletion aspect. --- include/deliver.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index f4fae6061..8f6ba543d 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -38,15 +38,30 @@ function deliver_run($argv, $argc) { continue; } - if($r[0]['outq_posturl'] === z_root() . '/post') { + $notify = json_decode($r[0]['outq_notify'],true); + + $sendtoweb = false; + if(array_key_exists('iv',$notify) && (! $r[0]['outq_msg'])) + $sendtoweb = true; + + if(($r[0]['outq_posturl'] === z_root() . '/post') && (! $sendtoweb)) { logger('deliver: local delivery', LOGGER_DEBUG); // local delivery // we should probably batch these and save a few delivery processes // If there is no outq_msg, this is a refresh_all message which does not require local handling + // also send 'request' packets to the webservice so it can decode the packet if($r[0]['outq_msg']) { - $msg = array('body' => json_encode(array('pickup' => array(array('notify' => json_decode($r[0]['outq_notify'],true),'message' => json_decode($r[0]['outq_msg'],true)))))); - - zot_import($msg,z_root()); + $m = json_decode($r[0]['outq_msg'],true); + if(array_key_exists('message_list',$m)) { + foreach($m['message_list'] as $mm) { + $msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $mm))))); + zot_import($msg,z_root()); + } + } + else { + $msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $m))))); + zot_import($msg,z_root()); + } $r = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]) ); -- cgit v1.2.3 From 285d6f61e4bf8aeaa3294ac4b7af43366a1448e9 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 2 Nov 2014 15:28:20 -0800 Subject: I'm going to try again with the conversation request packets. I've looked this over and tested a lot of edge cases, and thought about from every angle I can think of to prevent looping. I don't *think* this can loop. I also doubt that this is the problem at friendicared.de, but I don't know for sure what that problem might be. --- include/deliver.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 8f6ba543d..729018448 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -40,6 +40,10 @@ function deliver_run($argv, $argc) { $notify = json_decode($r[0]['outq_notify'],true); + // Check if this is a conversation request packet. It won't have outq_msg + // but will be an encrypted packet - so will need to be handed off to + // web delivery rather than processed inline. + $sendtoweb = false; if(array_key_exists('iv',$notify) && (! $r[0]['outq_msg'])) $sendtoweb = true; @@ -48,8 +52,7 @@ function deliver_run($argv, $argc) { logger('deliver: local delivery', LOGGER_DEBUG); // local delivery // we should probably batch these and save a few delivery processes - // If there is no outq_msg, this is a refresh_all message which does not require local handling - // also send 'request' packets to the webservice so it can decode the packet + if($r[0]['outq_msg']) { $m = json_decode($r[0]['outq_msg'],true); if(array_key_exists('message_list',$m)) { -- cgit v1.2.3 From 1a5a5c7edb8697c93f8bababbafa80245378dd7e Mon Sep 17 00:00:00 2001 From: Habeas Codice Date: Thu, 13 Nov 2014 12:21:58 -0800 Subject: PostgreSQL support initial commit There were 11 main types of changes: - UPDATE's and DELETE's sometimes had LIMIT 1 at the end of them. This is not only non-compliant but it would certainly not do what whoever wrote it thought it would. It is likely this mistake was just copied from Friendica. All of these instances, the LIMIT 1 was simply removed. - Bitwise operations (and even some non-zero int checks) erroneously rely on MySQL implicit integer-boolean conversion in the WHERE clauses. This is non-compliant (and bad programming practice to boot). Proper explicit boolean conversions were added. New queries should use proper conventions. - MySQL has a different operator for bitwise XOR than postgres. Rather than add yet another dba_ func, I converted them to "& ~" ("AND NOT") when turning off, and "|" ("OR") when turning on. There were no true toggles (XOR). New queries should refrain from using XOR when not necessary. - There are several fields which the schema has marked as NOT NULL, but the inserts don't specify them. The reason this works is because mysql totally ignores the constraint and adds an empty text default automatically. Again, non-compliant, obviously. In these cases a default of empty text was added. - Several statements rely on a non-standard MySQL feature (http://dev.mysql.com/doc/refman/5.5/en/group-by-handling.html). These queries can all be rewritten to be standards compliant. Interestingly enough, the newly rewritten standards compliant queries run a zillion times faster, even on MySQL. - A couple of function/operator name translations were needed (RAND/RANDOM, GROUP_CONCAT/STRING_AGG, UTC_NOW, REGEXP/~, ^/#) -- assist functions added in the dba_ - INTERVALs: postgres requires quotes around the value, mysql requires that there are not quotes around the value -- assist functions added in the dba_ - NULL_DATE's -- Postgres does not allow the invalid date '0000-00-00 00:00:00' (there is no such thing as year 0 or month 0 or day 0). We use '0001-01-01 00:00:00' for postgres. Conversions are handled in Zot/item packets automagically by quoting all dates with dbescdate(). - char(##) specifications in the schema creates fields with blank spaces that aren't trimmed in the code. MySQL apparently treats char(##) as varchar(##), again, non-compliant. Since postgres works better with text fields anyway, this ball of bugs was simply side-stepped by using 'text' datatype for all text fields in the postgres schema. varchar was used in a couple of places where it actually seemed appropriate (size constraint), but without rigorously vetting that all of the PHP code actually validates data, new bugs might come out from under the rug. - postgres doesn't store nul bytes and a few other non-printables in text fields, even when quoted. bytea fields were used when storing binary data (photo.data, attach.data). A new dbescbin() function was added to handle this transparently. - postgres does not support LIMIT #,# syntax. All databases support LIMIT # OFFSET # syntax. Statements were updated to be standard. These changes require corresponding changes in the coding standards. Please review those before adding any code going forward. Still on my TODO list: - remove quotes from non-reserved identifiers and make reserved identifiers use dba func for quoting - Rewrite search queries for better results (both MySQL and Postgres) --- include/deliver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/deliver.php') diff --git a/include/deliver.php b/include/deliver.php index 8f6ba543d..a9f4fc220 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -24,13 +24,13 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - $y = q("delete from outq where outq_hash = '%s' limit 1", + $y = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]) ); } else { logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]) ); @@ -62,7 +62,7 @@ function deliver_run($argv, $argc) { $msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $m))))); zot_import($msg,z_root()); } - $r = q("delete from outq where outq_hash = '%s' limit 1", + $r = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]) ); } @@ -74,7 +74,7 @@ function deliver_run($argv, $argc) { zot_process_response($r[0]['outq_posturl'],$result, $r[0]); } else { - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]) ); -- cgit v1.2.3