From 3fd877c4cecd80fbe65043dd4612d9688e16ecd8 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 3 Mar 2009 21:32:47 +0000 Subject: Use single quotes for data literals on inserts to notice_index, so it works on pgsql as well as mysql --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 8300667fa..907239b08 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -585,7 +585,7 @@ class Notice extends Memcached_DataObject $inbox = new Notice_inbox(); $UT = common_config('db','type')=='pgsql'?'"user"':'user'; $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' . - "SELECT $UT.id, " . $this->id . ', "' . $this->created . '" ' . + "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " . "FROM $UT JOIN subscription ON $UT.id = subscription.subscriber " . 'WHERE subscription.subscribed = ' . $this->profile_id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . @@ -655,7 +655,7 @@ class Notice extends Memcached_DataObject $inbox = new Notice_inbox(); $UT = common_config('db','type')=='pgsql'?'"user"':'user'; $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . - "SELECT $UT.id, " . $this->id . ', "' . $this->created . '", 2 ' . + "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " . "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . -- cgit v1.2.3-54-g00ecf From 35677336de4c01c4f6b02840222075c6ac963988 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 3 Mar 2009 21:33:52 +0000 Subject: Catch bad replyto IDs before saving a new notice to avoid a constraint violation. This happens, for example, when posting for the first time on a fresh install --- actions/newnotice.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actions/newnotice.php b/actions/newnotice.php index 9f44d2516..cbd04c58b 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -152,6 +152,11 @@ class NewnoticeAction extends Action } $replyto = $this->trimmed('inreplyto'); + #If an ID of 0 is wrongly passed here, it will cause a database error, + #so override it... + if ($replyto == 0) { + $replyto = 'false'; + } $notice = Notice::saveNew($user->id, $content, 'web', 1, ($replyto == 'false') ? null : $replyto); -- cgit v1.2.3-54-g00ecf From 7279554681da728deb74a87230de3a1021182f71 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Wed, 4 Mar 2009 00:23:34 +0000 Subject: Additional (optional, defaults to off) logging of PEAR error details, which allows database issues to be more easily diagnosed. --- config.php.sample | 3 +++ index.php | 6 +++++- lib/common.php | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.php.sample b/config.php.sample index 6e55eaffc..a6cada77a 100644 --- a/config.php.sample +++ b/config.php.sample @@ -34,6 +34,9 @@ $config['site']['path'] = 'laconica'; # If you want logging sent to a file instead of syslog #$config['site']['logfile'] = '/tmp/laconica.log'; +# Enables extra log information, for example full details of PEAR DB errors +#$config['site']['logdebug'] = true; + # This is a PEAR DB DSN, see http://pear.php.net/manual/en/package.database.db.intro-dsn.php # Set it to match your actual database diff --git a/index.php b/index.php index 914ba5bde..03c044415 100644 --- a/index.php +++ b/index.php @@ -43,7 +43,11 @@ function handleError($error) return; } - common_log(LOG_ERR, "PEAR error: " . $error->getMessage()); + $logmsg = "PEAR error: " . $error->getMessage(); + if(common_config('site', 'logdebug')) { + $logmsg .= " : ". $error->getDebugInfo(); + } + common_log(LOG_ERR, $logmsg); $msg = sprintf(_('The database for %s isn\'t responding correctly, '. 'so the site won\'t work properly. '. 'The site admins probably know about the problem, '. diff --git a/lib/common.php b/lib/common.php index 0fff3af2e..3df68d98a 100644 --- a/lib/common.php +++ b/lib/common.php @@ -73,6 +73,7 @@ $config = 'theme' => 'default', 'path' => $_path, 'logfile' => null, + 'logdebug' => false, 'fancy' => false, 'locale_path' => INSTALLDIR.'/locale', 'language' => 'en_US', -- cgit v1.2.3-54-g00ecf