Changeset 423 for branches/1.1dev


Ignore:
Timestamp:
Aug 13, 2013 11:52:52 PM (11 years ago)
Author:
anonymous
Message:

Backporting fixes to v1.1

Location:
branches/1.1dev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/config/boot.inc.php

    r352 r423  
    7676   
    7777    // Connect to MySQL
    78     $dbh = mysql_connect('localhost', $CFG->username, $CFG->password);
    79    
    80     // Select database
    81     mysql_select_db($CFG->database, $dbh);
     78    if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) {
     79        // Select database
     80        mysql_select_db($CFG->database, $dbh);       
     81    }
    8282
    8383    // Connection errors.
     
    109109            echo "<!-- --------------------------------------\n" . $debugqry . "\n-->";
    110110        }
     111       
     112        // Ensure we have an active connection.
     113        // If we continue on a dead connection we might experience a "MySQL server has gone away" error.
     114        // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
     115        // Unfortunately we'll have redundant code with the reconnection below.
     116        if (!mysql_ping($dbh)) {
     117            logMsg(sprintf('MySQL ping failed; reconnecting
 ("%s")', truncate(trim($debugqry), 150)), LOG_NOTICE, __FILE__, __LINE__);
     118            mysql_close($dbh);
     119            if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) {
     120                mysql_select_db($CFG->database, $dbh);       
     121            }
     122            if (!$dbh || mysql_error($dbh)) {
     123                $mysql_error_msg = $dbh ? 'Codebase MySQL error: (' . mysql_errno($dbh) . ') ' . mysql_error($dbh) : 'Codebase MySQL error: Could not connect to server.';
     124                if ($CFG->db_debug) {
     125                    echo $mysql_error_msg . "\n";
     126                } else {
     127                    echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
     128                }
     129                logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
     130                die;
     131            }
     132        }
     133
    111134        $qid = mysql_query($query, $dbh);
    112135        if (!$qid || mysql_error($dbh)) {
  • branches/1.1dev/lib/Utilities.inc.php

    r401 r423  
    154154 * @since   29 Mar 2006 13:48:49
    155155 */
    156 function truncate($str, $len, $where='middle')
    157 {
     156function truncate($str, $len, $where='end', $delim='
')
     157{
     158    if ($len <= 3 || mb_strlen($str) <= 3) {
     159        return '';
     160    }
    158161    $part1 = floor(($len - 3) / 2);
    159162    $part2 = ceil(($len - 3) / 2);
    160163    switch ($where) {
    161164    case 'start' :
    162         return preg_replace(array(sprintf('/^.{4,}(.{%s})$/', $part1 + $part2), '/\s*\.{3,}\s*/'), array('...$1', '...'), $str);
     165        return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str);
    163166        break;
    164167    default :
    165168    case 'middle' :
    166         return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/', $part1, $part2), '/\s*\.{3,}\s*/'), array('$1...$2', '...'), $str);
     169        return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str);
    167170        break;   
    168171    case 'end' :
    169         return preg_replace(array(sprintf('/^(.{%s}).{4,}$/', $part1 + $part2), '/\s*\.{3,}\s*/'), array('$1...', '...'), $str);
    170         break;   
     172        return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str);
     173        break;
    171174    }
    172175}
Note: See TracChangeset for help on using the changeset viewer.