Skip to content

Commit

Permalink
Merge pull request #625 from octobercms/develop
Browse files Browse the repository at this point in the history
OC Release - v3.6
  • Loading branch information
daftspunk authored Feb 23, 2024
2 parents b2b43a2 + 24af0ca commit bce9e9e
Show file tree
Hide file tree
Showing 70 changed files with 2,072 additions and 930 deletions.
3 changes: 3 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ https://github.com/jakeasmith/http_build_url

"Twig extensions", Copyright (c) 2016 Vojta Svoboda
https://github.com/vojtasvoboda/oc-twigextensions-plugin

"October Code", Copyright (c) 2022 Sergey Kasyanov
https://github.com/SergeyKasyanov/vscode-october-extension
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"composer/composer": "^2.0.0",
"doctrine/dbal": "^2.13.3|^3.1.4",
"linkorb/jsmin-php": "~1.0",
"wikimedia/less.php": "~3.0",
"wikimedia/less.php": "~4.1",
"scssphp/scssphp": "~1.0",
"symfony/yaml": "^6.0",
"twig/twig": "~3.0",
Expand Down
8 changes: 8 additions & 0 deletions helpers/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* Auth
*
* @see \RainLab\User\Classes\AuthManager
*/
class Auth extends October\Rain\Support\Facades\Auth {}
8 changes: 8 additions & 0 deletions helpers/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* Currency
*
* @see \Responsiv\Shop\Classes\CurrencyManager
*/
class Currency extends October\Rain\Support\Facades\Currency {}
26 changes: 26 additions & 0 deletions src/Auth/Concerns/HasProviderProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php namespace October\Rain\Auth\Concerns;

