r69968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69967‎ | r69968 | r69969 >
Date:20:36, 26 July 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Commits as per http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69713#c7931:
* Added proper variable declarations for class properties in PaypalIPNListener.php
* Created optional property to store a file system pointer resource which allows the listener to log directly to a file
Modified paths:
  • /trunk/extensions/DonationInterface/paypal_gateway/IPN/PaypalIPNListener.php (modified) (history)
  • /trunk/extensions/DonationInterface/paypal_gateway/IPN/StandaloneListener.php.example (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/paypal_gateway/IPN/PaypalIPNListener.php
@@ -49,21 +49,36 @@
5050
5151 class PaypalIPNProcessor {
5252
53 - // set the apropriate logging level
54 - $log_level = LOG_LEVEL_INFO;
 53+ /**
 54+ * @var string set the apropriate logging level
 55+ */
 56+ protected $log_level = LOG_LEVEL_INFO;
5557
56 - // path to Stomp
57 - $stomp_path = "../../activemq_stomp/Stomp.php";
 58+ /**
 59+ * @var string path to Stomp
 60+ */
 61+ protected $stomp_path = "../../activemq_stomp/Stomp.php";
5862
59 - // path to pending queue
60 - $pending_queue = '/queue/pending_paypal';
 63+ /**
 64+ * @var string path to pending queue
 65+ */
 66+ protected $pending_queue = '/queue/pending_paypal';
6167
62 - // path to the verified queue
63 - $verified_queue = '/queue/donations';
 68+ /**
 69+ * @var string path to the verified queue
 70+ */
 71+ protected $verified_queue = '/queue/donations';
6472
65 - // URI to activeMQ
66 - $activemq_stomp_uri = 'tcp://localhost:61613';
 73+ /**
 74+ * @var string URI to activeMQ
 75+ */
 76+ protected $activemq_stomp_uri = 'tcp://localhost:61613';
6777
 78+ /**
 79+ * @var resource a file system pointer resource (usually made with fopen())
 80+ */
 81+ protected $output_handle = NULL;
 82+
6883 /**
6984 * Class constructor, sets configurable parameters
7085 *
@@ -77,8 +92,14 @@
7893 unset( $opts[ 'log_level'] );
7994 }
8095
81 - $this->out( "Loading Paypal IPN processor" );
 96+ // prepare the output log file if necessary
 97+ if ( array_key_exists( 'output_handle', $opts )) {
 98+ $this->output_handle = $opts[ 'output_handle' ];
 99+ unset( $opts[ 'output_handle' ] );
 100+ }
82101
 102+ $this->out( "Loading Paypal IPN processor with log level: " . $this->log_level );
 103+
83104 // set parameters
84105 foreach ( $opts as $key => $value ) {
85106 $this->{$key} = $value;
@@ -371,7 +392,17 @@
372393 * @param $level the Level at which the message should be output.
373394 */
374395 protected function out( $msg, $level=LOG_LEVEL_INFO ) {
375 - if ( $this->log_level >= $level ) echo date( 'c' ) . ": " . $msg . "\n";
 396+ $out = NULL;
 397+
 398+ // format the output message if the apropriate log level is set
 399+ if ( $this->log_level >= $level ) $out = date( 'c' ) . ": " . $msg . "\n";
 400+
 401+ // if we have an output resource handle, write to the resource. otherwise, echo
 402+ if ( $this->output_handle ) {
 403+ fwrite( $this->output_handle, $out );
 404+ } else {
 405+ echo $out;
 406+ }
376407 }
377408
378409 public function __destruct() {
Index: trunk/extensions/DonationInterface/paypal_gateway/IPN/StandaloneListener.php.example
@@ -11,9 +11,12 @@
1212 * @author Arthur Richards <arichards@wikimedia.org>
1313 */
1414
15 -// turn on output buffering so we can capture the output
16 -ob_start();
1715
 16+// define a file where you can log the output from the listener
 17+$log_file = "out_" . date( 'Ymd' ) . '.log';
 18+// create a file resource pointer
 19+$output_handle = fopen( $log_file, 'a' );
 20+
1821 // require the actual listener
1922 require_once( '/path/to/PaypalIPNListener.php' );
2023
@@ -28,10 +31,9 @@
2932 'contrib_db_username' => 'user',
3033 'contrib_db_password' => 'password',
3134 'contrib_db_name' => 'drupal',
 35+ 'output_handle' => $output_handle, // filesystem pointer resource for logging output
3236 );
3337
34 -// define a file where you can log the output from the listener
35 -$log_file = "out_" . date( 'Ymd' ) . '.log'; //for logging the output
3638
3739 // instantaite the listener with our config options
3840 $listener = new PaypalIPNProcessor( $config );
@@ -42,13 +44,6 @@
4345 // shutdown the listener
4446 unset( $listener );
4547
46 -// get the output from the buffer
47 -$output = ob_get_clean();
48 -ob_flush();
49 -
50 -// open our log file
51 -$handle = fopen( $log_file, 'a' );
52 -
53 -// write the output to the log file
54 -fwrite( $handle, $output );
 48+// cleanly close the file pointer for output
 49+fclose( $output_handle );
5550 ?>

Status & tagging log