<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2083] sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments: WordCamp.org: Add some basic logging to our payment requests plugin.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/2083">2083</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/2083","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>kovshenin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-11-16 13:16:20 +0000 (Mon, 16 Nov 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp.org: Add some basic logging to our payment requests plugin.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsclassespaymentrequestphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/payment-request.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsclasseswordcamppaymentsphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/wordcamp-payments.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentscsswordcamppaymentscss">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-payments.css</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewspaymentrequestmetaboxlogphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-log.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsclassespaymentrequestphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/payment-request.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/payment-request.php 2015-11-14 08:00:10 UTC (rev 2082)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/payment-request.php 2015-11-16 13:16:20 UTC (rev 2083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,6 +19,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'wp_insert_post_data', array( $this, 'update_request_status' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'save_post', array( $this, 'save_payment' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'map_meta_cap', array( $this, 'modify_capabilities' ), 10, 4 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Columns
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'manage_'. self::POST_TYPE .'_posts_columns', array( $this, 'get_columns' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,6 +165,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'normal',
</span><span class="cx" style="display: block; padding: 0 10px"> 'high'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ add_meta_box( 'wcp_log', __( 'Log', 'wordcamporg' ), array( $this, 'render_log_metabox' ),
+ self::POST_TYPE, 'normal', 'high' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -250,6 +254,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Render the Log metabox
+ *
+ * @param WP_Post $post
+ */
+ public function render_log_metabox( $post ) {
+ $log = get_post_meta( $post->ID, '_wcp_log', true );
+ if ( empty( $log ) )
+ $log = '[]';
+
+ $log = json_decode( $log, true );
+
+ // I wish I had a spaceship.
+ uasort( $log, function( $a, $b ) {
+ if ( $b['timestamp'] == $a )
+ return 0;
+
+ return ( $a['timestamp'] < $b['timestamp'] ) ? -1 : 1;
+ });
+
+ require_once( dirname( __DIR__ ) . '/views/payment-request/metabox-log.php' );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Render a <textarea> field with the given attributes.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post $post
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -657,6 +684,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->should_mark_request_incomplete() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_data['post_status'] = 'incomplete';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->notify_requester_request_incomplete( $post_data_raw['ID'], $post_data, $post_data_raw );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ update_post_meta( $post_data_raw['ID'], '_wcp_incomplete_notes', sanitize_text_field( $post_data_raw['wcp_mark_incomplete_notes'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $previous_status = $post_data['post_status'];
</span><span class="cx" style="display: block; padding: 0 10px"> $post_data['post_status'] = strtotime( sanitize_text_field( $_POST['date_vendor_paid'] ) ) ? 'paid' : 'unpaid';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -900,6 +929,40 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->attach_existing_files( $post_id, $_POST );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function transition_post_status( $new, $old, $post ) {
+ if ( $post->post_type != self::POST_TYPE )
+ return;
+
+ $user = get_user_by( 'id', get_current_user_id() );
+ if ( $new == 'auto-draft' )
+ return;
+
+ if ( $new == 'incomplete' && $old != 'incomplete' ) {
+ $incomplete_text = get_post_meta( $post->ID, '_wcp_incomplete_notes', true );
+ $incomplete_text = preg_replace( '#\.$#', '', $incomplete_text ); // trailing-undot-it.
+ WordCamp_Payments::log( $post->ID, sprintf( 'Marked as incomplete by %s: %s.', $user->display_name, $incomplete_text ), array(
+ 'user_id' => $user->ID,
+ 'action' => 'marked-incomplete',
+ 'reason' => 'maybe notes',
+ ) );
+ } elseif ( $new == 'paid' && $old != 'paid' ) {
+ WordCamp_Payments::log( $post->ID, sprintf( 'Marked as paid by %s.', $user->display_name ), array(
+ 'user_id' => $user->ID,
+ 'action' => 'marked-paid',
+ ) );
+ } elseif ( $old == 'auto-draft' && $new != 'auto-draft' ) {
+ WordCamp_Payments::log( $post->ID, sprintf( 'Request created by %s.', $user->display_name ), array(
+ 'user_id' => $user->ID,
+ 'action' => 'updated',
+ ) );
+ } else {
+ WordCamp_Payments::log( $post->ID, sprintf( 'Request updated by %s.', $user->display_name ), array(
+ 'user_id' => $user->ID,
+ 'action' => 'updated',
+ ) );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Attach unattached files to the payment request post
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsclasseswordcamppaymentsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/wordcamp-payments.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/wordcamp-payments.php 2015-11-14 08:00:10 UTC (rev 2082)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/wordcamp-payments.php 2015-11-16 13:16:20 UTC (rev 2083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,7 +10,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Constructor
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ), 11 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,10 +38,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> true
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Let's still include our .css file even if these are unavailable.
+ $soft_deps = array( 'jquery-ui', 'wp-datepicker-skins' );
+ foreach ( $soft_deps as $key => $handle )
+ if ( ! wp_style_is( $handle, 'registered' ) )
+ unset( $soft_deps[ $key ] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_register_style(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wordcamp-payments',
</span><span class="cx" style="display: block; padding: 0 10px"> plugins_url( 'css/wordcamp-payments.css', __DIR__ ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array( 'jquery-ui', 'wp-datepicker-skins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $soft_deps,
</ins><span class="cx" style="display: block; padding: 0 10px"> self::VERSION
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -67,4 +73,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Log something with a payment request.
+ *
+ * @param int $post_id The payment requset ID.
+ * @param string $message A log message.
+ * @param array $data Optional data.
+ */
+ public static function log( $post_id, $message, $data = array() ) {
+ global $wpdb;
+
+ $entry = array(
+ 'timestamp' => time(),
+ 'message' => $message,
+ 'data' => $data,
+ );
+
+ $log = get_post_meta( $post_id, '_wcp_log', true );
+ if ( empty( $log ) )
+ $log = '[]';
+
+ $log = json_decode( $log, true );
+ $log[] = $entry;
+ $log = json_encode( $log );
+
+ update_post_meta( $post_id, '_wcp_log', wp_slash( $log ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentscsswordcamppaymentscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-payments.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-payments.css 2015-11-14 08:00:10 UTC (rev 2082)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-payments.css 2015-11-16 13:16:20 UTC (rev 2083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,3 +26,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> .form-table td p.wcp_no_files_uploaded {
</span><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 1em;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+#wcp_log .inside {
+ margin: 0;
+ padding: 0;
+}
+
+#wcp_log .wcp-request-log {
+ border-collapse: collapse;
+ width: 100%;
+}
+
+#wcp_log .wcp-request-log td {
+ padding: 8px;
+}
+
+#wcp_log td.timestamp {
+ width: 130px;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewspaymentrequestmetaboxlogphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-log.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-log.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-log.php 2015-11-16 13:16:20 UTC (rev 2083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,16 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php if ( ! empty( $log ) ) : ?>
+ <table class="wcp-request-log striped">
+ <?php foreach ( $log as $entry ) : ?>
+ <tr>
+ <td class="timestamp">
+ <?php echo gmdate( 'Y-m-d H:i:s', absint( $entry['timestamp'] ) ); ?>
+ </td>
+ <td>
+ <?php echo esc_html( $entry['message'] ); ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </table>
+<?php else : ?>
+ <p><?php _e( 'Nothing in the log yet.', 'wordcamporg' ); ?></p>
+<?php endif; ?>
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>