Skip to content

Commit

Permalink
Merge branch '3.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Jan 5, 2025
2 parents 2f197e5 + 4b34ed4 commit b26af0f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Database/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ protected function performDeleteOnRelations()
}

// Belongs-To-Many should clean up after itself by default
if ($type === 'belongsToMany') {
if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) {
if (!Arr::get($options, 'detach', true)) {
return;
}
Expand Down
12 changes: 7 additions & 5 deletions src/Database/Traits/Multisite.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ protected function defineMultisiteRelations()
*/
public function canDeleteMultisiteRelation($name, $type = null): bool
{
// Attribute is exclusive to parent model without propagation
if (!$this->isAttributePropagatable($name)) {
return false;
return true;
}

if ($type === null) {
$type = $this->getRelationType($name);
}

if (!in_array($type, ['belongsToMany', 'morphedByMany', 'belongsTo', 'hasOne', 'hasMany', 'attachOne', 'attachMany'])) {
return false;
// Type is not supported by multisite
if (!in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany', 'belongsTo', 'hasOne', 'hasMany', 'attachOne', 'attachMany'])) {
return true;
}

// The current record counts for one so halt if we find more
Expand All @@ -188,7 +190,7 @@ public function canDeleteMultisiteRelation($name, $type = null): bool
/**
* defineMultisiteRelation will modify defined relations on this model so they share
* their association using the shared identifier (`site_root_id`). Only these relation
* types support relation sharing: `belongsToMany`, `morphedByMany`,
* types support relation sharing: `belongsToMany`, `morphToMany`, `morphedByMany`,
* `belongsTo`, `hasOne`, `hasMany`, `attachOne`, `attachMany`.
*/
protected function defineMultisiteRelation($name, $type = null)
Expand All @@ -203,7 +205,7 @@ protected function defineMultisiteRelation($name, $type = null)
}

// Override the local key to the shared root identifier
if (in_array($type, ['belongsToMany', 'morphedByMany'])) {
if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) {
$this->$type[$name]['parentKey'] = 'site_root_id';
}
elseif (in_array($type, ['belongsTo', 'hasOne', 'hasMany'])) {
Expand Down
30 changes: 25 additions & 5 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,38 @@ protected function getRelationValidationValue($relationName)
* the validator use a different database connection than the default connection.
* @return \Illuminate\Validation\Validator
*/
protected static function makeValidator($data, $rules, $customMessages, $attributeNames, $connection = null)
protected static function makeValidator($data, $rules, $customMessages, $attributeNames, $connection = null, $verifier = null)
{
$validator = Validator::make($data, $rules, $customMessages, $attributeNames);
// @deprecated make required arg (v4) desired signature below
// makeValidator($data, $rules, $customMessages, $attributeNames, $verifier)
//
if ($verifier === null) {
$verifier = App::make('validation.presence');
}

// @deprecated set via getValidationPresenceVerifier (v4)
if ($connection !== null) {
$verifier = App::make('validation.presence');
$verifier->setConnection($connection);
$validator->setPresenceVerifier($verifier);
}

$validator = Validator::make($data, $rules, $customMessages, $attributeNames);
$validator->setPresenceVerifier($verifier);

return $validator;
}

/**
* getValidationPresenceVerifier
*/
protected function getValidationPresenceVerifier()
{
$verifier = App::make('validation.presence');

$verifier->setConnection($this->getConnectionName());

return $verifier;
}

/**
* forceSave the model even if validation fails
* @return bool
Expand Down Expand Up @@ -394,7 +413,8 @@ public function validate($rules = null, $customMessages = null, $attributeNames
$rules,
$customMessages,
$attrNames,
$this->getConnectionName()
$this->getConnectionName(),
$this->getValidationPresenceVerifier()
);

$success = $validator->passes();
Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function registerCoreContainerAliases()
'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
'db' => [\October\Rain\Database\DatabaseManager::class],
'db' => [\Illuminate\Database\DatabaseManager::class],
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
'db.schema' => [\Illuminate\Database\Schema\Builder::class],
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class],
Expand All @@ -347,7 +347,7 @@ public function registerCoreContainerAliases()
'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'redirect' => [\Illuminate\Routing\Redirector::class],
'redirect' => [\October\Rain\Router\CoreRedirector::class],
'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class],
'request' => [\Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
Expand Down
54 changes: 54 additions & 0 deletions src/Router/CoreRedirector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php namespace October\Rain\Router;

use App;
use Illuminate\Routing\Redirector as RedirectorBase;

/**
* CoreRedirector adds extra events to the base redirector and ensures the "intended"
* session is different for the frontend and backend contexts.
*
* @package october\router
* @author Alexey Bobkov, Samuel Georges
*/
class CoreRedirector extends RedirectorBase
{
/**
* intended creates a new redirect response to the previously intended location.
* @return \Illuminate\Http\RedirectResponse
*/
public function intended($default = '/', $status = 302, $headers = [], $secure = null)
{
if (!App::runningInFrontend()) {
return parent::intended($default, $status, $headers, $secure);
}

$path = $this->session->pull('url.cms.intended', $default);

return $this->to($path, $status, $headers, $secure);
}

/**
* getIntendedUrl from the session.
*/
public function getIntendedUrl()
{
if (!App::runningInFrontend()) {
return parent::getIntendedUrl();
}

return $this->session->get('url.cms.intended');
}

/**
* setIntendedUrl in the session.
*/
public function setIntendedUrl($url)
{
if (!App::runningInFrontend()) {
return parent::setIntendedUrl($url);
}

$this->session->put('url.cms.intended', $url);
return $this;
}
}
19 changes: 19 additions & 0 deletions src/Router/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,23 @@ protected function registerRouter()
return new CoreRouter($app['events'], $app);
});
}

/**
* registerRedirector
*/
protected function registerRedirector()
{
$this->app->singleton('redirect', function ($app) {
$redirector = new CoreRedirector($app['url']);

// If the session is set on the application instance, we'll inject it into
// the redirector instance. This allows the redirect responses to allow
// for the quite convenient "with" methods that flash to the session.
if (isset($app['session.store'])) {
$redirector->setSession($app['session.store']);
}

return $redirector;
});
}
}

0 comments on commit b26af0f

Please sign in to comment.