From a27391c33a6b2d3828182ca5f8e8b65998cf47a7 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 01:16:17 -0700 Subject: [PATCH 1/7] facebook queueing on failure, sync update.php with boot.php update version to avoid race condition --- addon/facebook/facebook.php | 84 ++++++++++++++++++++++++++++++++----- boot.php | 21 +++++++--- database.sql | 1 + include/queue.php | 22 +++------- include/queue_fn.php | 16 +++++++ update.php | 9 +++- 6 files changed, 119 insertions(+), 34 deletions(-) create mode 100644 include/queue_fn.php diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index 3cc40330c3..7ee2b1b082 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -335,18 +335,20 @@ function facebook_content(&$a) { } function facebook_install() { - register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook'); - register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets'); - register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings'); - register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron'); + register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook'); + register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets'); + register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings'); + register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron'); + register_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook'); } function facebook_uninstall() { - unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook'); - unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets'); - unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings'); - unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron'); + unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook'); + unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets'); + unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings'); + unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron'); + unregister_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook'); } @@ -635,9 +637,19 @@ function facebook_post_hook(&$a,&$b) { ); } else { - // FIXME queue the message so we can attempt to redeliver, see include/notifier.php and include/queue.php - if(! $likes) - notice( t('Facebook delivery failed.') . EOL); + if(! $likes) { + $s = serialize(array('url' => $url, 'item' => $b, 'post' => $postvars)); + q("INSERT INTO `queue` ( `network`, `cid`, `created`, `last`, `content`) + VALUES ( '%s', '%s', '%s', '%s') ", + dbesc(NETWORK_FACEBOOK), + intval($a->contact), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($s) + ); + + notice( t('Facebook post failed. Queued for retry.') . EOL); + } } logger('Facebook post returns: ' . $x, LOGGER_DEBUG); @@ -648,6 +660,56 @@ function facebook_post_hook(&$a,&$b) { } +function fb_queue_hook(&$a,&$b) { + + require_once('include/queue_fn.php'); + if((! is_array($b)) || (! count($b))) + return; + foreach($b as $x) { + if($b['network'] !== NETWORK_FACEBOOK) + continue; + $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid` + WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", + intval($x['cid']) + ); + if(! count($r)) + continue; + + $user = $r[0]; + + $appid = get_config('facebook', 'appid' ); + $secret = get_config('facebook', 'appsecret' ); + + if($appid && $secret) { + $fb_post = intval(get_pconfig($user['uid'],'facebook','post')); + $fb_token = get_pconfig($user['uid'],'facebook','access_token'); + + if($fb_post && $fb_token) { + logger('facebook_queue: able to post'); + require_once('library/facebook.php'); + + $z = unserialize($x['content']); + $item = $z['item']; + $j = post_url($z['url'],$z['post']); + + $retj = json_decode($j); + if($retj->id) { + q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1", + dbesc('fb::' . $retj->id), + intval($item['id']) + ); + logger('facebook queue: success: ' . $j); + remove_queue_item($x['id']); + } + else { + logger('facebook_queue: failed: ' . $j); + update_queue_time($x['id']); + } + } + } + } +} + function fb_consume_all($uid) { require_once('include/items.php'); diff --git a/boot.php b/boot.php index 0af73c4684..798a2ef433 100644 --- a/boot.php +++ b/boot.php @@ -6,7 +6,7 @@ ini_set('pcre.backtrack_limit', 250000); define ( 'FRIENDIKA_VERSION', '2.2.999' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); -define ( 'DB_UPDATE_VERSION', 1059 ); +define ( 'DB_UPDATE_VERSION', 1060 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -481,17 +481,26 @@ function check_config(&$a) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if(($stored < $current) && file_exists('update.php')) { + // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. require_once('update.php'); - for($x = $stored; $x < $current; $x ++) { - if(function_exists('update_' . $x)) { - $func = 'update_' . $x; - $func($a); + + // make sure that boot.php and update.php are the same release, we might be + // updating right this very second and the correct version of the update.php + // file may not be here yet. This can happen on a very busy site. + + if(DB_UPDATE_VERSION == UPDATE_VERSION) { + + for($x = $stored; $x < $current; $x ++) { + if(function_exists('update_' . $x)) { + $func = 'update_' . $x; + $func($a); + } } + set_config('system','build', DB_UPDATE_VERSION); } - set_config('system','build', DB_UPDATE_VERSION); } } diff --git a/database.sql b/database.sql index 8948e9b061..7c26af341b 100644 --- a/database.sql +++ b/database.sql @@ -440,6 +440,7 @@ PRIMARY KEY ( `id` ) CREATE TABLE IF NOT EXISTS `queue` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `cid` INT NOT NULL , +`network` CHAR( 32 ) NOT NULL, `created` DATETIME NOT NULL , `last` DATETIME NOT NULL , `content` MEDIUMTEXT NOT NULL diff --git a/include/queue.php b/include/queue.php index ff280cb53b..cc36b2f625 100644 --- a/include/queue.php +++ b/include/queue.php @@ -1,20 +1,6 @@ $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); call_hooks('queue_deliver', $a, $params); diff --git a/include/queue_fn.php b/include/queue_fn.php new file mode 100644 index 0000000000..bc47ceffdb --- /dev/null +++ b/include/queue_fn.php @@ -0,0 +1,16 @@ + Date: Fri, 3 Jun 2011 06:12:34 -0700 Subject: [PATCH 2/7] new member page --- include/auth.php | 13 +++++++++++++ mod/newmember.php | 43 +++++++++++++++++++++++++++++++++++++++++++ mod/profile.php | 3 +++ 3 files changed, 59 insertions(+) create mode 100644 mod/newmember.php diff --git a/include/auth.php b/include/auth.php index fd80a63e22..d1eb9d131c 100644 --- a/include/auth.php +++ b/include/auth.php @@ -63,6 +63,12 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p $_SESSION['theme'] = $a->user['theme']; $_SESSION['page_flags'] = $a->user['page-flags']; + $member_since = strtotime($a->user['register_date']); + if(time() < ($member_since + ( 60 * 60 * 24 * 14))) + $_SESSION['new_member'] = true; + else + $_SESSION['new_member'] = false; + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); $a->timezone = $a->user['timezone']; @@ -211,6 +217,13 @@ else { else info( t("Welcome back ") . $a->user['username'] . EOL); + + $member_since = strtotime($a->user['register_date']); + if(time() < ($member_since + ( 60 * 60 * 24 * 14))) + $_SESSION['new_member'] = true; + else + $_SESSION['new_member'] = false; + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); $a->timezone = $a->user['timezone']; diff --git a/mod/newmember.php b/mod/newmember.php new file mode 100644 index 0000000000..bc1fb75085 --- /dev/null +++ b/mod/newmember.php @@ -0,0 +1,43 @@ +' . t('Welcome to Friendika') . ''; + + $o .= '

' . t('New Member Checklist') . '

'; + + $o .= '
'; + + $o .= t('We would like to offer some tips and links to help make your experience enjoyable. Click any item to visit the relevant page.'); + + $o .= '
'; + + return $o; +} \ No newline at end of file diff --git a/mod/profile.php b/mod/profile.php index 52551c45f4..68110d7619 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -126,6 +126,9 @@ function profile_content(&$a, $update = 0) { return $o; } + if(x($_SESSION,'new_user') && $_SESSION['new_user']) + $o .= '' . t('Tips for New Members') . '' . EOL; + $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false); $commvisitor = (($commpage && $remote_contact == true) ? true : false); From 32bebdfa7e6cf4b73eeabba0377e9fcb5afea27c Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 06:17:43 -0700 Subject: [PATCH 3/7] new_member not new_user --- mod/profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index 68110d7619..ea84c3822c 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -126,7 +126,7 @@ function profile_content(&$a, $update = 0) { return $o; } - if(x($_SESSION,'new_user') && $_SESSION['new_user']) + if(x($_SESSION,'new_member') && $_SESSION['new_member']) $o .= '' . t('Tips for New Members') . '' . EOL; $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false); From 86df81352f6d9afdb5f30e59fa138a69ac20e222 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 06:22:39 -0700 Subject: [PATCH 4/7] show new_member page only on our own profile --- mod/profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index ea84c3822c..7dfdb49de4 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -126,7 +126,7 @@ function profile_content(&$a, $update = 0) { return $o; } - if(x($_SESSION,'new_member') && $_SESSION['new_member']) + if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner) $o .= '' . t('Tips for New Members') . '' . EOL; $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false); From bc3255ab3fc0857984e2b55bbb32a49cae73f7ea Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 06:41:52 -0700 Subject: [PATCH 5/7] don't serialize entire item --- addon/facebook/facebook.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index 7ee2b1b082..ac522aab63 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -638,7 +638,7 @@ function facebook_post_hook(&$a,&$b) { } else { if(! $likes) { - $s = serialize(array('url' => $url, 'item' => $b, 'post' => $postvars)); + $s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars)); q("INSERT INTO `queue` ( `network`, `cid`, `created`, `last`, `content`) VALUES ( '%s', '%s', '%s', '%s') ", dbesc(NETWORK_FACEBOOK), @@ -696,7 +696,7 @@ function fb_queue_hook(&$a,&$b) { if($retj->id) { q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1", dbesc('fb::' . $retj->id), - intval($item['id']) + intval($item) ); logger('facebook queue: success: ' . $j); remove_queue_item($x['id']); From 980d3864cb1036cf7968f4d7e612a8959f3639a3 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 06:49:57 -0700 Subject: [PATCH 6/7] document newmember link so you can find it later. --- doc/Account-Basics.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/Account-Basics.md b/doc/Account-Basics.md index 9c65484304..5791dce783 100644 --- a/doc/Account-Basics.md +++ b/doc/Account-Basics.md @@ -53,6 +53,9 @@ Otherwise, enter your password. This will have been initially provided in your r After your first login, please visit the 'Settings' page from the top menu bar and change your password to something that you will remember. +**Getting Started** + +A ['Tips for New Members'](newmember) link will show up on your home page for two weeks to provide some important Getting Started information. **See Also** From e591ed6b30808cabf1f0c80a356f3fa12ce4aa31 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 3 Jun 2011 07:04:43 -0700 Subject: [PATCH 7/7] minor edits --- mod/newmember.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/newmember.php b/mod/newmember.php index bc1fb75085..eff258d21c 100644 --- a/mod/newmember.php +++ b/mod/newmember.php @@ -31,10 +31,12 @@ function newmember_content(&$a) { $o .= '
  • ' . '' . t('Set some public keywords for your default profile which describe your interests. We may be able to find other people with similar interests and suggest friendships.') . '
  • ' . EOL; - $o .= '
  • ' . '' . t('Your Contact page is your gateway to editing and connecting with friends on other networks. Typically you enter their address or site URL in the Connect dialog.') . '
  • ' . EOL; + $o .= '
  • ' . '' . t('Your Contacts page is your gateway to managing friendships and connecting with friends on other networks. Typically you enter their address or site URL in the Connect dialog.') . '
  • ' . EOL; $o .= '
  • ' . '' . t('The Directory page lets you find other people in this network or other federated sites. Look for a Connect or Follow link on their profile page. Provide your own Identity Address if requested.') . '
  • ' . EOL; + $o .= '
  • ' . '' . t('Once you have made some friends, organize them into private conversation groups from the sidebar of your Contacts page and then you can interact with each group privately on your Network page.') . '
  • ' . EOL; + $o .= '
  • ' . '' . t('Our help pages may be consulted for detail on other program features and resources.') . '
  • ' . EOL; $o .= '';