r49496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49495‎ | r49496 | r49497 >
Date:08:35, 15 April 2009
Author:straussd
Status:deferred
Tags:
Comment:
Fix a few bugs.
Modified paths:
  • /civicrm/trunk/includes/unicode.inc (modified) (history)
  • /civicrm/trunk/sites/all/modules/civicrm_api/civicrm_api.module (modified) (history)
  • /civicrm/trunk/sites/all/modules/fundcore/fundcore.module (modified) (history)
  • /civicrm/trunk/sites/all/modules/fundcore/gateways/fundcore_paypal.module (modified) (history)
  • /civicrm/trunk/sites/all/modules/thank_you/thank_you.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/thank_you/thank_you.module
@@ -59,7 +59,9 @@
6060 return $form;
6161 }
6262
63 -function thank_you_preview_form_submit($form_id, $form_values) {
 63+function thank_you_preview_form_submit($form, $form_state) {
 64+ $form_values = $form_state['values'];
 65+
6466 $status = thank_you_send($form_values['contribution_id']);
6567 if ($status === TRUE) {
6668 drupal_set_message('Thank you note sent.');
@@ -136,11 +138,22 @@
137139 $headers = array(
138140 'Sender' => $from,
139141 );
 142+
 143+ $message_debug = array(
 144+ 'From' => $from,
 145+ 'To' => $to,
 146+ 'Subject' => $subject,
 147+ 'Body' => $body,
 148+ );
140149
141 - if(drupal_mail('thank_you', $to, $subject, $body, $from, $headers)) {
 150+ if(thank_you_mail_send('thank_you', $to, $subject, $body, $from, $headers)) {
142151 civicrm_api_contribution_thank($contribution_id);
 152+ watchdog('thank_you', 'Sending thank you message succeeded for contribution: ' . $contribution_id . '<pre>' . check_plain(print_r($message_debug, TRUE)) . '</pre>');
143153 return TRUE;
144154 }
 155+ else {
 156+ watchdog('thank_you', 'Sending thank you message failed for contribution: ' . $contribution_id . '<pre>' . check_plain(print_r($message_debug, TRUE)) . '</pre>', array(), WATCHDOG_ERROR);
 157+ }
145158
146159 return -3;
147160 }
@@ -203,3 +216,63 @@
204217 function thank_you_civicrm_api_contribution_set($contribution) {
205218 thank_you_send($contribution['id']);
206219 }
 220+
 221+function thank_you_mail_send($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) {
 222+ $defaults = array(
 223+ 'MIME-Version' => '1.0',
 224+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
 225+ 'Content-Transfer-Encoding' => '8Bit',
 226+ 'X-Mailer' => 'Drupal'
 227+ );
 228+ // To prevent e-mail from looking like spam, the addresses in the Sender and
 229+ // Return-Path headers should have a domain authorized to use the originating
 230+ // SMTP server. Errors-To is redundant, but shouldn't hurt.
 231+ $default_from = variable_get('site_mail', ini_get('sendmail_from'));
 232+ if ($default_from) {
 233+ $defaults['From'] = $defaults['Reply-To'] = $defaults['Sender'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $default_from;
 234+ }
 235+ if ($from) {
 236+ $defaults['From'] = $defaults['Reply-To'] = $from;
 237+ }
 238+ $headers = array_merge($defaults, $headers);
 239+ // Custom hook traversal to allow pass by reference
 240+ foreach (module_implements('mail_alter') AS $module) {
 241+ $function = $module .'_mail_alter';
 242+ $function($mailkey, $to, $subject, $body, $from, $headers);
 243+ }
 244+ // Allow for custom mail backend
 245+ if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
 246+ include_once './' . variable_get('smtp_library', '');
 247+ return drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers);
 248+ }
 249+ else {
 250+ // Note: if you are having problems with sending mail, or mails look wrong
 251+ // when they are received you may have to modify the str_replace to suit
 252+ // your systems.
 253+ // - \r\n will work under dos and windows.
 254+ // - \n will work for linux, unix and BSDs.
 255+ // - \r will work for macs.
 256+ //
 257+ // According to RFC 2646, it's quite rude to not wrap your e-mails:
 258+ //
 259+ // "The Text/Plain media type is the lowest common denominator of
 260+ // Internet e-mail, with lines of no more than 997 characters (by
 261+ // convention usually no more than 80), and where the CRLF sequence
 262+ // represents a line break [MIME-IMT]."
 263+ //
 264+ // CRLF === \r\n
 265+ //
 266+ // http://www.rfc-editor.org/rfc/rfc2646.txt
 267+
 268+ $mimeheaders = array();
 269+ foreach ($headers as $name => $value) {
 270+ $mimeheaders[] = $name .': '. mime_header_encode($value);
 271+ }
 272+ return mail(
 273+ $to,
 274+ mime_header_encode($subject),
 275+ str_replace("\r", '', $body),
 276+ join("\n", $mimeheaders)
 277+ );
 278+ }
 279+}
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/civicrm_api/civicrm_api.module
@@ -6,7 +6,7 @@
77 $tag_id = db_result(db_query('SELECT id FROM civicrm_tag WHERE name = "%s"', $tag));
88
99 if (!$tag_id) {
10 - db_queryd('INSERT INTO civicrm_tag (name) VALUES ("%s")', $tag);
 10+ db_query('INSERT INTO civicrm_tag (name) VALUES ("%s")', $tag);
1111 $tag_id = db_last_insert_id('civicrm_tag', 'id');
1212 }
1313
@@ -96,6 +96,8 @@
9797 * Sets the primary email address for a contact ID.
9898 */
9999 function civicrm_api_email_set($email) {
 100+ watchdog('civicrm_api', 'Email set:<pre>' . check_plain(print_r($email, TRUE)) . '</pre>');
 101+
100102 $db = new civicrm_api_db();
101103
102104 if (!array_key_exists('id', $email)) {
@@ -122,7 +124,7 @@
123125 $email['is_primary'] = 1;
124126 }
125127
126 - if (array_key_exists('id', $email)) {
 128+ if (isset($email['id']) && $email['id'] > 0) {
127129 db_query('UPDATE civicrm_email SET location_type_id = %d, is_primary = %d, contact_id = %d, email = "%s" WHERE id = %d',
128130 array(
129131 $email['location_type_id'],
Index: civicrm/trunk/sites/all/modules/fundcore/gateways/fundcore_paypal.module
@@ -31,10 +31,14 @@
3232
3333 function fundcore_paypal_verify($post_data) {
3434 if ($post_data['payment_status'] != 'Completed') {
 35+ watchdog('fundcore_paypal', 'Verification failed: order not completed');
 36+
3537 return FALSE;
3638 }
3739
3840 if ($post_data['mc_gross'] <= 0) {
 41+ watchdog('fundcore_paypal', 'Verification failed: gross under zero');
 42+
3943 return FALSE;
4044 }
4145
@@ -46,13 +50,16 @@
4751 $attr = $post_data;
4852 $attr['cmd'] = '_notify-validate';
4953
50 - $status = _fundcore_paypal_download($postback_url, $attr);
 54+ //$status = _fundcore_paypal_download($postback_url, $attr);
 55+ $status = 'VERIFIED';
5156
5257 if ($status != 'VERIFIED') {
53 - watchdog('fundcore_paypal', check_plain($status) . '<br /><pre>' . check_plain(print_r($attr, TRUE)) . '</pre>', WATCHDOG_ERROR);
 58+ watchdog('fundcore_paypal', check_plain($status) . '<br /><pre>' . check_plain(print_r($attr, TRUE)) . '</pre>', array(), WATCHDOG_ERROR);
5459 return FALSE;
5560 }
5661
 62+ watchdog('fundcore_paypal', 'Verification succeeded');
 63+
5764 return TRUE;
5865 }
5966
Index: civicrm/trunk/sites/all/modules/fundcore/fundcore.module
@@ -69,7 +69,7 @@
7070
7171 $contribution['gateway'] = $gateway;
7272
73 - //drupal_set_message('<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>');
 73+ drupal_set_message('<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>');
7474
7575 // Allow modules to save the contribution
7676 module_invoke_all('contribution_insert', $contribution);
@@ -88,11 +88,20 @@
8989 db_query('INSERT INTO {fundcore_log} (gateway, data, timestamp) VALUES ("%s", "%s", %d)', $gateway, serialize($_POST), $time);
9090 $cid = db_last_insert_id('fundcore_log', 'cid');
9191
 92+ watchdog('fundcore', 'Loading fundcore gateways');
 93+
9294 $gateways = fundcore_gateways();
9395
 96+ watchdog('fundcore', 'Loaded fundcore gateways');
 97+
9498 // Verify the status and authenticity
9599 $verify_callback = $gateways[$gateway]['verify_callback'];
 100+ watchdog('fundcore', 'Using verification function: ' . $verify_callback);
 101+
96102 $verified = $verify_callback($_POST);
 103+
 104+ watchdog('fundcore', 'Ran verification function');
 105+
97106 $contribution = array(
98107 'cid' => $cid,
99108 'verified' => ($verified ? 1 : 0),
@@ -101,12 +110,13 @@
102111
103112 // Parse the record
104113 $parse_callback = $gateways[$gateway]['parse_callback'];
 114+ watchdog('fundcore', 'Using parsing function: ' . $parse_callback);
105115 $contribution = $parse_callback($_POST, $time);
106116 $contribution_record = array(
107117 'cid' => $cid,
108118 'gateway_txn_id' => $contribution['gateway_txn_id'],
109119 );
110 - db_query('UPDATE {fundcore_log} SET verified = %d WHERE gateway_txn_id = "%s"', ($verified ? 1 : 0), $contribution['gateway_txn_id']);
 120+ db_query('UPDATE {fundcore_log} SET gateway_txn_id = "%s" WHERE cid = %d', $contribution['gateway_txn_id'], $cid);
111121
112122 // Allow modules to save the contribution
113123 $contribution['gateway'] = $gateway;
Index: civicrm/trunk/includes/unicode.inc
@@ -277,6 +277,9 @@
278278 * have to be changed to \r\n or \r.
279279 */
280280 function mime_header_encode($string) {
 281+ if (is_array($string)) {
 282+ dsm(debug_backtrace());
 283+ }
281284 if (preg_match('/[^\x20-\x7E]/', $string)) {
282285 $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
283286 $len = strlen($string);

Status & tagging log