Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: dependabots #7231

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
503 changes: 268 additions & 235 deletions assets/src/js/frontend/paypal-commerce/SmartButtons.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: GiveWP
* Author URI: https://givewp.com/
* Version: 3.4.1
* Version: 3.4.2
* Requires at least: 6.0
* Requires PHP: 7.2
* Text Domain: give
Expand Down Expand Up @@ -403,7 +403,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '3.4.1');
define('GIVE_VERSION', '3.4.2');
}

// Plugin Root File.
Expand Down
324 changes: 150 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@wordpress/interface": "^5.11.0",
"@wordpress/server-side-render": "^4.2.0",
"accounting": "^0.4.1",
"axios": "^0.21.2",
"axios": "^1.6.0",
"chart.js": "^2.9.3",
"chartjs-plugin-crosshair": "^1.1.4",
"chosen-js": "^1.8.7",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: donation, donate, recurring donations, fundraising, crowdfunding
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 7.2
Stable tag: 3.4.1
Stable tag: 3.4.2
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -262,6 +262,9 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
10. Use almost any payment gateway integration with GiveWP through our add-ons or by creating your own add-on.

== Changelog ==
= 3.4.2: February 19th, 2024 =
* Fix: Resolved an issue with PayPal donations that ensures the correct donation amount will be used after filling out payment details and modifying the original amount.

= 3.4.1: February 13th, 2024 =
* Fix: Resolved an issue with the default email block that ensures it is always a required field in the donation form.

Expand Down
2 changes: 1 addition & 1 deletion src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static function getUrl(): string
/**
* Get an array of supported addons
*
* @unreleased Added support for Gift Aid
* @since 3.4.2 Added support for Gift Aid
* @since 3.3.0 Add support to the Funds and Designations addon
* @since 3.0.0
* @return array
Expand Down
159 changes: 159 additions & 0 deletions src/Framework/Models/EagerLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

namespace Give\Framework\Models;

use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
use ReflectionClass;

/**
* Eager load model relationships for more performant queries.
*
* As opposed to "lazy" loading, which queries the database for a relationship when it is accessed,
* "eager" loading queries the database for the relationship of all queried models, with a single query.
* This prevents a "N+1" problem, where a query is executed for each model, but using query optimization.
*
* @unreleased
*
* @template M
*/
class EagerLoader
{
/**
* @unreleased
* @var ReflectionClass<M>
*/
protected $reflection;

/**
* @unreleased
* @var ModelQueryBuilder
*/
protected $modelQuery;

/**
* @unreleased
* @var ModelQueryBuilder
*/
protected $eagerLoadedQuery;

/**
* @unreleased
* @var string
*/
protected $relationshipKey;

/**
* @unreleased
* @var string
*/
protected $foreignKey;

/**
* @var mixed
*/
protected $foreignAttribute;

/**
* @unreleased
*
* @param class-string<M> $modelClass
* @param class-string<M> $eagerLoadedModelClass
* @param string $relationshipKey
* @param string $foreignKey
* @param string|null $foreignAttribute
*/
public function __construct(string $modelClass, string $eagerLoadedModelClass, string $relationshipKey, string $foreignKey, string $foreignAttribute = null)
{
if (!is_subclass_of($modelClass, Model::class)) {
throw new InvalidArgumentException("$modelClass must be an instance of " . Model::class);
}

if (!is_subclass_of($eagerLoadedModelClass, Model::class)) {
throw new InvalidArgumentException("$eagerLoadedModelClass must be an instance of " . Model::class);
}

$this->reflection = new ReflectionClass($modelClass);
$this->modelQuery = $modelClass::query();
$this->relationshipKey = $relationshipKey;
$this->eagerLoadedQuery = $eagerLoadedModelClass::query();
$this->foreignKey = $foreignKey;
$this->foreignAttribute = $foreignAttribute ?? $foreignKey;
}

/**
* @unreleased
*/
public function __call($name, $arguments)
{
$this->modelQuery->$name(...$arguments);
return $this;
}

/**
* This method wraps the `get()` method of the underlying ModelQueryBuilder.
* It uses the results to query the related models and pre-set the cachedRelations property.
*
* @unreleased
*
* @return M|null
*/
public function get()
{
$model = $this->modelQuery->get();

$eagerLoadedModels = $this->eagerLoadedQuery
->where($this->foreignKey, $model->id)
->getAll();

$this->setEagerLoadedModels($model, $eagerLoadedModels);

return $model;
}

/**
* This method wraps the `getAll()` method of the underlying ModelQueryBuilder.
* It uses the results to query the related models and pre-set the cachedRelations property.
*
* @unreleased
*
* @return M[]|null
*/
public function getAll()
{
$models = $this->modelQuery->getAll();

$eagerLoadedModels = $this->eagerLoadedQuery
->whereIn($this->foreignKey, array_column($models, 'id'))
->getAll();

foreach($models as $model) {
$this->setEagerLoadedModels($model, array_filter($eagerLoadedModels, function($eagerLoadedModel) use ($model) {
return $eagerLoadedModel->{$this->foreignAttribute} === $model->id;
}));
}

return $models;
}

/**
* The cachedRelations property is protected and cannot be accessed directly.
* This method uses reflection to set the cachedRelations property on the model.
*
* @unreleased
*
* @param Model $model
* @param array $eagerLoadedModels
*/
protected function setEagerLoadedModels(Model $model, array $eagerLoadedModels): void
{
$property = $this->reflection
->getParentClass()
->getProperty('cachedRelations');
$property->setAccessible(true);

$cachedRelations = $property->getValue($model);
$cachedRelations[$this->relationshipKey] = $eagerLoadedModels;

$property->setValue($model, $cachedRelations);
}
}
Loading
Loading