Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x

This commit is contained in:
Brion Vibber 2010-04-20 13:52:58 +02:00
commit df41287226
7 changed files with 88 additions and 28 deletions

View File

@ -981,8 +981,7 @@ class Notice extends Memcached_DataObject
* messages, we won't deliver to any remote targets as that's the * messages, we won't deliver to any remote targets as that's the
* source service's responsibility. * source service's responsibility.
* *
* @fixme Unlike saveReplies() there's no mail notification here. * Mail notifications etc will be handled later.
* Move that to distrib queue handler?
* *
* @param array of unique identifier URIs for recipients * @param array of unique identifier URIs for recipients
*/ */
@ -1021,8 +1020,7 @@ class Notice extends Memcached_DataObject
* and save reply records indicating that this message needs to be * and save reply records indicating that this message needs to be
* delivered to those users. * delivered to those users.
* *
* Side effect: local recipients get e-mail notifications here. * Mail notifications to local profiles will be sent later.
* @fixme move mail notifications to distrib?
* *
* @return array of integer profile IDs * @return array of integer profile IDs
*/ */
@ -1082,17 +1080,14 @@ class Notice extends Memcached_DataObject
$recipientIds = array_keys($replied); $recipientIds = array_keys($replied);
foreach ($recipientIds as $recipientId) {
$user = User::staticGet('id', $recipientId);
if (!empty($user)) {
self::blow('reply:stream:%d', $reply->profile_id);
mail_notify_attn($user, $this);
}
}
return $recipientIds; return $recipientIds;
} }
/**
* Pull the complete list of @-reply targets for this notice.
*
* @return array of integer profile ids
*/
function getReplies() function getReplies()
{ {
// XXX: cache me // XXX: cache me
@ -1115,6 +1110,31 @@ class Notice extends Memcached_DataObject
return $ids; return $ids;
} }
/**
* Send e-mail notifications to local @-reply targets.
*
* Replies must already have been saved; this is expected to be run
* from the distrib queue handler.
*/
function sendReplyNotifications()
{
// Don't send reply notifications for repeats
if (!empty($this->repeat_of)) {
return array();
}
$recipientIds = $this->getReplies();
foreach ($recipientIds as $recipientId) {
$user = User::staticGet('id', $recipientId);
if (!empty($user)) {
self::blow('reply:stream:%d', $recipientId);
mail_notify_attn($user, $this);
}
}
}
/** /**
* Pull list of groups this notice needs to be delivered to, * Pull list of groups this notice needs to be delivered to,
* as previously recorded by saveGroups() or saveKnownGroups(). * as previously recorded by saveGroups() or saveKnownGroups().

View File

@ -1,4 +1,4 @@
You can post messages to %%site.name%% using a many kinds of cell You can post messages to %%site.name%% using many kinds of cell
phones that support SMS messaging. This site does not support SMS phones that support SMS messaging. This site does not support SMS
directly; rather, it uses your carrier's email gateway to send and directly; rather, it uses your carrier's email gateway to send and
receive messages. receive messages.

View File

@ -49,25 +49,34 @@ class DistribQueueHandler
} }
/** /**
* Here's the meat of your queue handler -- you're handed a Notice * Handle distribution of a notice after we've saved it:
* object, which you may do as you will with. * @li add to local recipient inboxes
* @li send email notifications to local @-reply targets
* @li run final EndNoticeSave plugin events
* @li put any remaining post-processing into the queues
* *
* If this function indicates failure, a warning will be logged * If this function indicates failure, a warning will be logged
* and the item is placed back in the queue to be re-run. * and the item is placed back in the queue to be re-run.
* *
* @fixme addToInboxes is known to fail sometimes with large recipient sets
*
* @param Notice $notice * @param Notice $notice
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
function handle($notice) function handle($notice)
{ {
// XXX: do we need to change this for remote users?
try { try {
$notice->addToInboxes(); $notice->addToInboxes();
} catch (Exception $e) { } catch (Exception $e) {
$this->logit($notice, $e); $this->logit($notice, $e);
} }
try {
$notice->sendReplyNotifications();
} catch (Exception $e) {
$this->logit($notice, $e);
}
try { try {
Event::handle('EndNoticeSave', array($notice)); Event::handle('EndNoticeSave', array($notice));
// Enqueue for other handlers // Enqueue for other handlers

View File

@ -51,7 +51,7 @@ abstract class Installer
public static $dbModules = array( public static $dbModules = array(
'mysql' => array( 'mysql' => array(
'name' => 'MySQL', 'name' => 'MySQL',
'check_module' => 'mysql', // mysqli? 'check_module' => 'mysqli',
'installer' => 'mysql_db_installer', 'installer' => 'mysql_db_installer',
), ),
'pgsql' => array( 'pgsql' => array(
@ -341,7 +341,6 @@ abstract class Installer
* @param string $password * @param string $password
* @return mixed array of database connection params on success, false on failure * @return mixed array of database connection params on success, false on failure
* *
* @fixme be consistent about using mysqli vs mysql!
* @fixme escape things in the connection string in case we have a funny pass etc * @fixme escape things in the connection string in case we have a funny pass etc
*/ */
function Mysql_Db_installer($host, $database, $username, $password) function Mysql_Db_installer($host, $database, $username, $password)
@ -349,14 +348,13 @@ abstract class Installer
$this->updateStatus("Starting installation..."); $this->updateStatus("Starting installation...");
$this->updateStatus("Checking database..."); $this->updateStatus("Checking database...");
$conn = mysql_connect($host, $username, $password); $conn = mysqli_init();
if (!$conn) { if (!$conn->real_connect($host, $username, $password)) {
$this->updateStatus("Can't connect to server '$host' as '$username'.", true); $this->updateStatus("Can't connect to server '$host' as '$username'.", true);
return false; return false;
} }
$this->updateStatus("Changing to database..."); $this->updateStatus("Changing to database...");
$res = mysql_select_db($database, $conn); if (!$conn->select_db($database)) {
if (!$res) {
$this->updateStatus("Can't change to database.", true); $this->updateStatus("Can't change to database.", true);
return false; return false;
} }
@ -438,9 +436,9 @@ abstract class Installer
// FIXME: use PEAR::DB or PDO instead of our own switch // FIXME: use PEAR::DB or PDO instead of our own switch
switch ($type) { switch ($type) {
case 'mysqli': case 'mysqli':
$res = mysql_query($stmt, $conn); $res = $conn->query($stmt);
if ($res === false) { if ($res === false) {
$error = mysql_error(); $error = $conn->error();
} }
break; break;
case 'pgsql': case 'pgsql':

View File

@ -636,7 +636,7 @@ function mail_notify_attn($user, $notice)
$bestname = $sender->getBestName(); $bestname = $sender->getBestName();
common_init_locale($user->language); common_switch_locale($user->language);
if ($notice->hasConversation()) { if ($notice->hasConversation()) {
$conversationUrl = common_local_url('conversation', $conversationUrl = common_local_url('conversation',
@ -679,7 +679,7 @@ function mail_notify_attn($user, $notice)
$headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname); $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
common_init_locale(); common_switch_locale();
mail_to_user($user, $subject, $body, $headers); mail_to_user($user, $subject, $body, $headers);
} }

View File

@ -41,11 +41,13 @@ function common_init_locale($language=null)
} }
putenv('LANGUAGE='.$language); putenv('LANGUAGE='.$language);
putenv('LANG='.$language); putenv('LANG='.$language);
return setlocale(LC_ALL, $language . ".utf8", $ok = setlocale(LC_ALL, $language . ".utf8",
$language . ".UTF8", $language . ".UTF8",
$language . ".utf-8", $language . ".utf-8",
$language . ".UTF-8", $language . ".UTF-8",
$language); $language);
return $ok;
} }
function common_init_language() function common_init_language()
@ -89,6 +91,14 @@ function common_init_language()
$locale_set = common_init_locale($language); $locale_set = common_init_locale($language);
} }
common_init_gettext();
}
/**
* @access private
*/
function common_init_gettext()
{
setlocale(LC_CTYPE, 'C'); setlocale(LC_CTYPE, 'C');
// So we do not have to make people install the gettext locales // So we do not have to make people install the gettext locales
$path = common_config('site','locale_path'); $path = common_config('site','locale_path');
@ -97,6 +107,25 @@ function common_init_language()
textdomain("statusnet"); textdomain("statusnet");
} }
/**
* Switch locale during runtime, and poke gettext until it cries uncle.
* Otherwise, sometimes it doesn't actually switch away from the old language.
*
* @param string $language code for locale ('en', 'fr', 'pt_BR' etc)
*/
function common_switch_locale($language=null)
{
common_init_locale($language);
setlocale(LC_CTYPE, 'C');
// So we do not have to make people install the gettext locales
$path = common_config('site','locale_path');
bindtextdomain("statusnet", $path);
bind_textdomain_codeset("statusnet", "UTF-8");
textdomain("statusnet");
}
function common_timezone() function common_timezone()
{ {
if (common_logged_in()) { if (common_logged_in()) {

View File

@ -123,6 +123,10 @@ require_once INSTALLDIR . '/lib/common.php';
set_error_handler('common_error_handler'); set_error_handler('common_error_handler');
// Set up the language infrastructure so we can localize anything that
// needs to be sent out to users, such as mail notifications.
common_init_language();
function _make_matches($opt, $alt) function _make_matches($opt, $alt)
{ {
$matches = array(); $matches = array();