HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah_err/wp-content/plugins/give/src/Revenue/Repositories/Revenue.php
<?php

namespace Give\Revenue\Repositories;

use Give\Donations\Models\Donation;
use Give\Framework\Database\DB;
use Give\Framework\Exceptions\Primitives\InvalidArgumentException;

/**
 * Class Revenue
 * @package    Give\Revenue\Repositories
 *
 * Use this class to get data from "give_revenue" table.
 *
 * @since      2.9.0
 * @since 2.22.1 Added the `updateRevenueAmount()` method
 */
class Revenue
{
    /**
     * Insert revenue.
     *
     * @since 2.9.0
     *
     * @param array $revenueData
     *
     * @return bool|int
     */
    public function insert($revenueData)
    {
        global $wpdb;

        // Validate revenue data
        $this->validateNewRevenueData($revenueData);

        /**
         * Filter revenue data before inserting to revenue table.
         *
         * @since 2.9.0
         */
        $revenueData = apply_filters('give_revenue_insert_data', $revenueData);

        return DB::insert(
            $wpdb->give_revenue,
            $revenueData,
            $this->getPlaceholderForPrepareQuery($revenueData)
        );
    }

    /**
     * Deletes revenue
     *
     * @param $revenueId
     *
     * @return false|int
     */
    public function deleteByDonationId($revenueId)
    {
        global $wpdb;

        return DB::delete(
            $wpdb->give_revenue,
            ['donation_id' => $revenueId],
            ['%d']
        );
    }

    /**
     * @since 2.22.1
     *
     * @param Donation $donation
     *
     * @return false|int
     */
    public function updateRevenueAmount(Donation $donation)
    {
        global $wpdb;

        return DB::update(
            $wpdb->give_revenue,
            ['amount' => $donation->amount->formatToMinorAmount()],
            ['donation_id' => $donation->id],
            ['%d'],
            ['%d']
        );
    }

    /**
     * @since 4.1.0
     *
     * @return false|int
     */
    public function updateRevenueCampaignId(Donation $donation)
    {
        global $wpdb;

        return DB::update(
            $wpdb->give_revenue,
            ['campaign_id' => $donation->campaignId],
            ['donation_id' => $donation->id],
            ['%d'],
            ['%d']
        );
    }

    /**
     * Validate new revenue data.
     *
     * @since 2.9.0
     * @since 2.9.4 Mention donation id in exception message.
     *
     * @param array $array
     */
    protected function validateNewRevenueData($array)
    {
        $required = ['donation_id', 'form_id', 'amount'];

        if (empty($array['donation_id'])) {
            unset($array['donation_id']);
        }

        if (empty($array['form_id'])) {
            unset($array['form_id']);
        }

        if (!is_numeric($array['amount']) || (int)$array['amount'] < 0) {
            unset($array['amount']);
        }

        if (array_diff($required, array_keys($array))) {
            $errorMessage = '';
            if (isset($array['donation_id'])) {
                $errorMessage = "An error occurred when processing Donation #{$array['donation_id']}. ";
            }

            throw new InvalidArgumentException(
                sprintf(
                    '%2$sTo insert revenue, please provide valid %1$s.',
                    implode(', ', $required),
                    $errorMessage
                )
            );
        }
    }

    /**
     * Get placeholder for prepare query.
     *
     * @param array $data
     *
     * @return string[] Array of value format type
     */
    private function getPlaceholderForPrepareQuery($data)
    {
        $format = [];

        foreach ($data as $value) {
            $format[] = is_numeric($value) ? '%d' : '%s';
        }

        return $format;
    }

    /**
     * Return whether or not donation id exist in give_revenue table.
     *
     * @sicne 2.9.0
     *
     * @param int $donationId
     *
     * @return bool
     */
    public function isDonationExist($donationId)
    {
        global $wpdb;

        return (bool)DB::get_var(
            DB::prepare(
                "
				SELECT donation_id
				FROM {$wpdb->give_revenue}
				WHERE donation_id = %d
				",
                $donationId
            )
        );
    }
}