From 3abfb454a381806a0f237e1463d2ba9a8612c22a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 18:39:17 -0800 Subject: Adds an emergency switch so we can run inbox distribution at save time (bypassing 'distrib' queue) Set $config['queue']['inboxes'] = false to do so --- classes/Notice.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 0966697e2..6b364fb5c 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -326,9 +326,13 @@ class Notice extends Memcached_DataObject # XXX: someone clever could prepend instead of clearing the cache $notice->blowOnInsert(); - $qm = QueueManager::get(); - - $qm->enqueue($notice, 'distrib'); + if (common_config('queue', 'inboxes')) { + $qm = QueueManager::get(); + $qm->enqueue($notice, 'distrib'); + } else { + $handler = new DistribQueueHandler(); + $handler->handle($notice); + } return $notice; } -- cgit v1.2.3-54-g00ecf From 644c319f5ad78dbedb686cdfef38152cadf615b2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 19:58:33 -0800 Subject: fix notice -- drop unused return value of variable that isn't initialized :) thx @ g0 for the catch --- classes/Notice.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 6b364fb5c..90e3e76ef 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1378,8 +1378,6 @@ class Notice extends Memcached_DataObject } $reply->free(); - - return $ids; } function clearRepeats() -- cgit v1.2.3-54-g00ecf From ffaaf9de4a1da25f6168c53a33b25683ae134c61 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 23:51:22 -0800 Subject: Don't preemptively close existing DB connections for web views (needed to keep # of conns from going insane on multi-site queue daemons, so just doing for CLI) May, or may not, help with mystery session problems --- classes/Memcached_DataObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 2cc6377f8..b60aa7911 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -428,7 +428,7 @@ class Memcached_DataObject extends DB_DataObject // // WARNING WARNING if we end up actually using multiple DBs at a time // we'll need some fancier logic here. - if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS'])) { + if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS']) && php_sapi_name() == 'cli') { foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $index => $conn) { if (!empty($conn)) { $conn->disconnect(); -- cgit v1.2.3-54-g00ecf From c81318d3ca60f47b3e248c64b7c27364a24814a7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Jan 2010 13:53:28 -0500 Subject: additional debugging data for Sessions --- classes/Session.php | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'classes') diff --git a/classes/Session.php b/classes/Session.php index 79a69a96e..2422f8b68 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -64,8 +64,12 @@ class Session extends Memcached_DataObject $session = Session::staticGet('id', $id); if (empty($session)) { + self::logdeb("Couldn't find '$id'"); return ''; } else { + self::logdeb("Found '$id', returning " . + strlen($session->session_data) . + " chars of data"); return (string)$session->session_data; } } @@ -77,14 +81,24 @@ class Session extends Memcached_DataObject $session = Session::staticGet('id', $id); if (empty($session)) { + self::logdeb("'$id' doesn't yet exist; inserting."); $session = new Session(); $session->id = $id; $session->session_data = $session_data; $session->created = common_sql_now(); - return $session->insert(); + $result = $session->insert(); + + if (!$result) { + common_log_db_error($session, 'INSERT', __FILE__); + self::logdeb("Failed to insert '$id'."); + } else { + self::logdeb("Successfully inserted '$id' (result = $result)."); + } + return $result; } else { + self::logdeb("'$id' already exists; updating."); if (strcmp($session->session_data, $session_data) == 0) { self::logdeb("Not writing session '$id'; unchanged"); return true; @@ -95,7 +109,16 @@ class Session extends Memcached_DataObject $session->session_data = $session_data; - return $session->update($orig); + $result = $session->update($orig); + + if (!$result) { + common_log_db_error($session, 'UPDATE', __FILE__); + self::logdeb("Failed to update '$id'."); + } else { + self::logdeb("Successfully updated '$id' (result = $result)."); + } + + return $result; } } } @@ -106,8 +129,17 @@ class Session extends Memcached_DataObject $session = Session::staticGet('id', $id); - if (!empty($session)) { - return $session->delete(); + if (empty($session)) { + self::logdeb("Can't find '$id' to delete."); + } else { + $result = $session->delete(); + if (!$result) { + common_log_db_error($session, 'DELETE', __FILE__); + self::logdeb("Failed to delete '$id'."); + } else { + self::logdeb("Successfully deleted '$id' (result = $result)."); + } + return $result; } } @@ -132,7 +164,10 @@ class Session extends Memcached_DataObject $session->free(); + self::logdeb("Found " . count($ids) . " ids to delete."); + foreach ($ids as $id) { + self::logdeb("Destroying session '$id'."); self::destroy($id); } } -- cgit v1.2.3-54-g00ecf From 84b5480007d30280cc9c829fe1316db0f853f64c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Jan 2010 12:57:52 -0500 Subject: update mysqltimestamps on insert and update --- classes/Memcached_DataObject.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 2cc6377f8..bc9aaf81f 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -147,6 +147,7 @@ class Memcached_DataObject extends DB_DataObject { $result = parent::insert(); if ($result) { + $this->fixupTimestamps(); $this->encache(); // in case of cached negative lookups } return $result; @@ -159,6 +160,7 @@ class Memcached_DataObject extends DB_DataObject } $result = parent::update($orig); if ($result) { + $this->fixupTimestamps(); $this->encache(); } return $result; @@ -366,7 +368,7 @@ class Memcached_DataObject extends DB_DataObject } /** - * sends query to database - this is the private one that must work + * sends query to database - this is the private one that must work * - internal functions use this rather than $this->query() * * Overridden to do logging. @@ -529,4 +531,20 @@ class Memcached_DataObject extends DB_DataObject return $c->delete($cacheKey); } + + function fixupTimestamps() + { + // Fake up timestamp columns + $columns = $this->table(); + foreach ($columns as $name => $type) { + if ($type & DB_DATAOBJECT_MYSQLTIMESTAMP) { + $this->$name = common_sql_now(); + } + } + } + + function debugDump() + { + common_debug("debugDump: " . common_log_objstring($this)); + } } -- cgit v1.2.3-54-g00ecf From 513f8be07a22d722b86509e570bee46d028066f2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Jan 2010 16:26:55 -0500 Subject: hide most DB_DataObject errors --- classes/Memcached_DataObject.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index e615f2353..f4dfe6314 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -547,4 +547,9 @@ class Memcached_DataObject extends DB_DataObject { common_debug("debugDump: " . common_log_objstring($this)); } + + function raiseError($message, $type = null, $behaviour = null) + { + throw new ServerException("DB_DataObject error [$type]: $message"); + } } -- cgit v1.2.3-54-g00ecf From d13d73c5630244963f0c3bd9db68dd6c6451821a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Jan 2010 18:40:38 -0500 Subject: Last-chance distribution if enqueueing fails --- classes/Notice.php | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 90e3e76ef..a60dd5bcd 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -326,13 +326,7 @@ class Notice extends Memcached_DataObject # XXX: someone clever could prepend instead of clearing the cache $notice->blowOnInsert(); - if (common_config('queue', 'inboxes')) { - $qm = QueueManager::get(); - $qm->enqueue($notice, 'distrib'); - } else { - $handler = new DistribQueueHandler(); - $handler->handle($notice); - } + $notice->distribute(); return $notice; } @@ -1447,4 +1441,31 @@ class Notice extends Memcached_DataObject $gi->free(); } + + function distribute() + { + if (common_config('queue', 'inboxes')) { + // If there's a failure, we want to _force_ + // distribution at this point. + try { + $qm = QueueManager::get(); + $qm->enqueue($this, 'distrib'); + } catch (Exception $e) { + // If the exception isn't transient, this + // may throw more exceptions as DQH does + // its own enqueueing. So, we ignore them! + try { + $handler = new DistribQueueHandler(); + $handler->handle($this); + } catch (Exception $e) { + common_log(LOG_ERR, "emergency redistribution resulted in " . $e->getMessage()); + } + // Re-throw so somebody smarter can handle it. + throw $e; + } + } else { + $handler = new DistribQueueHandler(); + $handler->handle($this); + } + } } -- cgit v1.2.3-54-g00ecf From 864ce8e276220262ef8a26a9138c929145ccf57e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 28 Jan 2010 20:09:17 -0800 Subject: Fixes for status_network db object .ini and tag setter script --- classes/status_network.ini | 1 + scripts/settag.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/status_network.ini b/classes/status_network.ini index 8123265e4..adb71cba7 100644 --- a/classes/status_network.ini +++ b/classes/status_network.ini @@ -11,6 +11,7 @@ theme = 2 logo = 2 created = 142 modified = 384 +tags = 34 [status_network__keys] nickname = K diff --git a/scripts/settag.php b/scripts/settag.php index 1d7b60b90..e91d5eb50 100644 --- a/scripts/settag.php +++ b/scripts/settag.php @@ -50,7 +50,7 @@ if (empty($sn)) { $tags = $sn->getTags(); -$i = array_search($tags, $tag); +$i = array_search($tag, $tags); if ($i !== false) { if (have_option('d', 'delete')) { // Delete -- cgit v1.2.3-54-g00ecf From f6eecf02fc9eca0d3947a8cacf374909003dc8d4 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 15:01:21 -0500 Subject: add simple cache getter/setter static functions to Memcached_DataObject --- classes/Memcached_DataObject.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index f4dfe6314..ab65c30ce 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -552,4 +552,30 @@ class Memcached_DataObject extends DB_DataObject { throw new ServerException("DB_DataObject error [$type]: $message"); } + + static function cacheGet($keyPart) + { + $c = self::memcache(); + + if (empty($c)) { + return false; + } + + $cacheKey = common_cache_key($keyPart); + + return $c->get($cacheKey); + } + + static function cacheSet($keyPart, $value) + { + $c = self::memcache(); + + if (empty($c)) { + return false; + } + + $cacheKey = common_cache_key($keyPart); + + return $c->set($cacheKey, $value); + } } -- cgit v1.2.3-54-g00ecf From d437b76ed1a7ba3c39f0d3cb8bef15e19c1c184f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 15:15:04 -0500 Subject: define a constant for the 'owner' role of a site --- classes/Profile_role.php | 1 + 1 file changed, 1 insertion(+) (limited to 'classes') diff --git a/classes/Profile_role.php b/classes/Profile_role.php index 74aca3730..bf2c453ed 100644 --- a/classes/Profile_role.php +++ b/classes/Profile_role.php @@ -48,6 +48,7 @@ class Profile_role extends Memcached_DataObject return Memcached_DataObject::pkeyGet('Profile_role', $kv); } + const OWNER = 'owner'; const MODERATOR = 'moderator'; const ADMINISTRATOR = 'administrator'; const SANDBOXED = 'sandboxed'; -- cgit v1.2.3-54-g00ecf From 70a4f8c0e26bfdb76f595ce501c6e84a8011fea8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 15:15:23 -0500 Subject: method to get the site owner --- classes/User.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'classes') diff --git a/classes/User.php b/classes/User.php index 6ea975202..b70049617 100644 --- a/classes/User.php +++ b/classes/User.php @@ -925,4 +925,30 @@ class User extends Memcached_DataObject return $share; } } + + static function siteOwner() + { + $owner = self::cacheGet('user:site_owner'); + + if ($owner === false) { // cache miss + + $pr = new Profile_role(); + + $pr->role = Profile_role::OWNER; + + $pr->orderBy('created'); + + $pr->limit(0, 1); + + if ($pr->fetch($true)) { + $owner = User::staticGet('id', $pr->profile_id); + } else { + $owner = null; + } + + self::cacheSet('user:site_owner', $owner); + } + + return $owner; + } } -- cgit v1.2.3-54-g00ecf From 8cb8b357a4383f7afb1e09fcd264aa41ac1502a6 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 17:54:54 -0500 Subject: add hooks for user registration --- EVENTS.txt | 9 +++ classes/User.php | 171 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 98 insertions(+), 82 deletions(-) (limited to 'classes') diff --git a/EVENTS.txt b/EVENTS.txt index 1ed670697..3317c80de 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -699,3 +699,12 @@ StartShowContentLicense: Showing the default license for content EndShowContentLicense: Showing the default license for content - $action: the current action + +StartUserRegister: When a new user is being registered +- &$profile: new profile data (no ID) +- &$user: new user account (no ID or URI) + +EndUserRegister: When a new user has been registered +- &$profile: new profile data +- &$user: new user account + diff --git a/classes/User.php b/classes/User.php index b70049617..022044aac 100644 --- a/classes/User.php +++ b/classes/User.php @@ -209,8 +209,6 @@ class User extends Memcached_DataObject $profile = new Profile(); - $profile->query('BEGIN'); - if(!empty($email)) { $email = common_canonical_email($email); @@ -220,7 +218,7 @@ class User extends Memcached_DataObject $profile->nickname = $nickname; if(! User::allowed_nickname($nickname)){ common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname), - __FILE__); + __FILE__); } $profile->profileurl = common_profile_url($nickname); @@ -248,16 +246,8 @@ class User extends Memcached_DataObject $profile->created = common_sql_now(); - $id = $profile->insert(); - - if (empty($id)) { - common_log_db_error($profile, 'INSERT', __FILE__); - return false; - } - $user = new User(); - $user->id = $id; $user->nickname = $nickname; if (!empty($password)) { // may not have a password for OpenID users @@ -282,109 +272,126 @@ class User extends Memcached_DataObject $user->inboxed = 1; $user->created = common_sql_now(); - $user->uri = common_user_uri($user); - $result = $user->insert(); + if (Event::handle('StartUserRegister', array(&$user, &$profile))) { - if (!$result) { - common_log_db_error($user, 'INSERT', __FILE__); - return false; - } + $profile->query('BEGIN'); - // Everyone gets an inbox + $id = $profile->insert(); - $inbox = new Inbox(); + if (empty($id)) { + common_log_db_error($profile, 'INSERT', __FILE__); + return false; + } - $inbox->user_id = $user->id; - $inbox->notice_ids = ''; + $user->id = $id; + $user->uri = common_user_uri($user); - $result = $inbox->insert(); + $result = $user->insert(); - if (!$result) { - common_log_db_error($inbox, 'INSERT', __FILE__); - return false; - } + if (!$result) { + common_log_db_error($user, 'INSERT', __FILE__); + return false; + } - // Everyone is subscribed to themself + // Everyone gets an inbox - $subscription = new Subscription(); - $subscription->subscriber = $user->id; - $subscription->subscribed = $user->id; - $subscription->created = $user->created; + $inbox = new Inbox(); - $result = $subscription->insert(); + $inbox->user_id = $user->id; + $inbox->notice_ids = ''; - if (!$result) { - common_log_db_error($subscription, 'INSERT', __FILE__); - return false; - } - - if (!empty($email) && !$user->email) { - - $confirm = new Confirm_address(); - $confirm->code = common_confirmation_code(128); - $confirm->user_id = $user->id; - $confirm->address = $email; - $confirm->address_type = 'email'; + $result = $inbox->insert(); - $result = $confirm->insert(); if (!$result) { - common_log_db_error($confirm, 'INSERT', __FILE__); + common_log_db_error($inbox, 'INSERT', __FILE__); return false; } - } - if (!empty($code) && $user->email) { - $user->emailChanged(); - } + // Everyone is subscribed to themself - // Default system subscription + $subscription = new Subscription(); + $subscription->subscriber = $user->id; + $subscription->subscribed = $user->id; + $subscription->created = $user->created; - $defnick = common_config('newuser', 'default'); + $result = $subscription->insert(); - if (!empty($defnick)) { - $defuser = User::staticGet('nickname', $defnick); - if (empty($defuser)) { - common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), - __FILE__); - } else { - $defsub = new Subscription(); - $defsub->subscriber = $user->id; - $defsub->subscribed = $defuser->id; - $defsub->created = $user->created; + if (!$result) { + common_log_db_error($subscription, 'INSERT', __FILE__); + return false; + } + + if (!empty($email) && !$user->email) { + + $confirm = new Confirm_address(); + $confirm->code = common_confirmation_code(128); + $confirm->user_id = $user->id; + $confirm->address = $email; + $confirm->address_type = 'email'; - $result = $defsub->insert(); + $result = $confirm->insert(); if (!$result) { - common_log_db_error($defsub, 'INSERT', __FILE__); + common_log_db_error($confirm, 'INSERT', __FILE__); return false; } } - } - $profile->query('COMMIT'); + if (!empty($code) && $user->email) { + $user->emailChanged(); + } - if (!empty($email) && !$user->email) { - mail_confirm_address($user, $confirm->code, $profile->nickname, $email); - } + // Default system subscription - // Welcome message + $defnick = common_config('newuser', 'default'); - $welcome = common_config('newuser', 'welcome'); + if (!empty($defnick)) { + $defuser = User::staticGet('nickname', $defnick); + if (empty($defuser)) { + common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), + __FILE__); + } else { + $defsub = new Subscription(); + $defsub->subscriber = $user->id; + $defsub->subscribed = $defuser->id; + $defsub->created = $user->created; - if (!empty($welcome)) { - $welcomeuser = User::staticGet('nickname', $welcome); - if (empty($welcomeuser)) { - common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), - __FILE__); - } else { - $notice = Notice::saveNew($welcomeuser->id, - sprintf(_('Welcome to %1$s, @%2$s!'), - common_config('site', 'name'), - $user->nickname), - 'system'); + $result = $defsub->insert(); + if (!$result) { + common_log_db_error($defsub, 'INSERT', __FILE__); + return false; + } + } } + + $profile->query('COMMIT'); + + if (!empty($email) && !$user->email) { + mail_confirm_address($user, $confirm->code, $profile->nickname, $email); + } + + // Welcome message + + $welcome = common_config('newuser', 'welcome'); + + if (!empty($welcome)) { + $welcomeuser = User::staticGet('nickname', $welcome); + if (empty($welcomeuser)) { + common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), + __FILE__); + } else { + $notice = Notice::saveNew($welcomeuser->id, + sprintf(_('Welcome to %1$s, @%2$s!'), + common_config('site', 'name'), + $user->nickname), + 'system'); + + } + } + + Event::handle('EndUserRegister', array(&$profile, &$user)); } return $user; -- cgit v1.2.3-54-g00ecf From fec8066bf76948142828b689708386861d089fb3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 Jan 2010 14:37:39 -0500 Subject: error clearing tags for profiles from memcached --- classes/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index a60dd5bcd..42878d94f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -140,7 +140,7 @@ class Notice extends Memcached_DataObject foreach(array_unique($hashtags) as $hashtag) { /* elide characters we don't want in the tag */ $this->saveTag($hashtag); - self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, $tag->tag); + self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, $hashtag); } return true; } -- cgit v1.2.3-54-g00ecf