Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm.module |
— | — | @@ -27,6 +27,12 @@ |
28 | 28 | 'type' => MENU_LOCAL_TASK, |
29 | 29 | ); |
30 | 30 | |
| 31 | + $items['queue2civicrm'] = array( |
| 32 | + 'access callback' => TRUE, |
| 33 | + 'type' => MENU_CALLBACK, |
| 34 | + 'page callback' => 'queue2civicrm_batch_process', |
| 35 | + ); |
| 36 | + |
31 | 37 | return $items; |
32 | 38 | } |
33 | 39 | |
— | — | @@ -98,6 +104,12 @@ |
99 | 105 | * Implementation of hook_cron(). |
100 | 106 | */ |
101 | 107 | function queue2civicrm_cron() { |
| 108 | + queue2civicrm_batch_process(); |
| 109 | +} |
| 110 | + |
| 111 | +function queue2civicrm_batch_process() { |
| 112 | + set_time_limit(10); |
| 113 | + |
102 | 114 | $processed = 0; |
103 | 115 | |
104 | 116 | watchdog('queue2civicrm', 'Attempting to process up to ' . variable_get('queue2civicrm_batch', 0) . ' contribution(s).'); |
— | — | @@ -157,12 +169,15 @@ |
158 | 170 | function queue2civicrm_dequeue() { |
159 | 171 | $con = _queue2civicrm_stomp_connection(); |
160 | 172 | |
161 | | - if ($con) { |
| 173 | + if ($con) { |
162 | 174 | $con->subscribe(variable_get('queue2civicrm_subscription', '/queue/test')); |
| 175 | + |
163 | 176 | $msg = $con->readFrame(); |
164 | 177 | |
165 | 178 | // Skip processing if no message to process. |
166 | 179 | if ($msg !== FALSE) { |
| 180 | + watchdog('queue2civicrm', 'Read frame:<pre>' . check_plain(print_r($msg, TRUE)) . '</pre>'); |
| 181 | + set_time_limit(60); |
167 | 182 | try { |
168 | 183 | queue2civicrm_import($msg); |
169 | 184 | // Confirm successful processing of message. |
— | — | @@ -173,6 +188,9 @@ |
174 | 189 | watchdog('queue2civicrm', 'Could not process frame from queue.', array(), WATCHDOG_ERROR); |
175 | 190 | } |
176 | 191 | } |
| 192 | + else { |
| 193 | + watchdog('queue2civicrm', 'Nothing to process.'); |
| 194 | + } |
177 | 195 | } |
178 | 196 | |
179 | 197 | return FALSE; |
— | — | @@ -189,9 +207,18 @@ |
190 | 208 | if (!is_integer($contribution['date'])) { |
191 | 209 | $contribution['date'] = strtotime($contribution['date']); |
192 | 210 | } |
| 211 | + |
| 212 | + watchdog('queue2civicrm', 'Contribution (pre-conversion):<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>'); |
193 | 213 | |
194 | | - dsm($contribution); |
195 | | - |
| 214 | + $contribution['fee'] = exchange_rate_convert($contribution['currency'], $contribution['fee'], $contribution['date']); |
| 215 | + $contribution['gross'] = exchange_rate_convert($contribution['currency'], $contribution['gross'], $contribution['date']); |
| 216 | + $contribution['net'] = exchange_rate_convert($contribution['currency'], $contribution['net'], $contribution['date']); |
| 217 | + |
| 218 | + $contribution['gateway_txn_id'] .= ' ' . time(); |
| 219 | + |
| 220 | + //dsm($contribution); |
| 221 | + watchdog('queue2civicrm', 'Contribution:<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>'); |
| 222 | + |
196 | 223 | // Save the contribution. |
197 | 224 | fundcore_civicrm_contribution_insert($contribution); |
198 | 225 | } |
Index: civicrm/trunk/sites/all/modules/queue2civicrm/Stomp.php |
— | — | @@ -515,17 +515,22 @@ |
516 | 516 | return false; |
517 | 517 | } |
518 | 518 | |
| 519 | + stream_set_timeout($this->_socket, 5); |
519 | 520 | $rb = 1024; |
520 | 521 | $data = ''; |
521 | 522 | do { |
522 | 523 | $read = fgets($this->_socket, $rb); |
523 | | - if ($read === false) { |
524 | | - $this->_reconnect(); |
525 | | - return $this->readFrame(); |
| 524 | + $info = stream_get_meta_data($this->_socket); |
| 525 | + if ($info['timed_out']) { |
| 526 | + return FALSE; |
526 | 527 | } |
| 528 | + //if ($read === false) { |
| 529 | + // $this->_reconnect(); |
| 530 | + // return $this->readFrame(); |
| 531 | + //} |
527 | 532 | $data .= $read; |
528 | 533 | $len = strlen($data); |
529 | | - } while (($len < 2 || ! ($data[$len - 2] == "\x00" && $data[$len - 1] == "\n"))); |
| 534 | + } while ($read && ($len < 2 || ! ($data[$len - 2] == "\x00" && $data[$len - 1] == "\n"))); |
530 | 535 | |
531 | 536 | list ($header, $body) = explode("\n\n", $data, 2); |
532 | 537 | $header = explode("\n", $header); |