/**
* HasProviderProxy provides proxy methods to emulate Laravel's auth provider
*
* @package october\auth
* @author Alexey Bobkov, Samuel Georges
*/
trait HasProviderProxy
{
/**
* getProvider just passes it back to the current class
*/
public function getProvider()
{
return $this;
}

/**
* getModel returns the class name for the user model
*/
public function getModel()
{
return $this->userModel;
}
}
1 change: 1 addition & 0 deletions src/Auth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Manager implements StatefulGuard
use \October\Rain\Auth\Concerns\HasThrottle;
use \October\Rain\Auth\Concerns\HasImpersonation;
use \October\Rain\Auth\Concerns\HasStatefulGuard;
use \October\Rain\Auth\Concerns\HasProviderProxy;
use \October\Rain\Auth\Concerns\HasGuard;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Auth/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public function addGroup($group)
{
if (!$this->inGroup($group)) {
$this->groups()->attach($group);
$this->reloadRelations('groups');
$this->unsetRelation('groups');
}

return true;
Expand All @@ -436,7 +436,7 @@ public function removeGroup($group)
{
if ($this->inGroup($group)) {
$this->groups()->detach($group);
$this->reloadRelations('groups');
$this->unsetRelation('groups');
}

return true;
Expand Down
4 changes: 0 additions & 4 deletions src/Database/Attach/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ public function beforeSave()
if ($this->data instanceof UploadedFile) {
$this->fromPost($this->data);
}
// @deprecated see AttachOneOrMany::isValidFileData
else {
$this->fromFile($this->data);
}

$this->data = null;
}
Expand Down
19 changes: 19 additions & 0 deletions src/Database/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as BuilderModel;
use October\Rain\Support\Facades\DbDongle;
use Closure;

/**
* Builder class for queries, extends the Eloquent builder class.
Expand All @@ -13,6 +14,24 @@
class Builder extends BuilderModel
{
use \October\Rain\Database\Concerns\HasNicerPagination;
use \October\Rain\Database\Concerns\HasEagerLoadAttachRelation;

/**
* eagerLoadRelation eagerly load the relationship on a set of models, with support
* for attach relations.
* @param array $models
* @param string $name
* @param \Closure $constraints
* @return array
*/
protected function eagerLoadRelation(array $models, $name, Closure $constraints)
{
if ($result = $this->eagerLoadAttachRelation($models, $name, $constraints)) {
return $result;
}

return parent::eagerLoadRelation($models, $name, $constraints);
}

/**
* lists gets an array with the values of a given column.
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function setAttribute($key, $value)

// Handle direct relation setting
if ($this->hasRelation($key) && !$this->hasSetMutator($key)) {
return $this->setRelationValue($key, $value);
return $this->setRelationSimpleValue($key, $value);
}

/**
Expand Down
68 changes: 68 additions & 0 deletions src/Database/Concerns/HasEagerLoadAttachRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php namespace October\Rain\Database\Concerns;

use Closure;

/**
* HasEagerLoadAttachRelation eagerly loads all attachments on a model in one pass.
* Since they share a common type and database table, multiple attachment definitions
* can be eagerly loaded as a single query.
*/
trait HasEagerLoadAttachRelation
{
/**
* @var array eagerLoadAttachResultCache
*/
protected $eagerLoadAttachResultCache = [];

/**
* eagerLoadAttachRelation eagerly loads an attachment relationship on a set of models.
* @param string $relatedModel
* @param array $models
* @param string $name
* @param \Closure $constraints
* @return array|null
*/
protected function eagerLoadAttachRelation(array $models, $name, Closure $constraints)
{
// Look up relation type
$relationType = $this->getModel()->getRelationType($name);
if (!$relationType || !in_array($relationType, ['attachOne', 'attachMany'])) {
return null;
}

// Only vanilla attachments are supported, pass complex lookups back to Laravel
$definition = $this->getModel()->getRelationDefinition($name);
if (isset($definition['conditions']) || isset($definition['scope'])) {
return null;
}

// Opt-out of the combined eager loading logic
if (isset($definition['combineEager']) && $definition['combineEager'] === false) {
return null;
}

$relation = $this->getRelation($name);
$relatedModel = get_class($relation->getRelated());

// Perform a global look up attachment without the 'field' constraint
// to produce a combined subset of all possible attachment relations.
if (!isset($this->eagerLoadAttachResultCache[$relatedModel])) {
$relation->addCommonEagerConstraints($models);

// Note this takes first constraint only. If it becomes a problem one solution
// could be to compare the md5 of toSql() to ensure uniqueness. The workaround
// for this edge case is to set combineEager => false in the definition.
$constraints($relation);

$this->eagerLoadAttachResultCache[$relatedModel] = $relation->getEager();
}

$results = $this->eagerLoadAttachResultCache[$relatedModel];

return $relation->match(
$relation->initRelation($models, $name),
$results->where('field', $name),
$name
);
}
}
24 changes: 14 additions & 10 deletions src/Database/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ trait HasEvents
*/
protected function bootNicerEvents()
{
$class = get_called_class();

if (isset(static::$eventsBooted[$class])) {
if (isset(static::$eventsBooted[static::class])) {
return;
}

Expand All @@ -39,20 +37,26 @@ protected function bootNicerEvents()
];

foreach ($nicerEvents as $eventMethod => $method) {
self::$eventMethod(function ($model) use ($method) {
$model->fireEvent('model.' . $method);

if ($model->methodExists($method)) {
return $model->$method();
}
self::registerModelEvent($eventMethod, function ($model) use ($method) {
$model->fireEvent("model.{$method}");
return $model->$method();
});
}

// Hooks for late stage attribute changes
self::registerModelEvent('creating', function ($model) {
$model->fireEvent('model.beforeSaveDone');
});

self::registerModelEvent('updating', function ($model) {
$model->fireEvent('model.beforeSaveDone');
});

// Boot event
$this->fireEvent('model.afterBoot');
$this->afterBoot();

static::$eventsBooted[$class] = true;
static::$eventsBooted[static::class] = true;
}

/**
Expand Down
Loading

0 comments on commit bce9e9e

Please sign in to comment.