Пример #1
0
/**
 * Maybe log a recommendation sale
 * Iterates through items in the payment and if one is a recommendation logs it
 *
 * @since  1.2.6
 * @param  int $payment_id The Payment ID being completed
 * @return void
 */
function edd_rp_log_recommendation_sale($payment_id)
{
    $payment_items = edd_get_payment_meta_cart_details($payment_id, true);
    foreach ($payment_items as $item) {
        if (!empty($item['item_number']['recommendation_source'])) {
            $edd_log = new EDD_Logging();
            $log_data = array('post_parent' => $item['item_number']['recommendation_source'], 'post_date' => edd_get_payment_completed_date($payment_id), 'log_type' => 'recommendation_sale');
            $log_meta = array('payment_id' => $payment_id, 'download_id' => $item['id'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'item_price' => $item['item_price']);
            $log_entry = $edd_log->insert_log($log_data, $log_meta);
        }
    }
}
/**
 * Converts old sale and file download logs to new logging system
 *
 * @since 1.3.1
 * @uses WP_Query
 * @uses EDD_Logging
 * @return void
 */
function edd_v131_upgrades()
{
    if (get_option('edd_logs_upgraded')) {
        return;
    }
    if (version_compare(get_option('edd_version'), '1.3', '>=')) {
        return;
    }
    ignore_user_abort(true);
    if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $args = array('post_type' => 'download', 'posts_per_page' => -1, 'post_status' => 'publish');
    $query = new WP_Query($args);
    $downloads = $query->get_posts();
    if ($downloads) {
        $edd_log = new EDD_Logging();
        foreach ($downloads as $download) {
            // Convert sale logs
            $sale_logs = edd_get_download_sales_log($download->ID, false);
            if ($sale_logs) {
                foreach ($sale_logs['sales'] as $sale) {
                    $log_data = array('post_parent' => $download->ID, 'post_date' => $sale['date'], 'log_type' => 'sale');
                    $log_meta = array('payment_id' => $sale['payment_id']);
                    $log = $edd_log->insert_log($log_data, $log_meta);
                }
            }
            // Convert file download logs
            $file_logs = edd_get_file_download_log($download->ID, false);
            if ($file_logs) {
                foreach ($file_logs['downloads'] as $log) {
                    $log_data = array('post_parent' => $download->ID, 'post_date' => $log['date'], 'log_type' => 'file_download');
                    $log_meta = array('user_info' => $log['user_info'], 'file_id' => $log['file_id'], 'ip' => $log['ip']);
                    $log = $edd_log->insert_log($log_data, $log_meta);
                }
            }
        }
    }
    add_option('edd_logs_upgraded', '1');
}