Skip to content

Commit

Permalink
Use getters for logs instead of directly accessing properties. #3841
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyratilal committed Apr 15, 2018
1 parent 6b02082 commit c0055e3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 41 deletions.
20 changes: 11 additions & 9 deletions includes/admin/reporting/class-api-requests-logs-list-table.php
Expand Up @@ -256,16 +256,18 @@ public function get_logs() {

if ( $logs ) {
foreach ( $logs as $log ) {
/** @var $log EDD\Logs\Api_Request_Log */

$logs_data[] = array(
'ID' => $log->id,
'version' => $log->version,
'speed' => $log->time,
'ip' => $log->ip,
'date' => $log->date_created,
'api_key' => $log->api_key,
'request' => $log->request,
'error' => $log->error,
'user_id' => $log->user_id,
'ID' => $log->get_id(),
'version' => $log->get_version(),
'speed' => $log->get_time(),
'ip' => $log->get_ip(),
'date' => $log->get_date_created(),
'api_key' => $log->get_api_key(),
'request' => $log->get_request(),
'error' => $log->get_error(),
'user_id' => $log->get_user_id(),
);
}
}
Expand Down
40 changes: 21 additions & 19 deletions includes/admin/reporting/class-file-downloads-logs-list-table.php
Expand Up @@ -295,7 +295,7 @@ public function get_meta_query() {
}

if ( ! $this->file_search ) {
// Meta query only works for non file name searche
// Meta query only works for non file name search
$meta_query[] = array(
'key' => $key,
'value' => $search,
Expand Down Expand Up @@ -383,34 +383,36 @@ function get_logs() {

if ( $logs ) {
foreach ( $logs as $log ) {
$customer_id = edd_get_payment_customer_id( $log->payment_id );
/** @var $log EDD\Logs\File_Download_Log */

if ( ! array_key_exists( $log->download_id, $this->queried_files ) ) {
$files = maybe_unserialize( $wpdb->get_var( $wpdb->prepare( "SELECT meta_value from $wpdb->postmeta WHERE post_id = %d and meta_key = 'edd_download_files'", $log->post_parent ) ) );
$this->queried_files[ $log->download_id ] = $files;
$customer_id = edd_get_payment_customer_id( $log->get_payment_id() );

if ( ! array_key_exists( $log->get_download_id(), $this->queried_files ) ) {
$files = get_post_meta( $log->get_download_id(), 'edd_download_files', true );
$this->queried_files[ $log->get_download_id() ] = $files;
} else {
$files = $this->queried_files[ $log->download_id ];
$files = $this->queried_files[ $log->get_download_id() ];
}

// For backwards compatibility purposes
$user = get_userdata( $log->user_id );
$user = get_userdata( $log->get_user_id() );
$meta = array(
'_edd_log_user_info' => array(
'id' => $user->ID,
'email' => $user->user_email,
'name' => $user->display_name,
),
'_edd_log_user_id' => $log->user_id,
'_edd_log_file_id' => $log->file_id,
'_edd_log_ip' => $log->ip,
'_edd_log_payment_id' => $log->payment_id,
'_edd_log_price_id' => $log->price_id,
'_edd_log_user_id' => $log->get_user_id(),
'_edd_log_file_id' => $log->get_file_id(),
'_edd_log_ip' => $log->get_id(),
'_edd_log_payment_id' => $log->get_payment_id(),
'_edd_log_price_id' => $log->get_price_id(),
);

// Filter the download files
$files = apply_filters( 'edd_log_file_download_download_files', $files, $log, $meta );

$file_id = $log->file_id;
$file_id = $log->get_file_id();

// Filter the $file_id
$file_id = apply_filters( 'edd_log_file_download_file_id', $file_id, $log );
Expand All @@ -419,14 +421,14 @@ function get_logs() {

if ( ( $this->file_search && strpos( strtolower( $file_name ), strtolower( $this->get_search() ) ) !== false ) || ! $this->file_search ) {
$logs_data[] = array(
'ID' => $log->id,
'download' => $log->download_id,
'ID' => $log->get_id(),
'download' => $log->get_download_id(),
'customer' => new EDD_Customer( $customer_id ),
'payment_id' => $log->payment_id,
'price_id' => $log->price_id,
'payment_id' => $log->get_payment_id(),
'price_id' => $log->get_price_id(),
'file' => $file_name,
'ip' => $log->ip,
'date' => $log->post_date,
'ip' => $log->get_ip(),
'date' => $log->get_date_created(),
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions includes/admin/reporting/class-gateway-error-logs-list-table.php
Expand Up @@ -158,8 +158,6 @@ public function bulk_actions( $which = '' ) {
* @return array $logs_data Array of all the Log entires
*/
public function get_logs() {
global $edd_logs;

// Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
wp_suspend_cache_addition( true );

Expand All @@ -175,12 +173,14 @@ public function get_logs() {

if ( $logs ) {
foreach ( $logs as $log ) {
/** @var $log EDD\Logs\Log */

$logs_data[] = array(
'ID' => $log->ID,
'payment_id' => $log->post_parent,
'ID' => $log->get_id(),
'payment_id' => $log->get_object_id(),
'error' => 'error',
'gateway' => edd_get_payment_gateway( $log->post_parent ),
'date' => $log->post_date,
'gateway' => edd_get_payment_gateway( $log->get_object_id() ),
'date' => $log->get_date_created(),
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions includes/admin/reporting/class-sales-logs-list-table.php
Expand Up @@ -335,7 +335,7 @@ public function get_logs() {
if ( is_array( $cart_items ) ) {
foreach ( $cart_items as $item ) {
// If the item has variable pricing, make sure it's the right variation
if ( $item['id'] == $log->object_id ) {
if ( $item['id'] == $log->get_object_id() ) {
if ( isset( $item['item_number']['options']['price_id'] ) ) {
$log_price_id = $log->get_meta( 'price_id' );

Expand All @@ -350,10 +350,10 @@ public function get_logs() {
}

$logs_data[] = array(
'ID' => $log->ID,
'ID' => $log->get_id(),
'payment_id' => $payment->ID,
'customer' => $customer,
'download' => $log->object_id,
'download' => $log->get_object_id(),
'price_id' => isset( $log_price_id ) ? $log_price_id : null,
'item_price' => isset( $item['item_price'] ) ? $item['item_price'] : $item['price'],
'amount' => $amount,
Expand Down
28 changes: 24 additions & 4 deletions includes/logs/class-api-request-log.php
Expand Up @@ -25,7 +25,7 @@ class Api_Request_Log extends Base_Object {
/**
* API request log ID.
*
* @since 3.0
* @since 3.0.0
* @access protected
* @var int
*/
Expand All @@ -34,7 +34,7 @@ class Api_Request_Log extends Base_Object {
/**
* User ID.
*
* @since 3.0
* @since 3.0.0
* @access protected
* @var int
*/
Expand All @@ -43,7 +43,7 @@ class Api_Request_Log extends Base_Object {
/**
* API key.
*
* @since 3.0
* @since 3.0.0
* @access protected
* @var string
*/
Expand All @@ -70,12 +70,21 @@ class Api_Request_Log extends Base_Object {
/**
* API request.
*
* @since 3.0
* @since 3.0.0
* @access protected
* @var string
*/
protected $request;

/**
* Request errors.
*
* @since 3.0.0
* @access protected
* @var string
*/
protected $error;

/**
* IP.
*
Expand Down Expand Up @@ -169,6 +178,17 @@ public function get_request() {
return $this->request;
}

/**
* Retrieve any errors for the API request.
*
* @since 3.0.0
*
* @return string
*/
public function get_error() {
return $this->error;
}

/**
* Retrieve IP address of the client making the API request.
*
Expand Down

0 comments on commit c0055e3

Please sign in to comment.