From 4b32c7be676d4a191c869a5745f2890240852fb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 10 Mar 2010 00:26:40 +0000 Subject: [PATCH] Failed SQL queries are now also reported in bug mails, SQL queries improved (more human-readable) --- inc/db/lib-mysql3.php | 5 +-- inc/libs/admins_functions.php | 4 +- inc/libs/surfbar_functions.php | 80 +++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 77568f0338..02e1722fe2 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -85,9 +85,8 @@ function SQL_QUERY ($sqlString, $F, $L) { // Run SQL command //* DEBUG: */ print('F=' . basename($F) . ',L=' . $L . 'sql=' . htmlentities($sqlString) . '
'); $result = mysql_query($sqlString, SQL_GET_LINK()) - or addFatalMessage(__FUNCTION__, __LINE__, $F . ' (' . $L . '):' . mysql_error() . '
-Query string:
-' . $sqlString); + or debug_report_bug('[' . __FUNCTION__ . ':' . __LINE__ . '] ' . $F . ' (' . $L . '):' . mysql_error() . "\n". +'Query string:' . $sqlString); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sqlString . ',numRows=' . SQL_NUMROWS($result) . ',affected=' . SQL_AFFECTEDROWS()); // Calculate query time diff --git a/inc/libs/admins_functions.php b/inc/libs/admins_functions.php index e0424383fb..8c692aa43b 100644 --- a/inc/libs/admins_functions.php +++ b/inc/libs/admins_functions.php @@ -420,7 +420,7 @@ function adminsListAdminAccounts() { } // Sends out mail to all administrators -// IMPORTANT: Please use SEND_ADMIN_NOTIFCATION() for now! +// IMPORTANT: Please use sendAdminNotification() instead of calling this function directly function sendAdminsEmails ($subj, $template, $content, $userid) { // Trim template name $template = trim($template); @@ -463,7 +463,7 @@ function sendAdminsEmails ($subj, $template, $content, $userid) { $userid )); } - } elseif ($adminId == '0') { + } elseif (($adminId == '0') || (empty($adminId))) { // Select all email adresses $result = SQL_QUERY("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC", __FUNCTION__, __LINE__); diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index e62d6835f0..ab04a7fa5d 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -364,11 +364,11 @@ function SURFBAR_MEMBER_RESUBMIT_ACTION ($urlData) { // Display selected "action form" function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) { // Translate some data - $urlData['registered'] = generateDateTime($urlData['registered'], 2); - $urlData['views_total'] = translateComma($urlData['views_total']); - $urlData['views_max'] = translateComma($urlData['views_max']); - $urlData['views_allowed'] = translateComma($urlData['views_allowed']); - $urlData['last_locked'] = generateDateTime($urlData['last_locked'], 2); + $urlData['url_registered'] = generateDateTime($urlData['url_registered'], 2); + $urlData['views_total'] = translateComma($urlData['views_total']); + $urlData['views_max'] = translateComma($urlData['views_max']); + $urlData['views_allowed'] = translateComma($urlData['views_allowed']); + $urlData['last_locked'] = generateDateTime($urlData['last_locked'], 2); // Is the lock reason empty? if (empty($urlData['lock_reason'])) { @@ -556,7 +556,7 @@ function SURFBAR_GET_URL_DATA ($searchTerm, $column = 'id', $order = 'id', $sort $result = SQL_QUERY_ESC("SELECT `id`, `userid`, `url`, `views_total`, `views_max`, `views_allowed`, `status`, - UNIX_TIMESTAMP(`registered`) AS `registered`, UNIX_TIMESTAMP(`last_locked`) AS `last_locked`, `lock_reason`, + UNIX_TIMESTAMP(`registered`) AS `url_registered`, UNIX_TIMESTAMP(`last_locked`) AS `last_locked`, `lock_reason`, `views_max`, `views_allowed`, `fixed_reload` FROM `{?_MYSQL_PREFIX?}_surfbar_urls` @@ -684,12 +684,12 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) { } // END - if // Translate some data if present - if (isset($content['status'])) $content['status'] = translateSurfbarUrlStatus($content['status']); - if (isset($content['registered'])) $content['registered'] = generateDateTime($content['registered'], 2); - if (isset($content['last_locked'])) $content['last_locked'] = generateDateTime($content['last_locked'], 2); - if (isset($content['views_total'])) $content['views_total'] = translateComma($content['views_total']); - if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']); - if (isset($content['views_max'])) $content['views_max'] = translateComma($content['views_max']); + if (isset($content['status'])) $content['status'] = translateSurfbarUrlStatus($content['status']); + if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2); + if (isset($content['last_locked'])) $content['last_locked'] = generateDateTime($content['last_locked'], 2); + if (isset($content['views_total'])) $content['views_total'] = translateComma($content['views_total']); + if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']); + if (isset($content['views_max'])) $content['views_max'] = translateComma($content['views_max']); // Send the notification out return sendAdminNotification($subject, $templateName, $content, $content['userid']); @@ -717,12 +717,12 @@ function SURFBAR_NOTIFY_USER ($messageType, $content) { } // END - if // Translate some data if present - if (isset($content['status'])) $content['status'] = translateSurfbarUrlStatus($content['status']); - if (isset($content['registered'])) $content['registered'] = generateDateTime($content['registered'], 2); - if (isset($content['last_locked'])) $content['last_locked'] = generateDateTime($content['last_locked'], 2); - if (isset($content['views_total'])) $content['views_total'] = translateComma($content['views_total']); - if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']); - if (isset($content['views_max'])) $content['views_max'] = translateComma($content['views_max']); + if (isset($content['status'])) $content['status'] = translateSurfbarUrlStatus($content['status']); + if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2); + if (isset($content['last_locked'])) $content['last_locked'] = generateDateTime($content['last_locked'], 2); + if (isset($content['views_total'])) $content['views_total'] = translateComma($content['views_total']); + if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']); + if (isset($content['views_max'])) $content['views_max'] = translateComma($content['views_max']); // Load template $mailText = loadEmailTemplate($templateName, $content, $content['userid']); @@ -1445,14 +1445,25 @@ ORDER BY // "Getter" for maximum random number function SURFBAR_GET_MAX_RANDOM ($userids, $add) { // Count max availabe entries - $result = SQL_QUERY("SELECT sbu.id AS cnt -FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu -LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs -ON sbu.id=sbs.url_id -LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l -ON sbu.id=l.url_id -WHERE sbu.userid NOT IN (".implode(',', $userids).") AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND sbu.`status`='ACTIVE'".$add." -GROUP BY sbu.id", __FUNCTION__, __LINE__); + $result = SQL_QUERY("SELECT + sbu.id AS cnt +FROM + `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu +LEFT JOIN + `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs +ON + sbu.id=sbs.url_id +LEFT JOIN + `{?_MYSQL_PREFIX?}_surfbar_locks` AS l +ON + sbu.id=l.url_id +WHERE + sbu.userid NOT IN (".implode(',', $userids).") AND + (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND + sbu.`status`='ACTIVE' + ".$add." +GROUP BY + sbu.id ASC", __FUNCTION__, __LINE__); // Log last query //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false); @@ -1473,10 +1484,19 @@ function SURFBAR_GET_USER_URLS () { $URLs = array(); // Begin the query - $result = SQL_QUERY_ESC("SELECT u.id, u.userid, u.url, u.views_total, u.views_max, u.views_allowed, u.status, UNIX_TIMESTAMP(u.registered) AS registered, UNIX_TIMESTAMP(u.last_locked) AS last_locked, u.lock_reason AS lock_reason -FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS u -WHERE u.userid=%s AND u.status != 'DELETED' -ORDER BY u.id ASC", + $result = SQL_QUERY_ESC("SELECT + u.id, u.userid, u.url, u.status, + u.views_total, u.views_max, u.views_allowed, + UNIX_TIMESTAMP(u.registered) AS url_registered, + UNIX_TIMESTAMP(u.last_locked) AS last_locked, + u.lock_reason AS lock_reason +FROM + `{?_MYSQL_PREFIX?}_surfbar_urls` AS u +WHERE + u.userid=%s AND + u.status != 'DELETED' +ORDER BY + u.id ASC", array(getMemberId()), __FUNCTION__, __LINE__); // Are there entries? -- 2.39.5