From c3d4ba67ba3818b7f5d4580aedff9ced275d4385 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 14 May 2024 11:49:46 +1000 Subject: [PATCH 01/12] Minor --- src/Database/Relations/BelongsToMany.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Database/Relations/BelongsToMany.php b/src/Database/Relations/BelongsToMany.php index f8b29a3a5..eb6df149f 100644 --- a/src/Database/Relations/BelongsToMany.php +++ b/src/Database/Relations/BelongsToMany.php @@ -301,14 +301,10 @@ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'p */ public function newPivot(array $attributes = [], $exists = false) { - /* - * October looks to the relationship parent - */ + // October looks to the relationship parent $pivot = $this->parent->newRelationPivot($this->relationName, $this->parent, $attributes, $this->table, $exists); - /* - * Laravel looks to the related model - */ + // Laravel looks to the related model if (empty($pivot)) { $pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists, $this->using); } From cf8b4cb48c4f745660d9e4ccebdfbeed21bfe65f Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 14 May 2024 12:20:58 +1000 Subject: [PATCH 02/12] Allows programmatic toggling of soft deletes --- src/Database/Scopes/MultisiteScope.php | 20 +++++++++---------- src/Database/Scopes/SoftDeleteScope.php | 24 +++++++++++++++++++++++ src/Database/Traits/SoftDelete.php | 26 +++++++++++++++++-------- 3 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 src/Database/Scopes/SoftDeleteScope.php diff --git a/src/Database/Scopes/MultisiteScope.php b/src/Database/Scopes/MultisiteScope.php index 97dc394fe..83dcf8243 100644 --- a/src/Database/Scopes/MultisiteScope.php +++ b/src/Database/Scopes/MultisiteScope.php @@ -28,6 +28,16 @@ public function apply(BuilderBase $builder, ModelBase $model) } } + /** + * extend the Eloquent query builder. + */ + public function extend(BuilderBase $builder) + { + foreach ($this->extensions as $extension) { + $this->{"add{$extension}"}($builder); + } + } + /** * addWithSite removes this scope and includes the specified site */ @@ -67,14 +77,4 @@ protected function addWithSyncSites(BuilderBase $builder) return $builder->withSites($builder->getModel()->getMultisiteSyncSites()); }); } - - /** - * extend the Eloquent query builder. - */ - public function extend(BuilderBase $builder) - { - foreach ($this->extensions as $extension) { - $this->{"add{$extension}"}($builder); - } - } } diff --git a/src/Database/Scopes/SoftDeleteScope.php b/src/Database/Scopes/SoftDeleteScope.php new file mode 100644 index 000000000..9307ecc05 --- /dev/null +++ b/src/Database/Scopes/SoftDeleteScope.php @@ -0,0 +1,24 @@ +isSoftDeleteEnabled()) { + $builder->whereNull($model->getQualifiedDeletedAtColumn()); + } + } +} diff --git a/src/Database/Traits/SoftDelete.php b/src/Database/Traits/SoftDelete.php index 3178f7efb..19b6fef59 100644 --- a/src/Database/Traits/SoftDelete.php +++ b/src/Database/Traits/SoftDelete.php @@ -2,7 +2,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Eloquent\Collection as CollectionBase; -use Illuminate\Database\Eloquent\SoftDeletingScope; +use October\Rain\Database\Scopes\SoftDeleteScope; /** * SoftDelete trait for flagging models as deleted instead of actually deleting them. @@ -22,7 +22,7 @@ trait SoftDelete */ public static function bootSoftDelete() { - static::addGlobalScope(new SoftDeletingScope); + static::addGlobalScope(new SoftDeleteScope); static::softDeleted(function($model) { /** @@ -106,17 +106,18 @@ public function forceDelete() */ protected function performDeleteOnModel() { - if ($this->forceDeleting) { + if ($this->forceDeleting || !$this->isSoftDeleteEnabled()) { $this->performDeleteOnRelations(); $this->setKeysForSaveQuery($this->newQuery()->withTrashed())->forceDelete(); $this->exists = false; } + else { + $this->performSoftDeleteOnRelations(); - $this->performSoftDeleteOnRelations(); - - $this->runSoftDelete(); + $this->runSoftDelete(); + } } /** @@ -248,7 +249,7 @@ public function trashed() */ public static function withTrashed() { - return with(new static)->newQueryWithoutScope(new SoftDeletingScope); + return with(new static)->newQueryWithoutScope(new SoftDeleteScope); } /** @@ -261,7 +262,7 @@ public static function onlyTrashed() $column = $instance->getQualifiedDeletedAtColumn(); - return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column); + return $instance->newQueryWithoutScope(new SoftDeleteScope)->whereNotNull($column); } /** @@ -294,6 +295,15 @@ public static function restored($callback) static::registerModelEvent('restored', $callback); } + /** + * isSoftDeleteEnabled allows for programmatic toggling + * @return bool + */ + public function isSoftDeleteEnabled() + { + return true; + } + /** * getDeletedAtColumn gets the name of the "deleted at" column. * @return string From 6b1d99a6509f2ba2fed4623a0fb8b5842ef71108 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 15 May 2024 16:26:33 +1000 Subject: [PATCH 03/12] Adds incrementing pivot key support --- src/Database/Relations/DefinedConstraints.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Database/Relations/DefinedConstraints.php b/src/Database/Relations/DefinedConstraints.php index 5689852c4..335290b14 100644 --- a/src/Database/Relations/DefinedConstraints.php +++ b/src/Database/Relations/DefinedConstraints.php @@ -42,6 +42,11 @@ public function addDefinedConstraintsToRelation($relation, array $args = null) $relation->withPivot($pivotData); } + // Pivot incrementing key (belongsToMany, morphToMany, morphByMany) + if ($pivotKey = array_get($args, 'pivotKey')) { + $relation->withPivot($pivotKey); + } + // Pivot timestamps (belongsToMany, morphToMany, morphByMany) if (array_get($args, 'timestamps')) { $relation->withTimestamps(); From e196770b2226fdaee69ddb906419afd6844da015 Mon Sep 17 00:00:00 2001 From: October CMS Date: Thu, 23 May 2024 13:15:11 +1000 Subject: [PATCH 04/12] Refactor file resolution This fixes a long file resolution error /var/html/path/to/asset.css/var/html/path/to/asset.css when using child themes and shows a nicer error for missing files --- src/Assetic/Asset/FileAsset.php | 7 ++++--- src/Assetic/Combiner.php | 12 +++++++----- src/Assetic/Factory/AssetFactory.php | 8 ++++---- src/Assetic/Traits/HasDeepHasher.php | 13 ++++++++++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Assetic/Asset/FileAsset.php b/src/Assetic/Asset/FileAsset.php index b1ebe92e4..a38f032d3 100644 --- a/src/Assetic/Asset/FileAsset.php +++ b/src/Assetic/Asset/FileAsset.php @@ -1,5 +1,6 @@ source, $this->getVars(), $this->getValues()); if (!is_file($source)) { - throw new RuntimeException(sprintf('The source file "%s" does not exist.', $source)); + throw new RuntimeException(sprintf('The source file "%s" does not exist.', File::nicePath($source))); } $this->doLoad(file_get_contents($source), $additionalFilter); @@ -71,7 +72,7 @@ public function getLastModified() $source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues()); if (!is_file($source)) { - throw new RuntimeException(sprintf('The source file "%s" does not exist.', $source)); + throw new RuntimeException(sprintf('The source file "%s" does not exist.', File::nicePath($source))); } return filemtime($source); diff --git a/src/Assetic/Combiner.php b/src/Assetic/Combiner.php index 4cfe94f6f..412283810 100644 --- a/src/Assetic/Combiner.php +++ b/src/Assetic/Combiner.php @@ -1,10 +1,10 @@ getFilters(File::extension($asset), $production); - $path = file_exists($asset) - ? $asset - : (File::symbolizePath($asset, null) ?: $this->localPath . $asset); + + $path = File::symbolizePath($asset); + if (!file_exists($path) && file_exists($this->localPath . $asset)) { + $path = $this->localPath . $asset; + } $files[] = new FileAsset($path, $filters, base_path()); $filesSalt .= $this->localPath . $asset; } - $filesSalt = md5($filesSalt); + $filesSalt = md5($filesSalt); $collection = new AssetCollection($files, [], $filesSalt); $collection->setTargetPath($targetPath); diff --git a/src/Assetic/Factory/AssetFactory.php b/src/Assetic/Factory/AssetFactory.php index 61efefa73..43607bf54 100644 --- a/src/Assetic/Factory/AssetFactory.php +++ b/src/Assetic/Factory/AssetFactory.php @@ -257,7 +257,7 @@ public function generateAssetName($inputs, $filters, $options = []) public function getLastModified(AssetInterface $asset) { $mtime = 0; - foreach ($asset instanceof AssetCollectionInterface ? $asset : array($asset) as $leaf) { + foreach ($asset instanceof AssetCollectionInterface ? $asset : [$asset] as $leaf) { $mtime = max($mtime, $leaf->getLastModified()); if (!$filters = $leaf->getFilters()) { @@ -272,7 +272,7 @@ public function getLastModified(AssetInterface $asset) continue; } - // extract children from leaf after running all preceeding filters + // Extract children from leaf after running all preceding filters $clone = clone $leaf; $clone->clearFilters(); foreach (array_slice($prevFilters, 0, -1) as $prevFilter) { @@ -298,7 +298,7 @@ public function getLastModified(AssetInterface $asset) * * A glob: If the string contains a "*" it will be interpreted as a glob * * A path: Otherwise the string is interpreted as a filesystem path * - * Both globs and paths will be absolutized using the current root directory. + * Both globs and paths will be absolute using the current root directory. * * @param string $input An input string * @param array $options An array of options @@ -384,7 +384,7 @@ private static function isAbsolutePath($path) } /** - * Loops through the root directories and returns the first match. + * findRootDir loops through the root directories and returns the first match. * * @param string $path An absolute path * @param array $roots An array of root directories diff --git a/src/Assetic/Traits/HasDeepHasher.php b/src/Assetic/Traits/HasDeepHasher.php index 3989b18ae..bc0e04ae2 100644 --- a/src/Assetic/Traits/HasDeepHasher.php +++ b/src/Assetic/Traits/HasDeepHasher.php @@ -29,9 +29,16 @@ public function getDeepHashFromAssets($assets) { $key = ''; - $assetFiles = array_map(function ($file) { - return file_exists($file) ? $file : (File::symbolizePath($file, null) ?: $this->localPath . $file); - }, $assets); + $assetFiles = []; + foreach ($assets as $file) { + $path = File::symbolizePath($file); + if (file_exists($path)) { + $assetFiles[] = $path; + } + elseif (file_exists($this->localPath . $path)) { + $assetFiles[] = $this->localPath . $path; + } + } foreach ($assetFiles as $file) { $filters = $this->getFilters(File::extension($file)); From 5879adb552b58fb744330392d3a9dbc5051270df Mon Sep 17 00:00:00 2001 From: October CMS Date: Wed, 29 May 2024 12:31:17 +1000 Subject: [PATCH 05/12] Fixes replication logic for syntax models --- src/Parse/Syntax/SyntaxModelTrait.php | 39 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Parse/Syntax/SyntaxModelTrait.php b/src/Parse/Syntax/SyntaxModelTrait.php index 6e305608d..13c79d7bf 100644 --- a/src/Parse/Syntax/SyntaxModelTrait.php +++ b/src/Parse/Syntax/SyntaxModelTrait.php @@ -10,6 +10,9 @@ */ trait SyntaxModelTrait { + /** + * @deprecated replace with initializeSyntaxModelTrait model.afterFetch + */ public static function bootSyntaxModelTrait() { static::fetched(function ($model) { @@ -18,9 +21,18 @@ public static function bootSyntaxModelTrait() } /** - * Defines any relationships (attachments) that this model will need - * based on the field definitions. - * @return void + * initializeSyntaxModelTrait constructor + */ + public function initializeSyntaxModelTrait() + { + $this->bindEvent('model.beforeReplicate', function() { + $this->defineSyntaxRelations(); + }); + } + + /** + * defineSyntaxRelations defines any relationships (attachments) that this model + * will need based on the field definitions. */ public function defineSyntaxRelations() { @@ -98,8 +110,8 @@ protected function getThumbForImage($image, $params = []) } /** - * Prepare the syntax fields for use in a Form builder. The array - * name is added to each field. + * getFormSyntaxFields prepares the syntax fields for use in a Form builder. + * The array name is added to each field. * @return array */ public function getFormSyntaxFields() @@ -134,7 +146,7 @@ public function getFormSyntaxFields() } /** - * Processes supplied content and extracts the field definitions + * makeSyntaxFields processes supplied content and extracts the field definitions * and default data. It is mixed with the current data and applied * to the fields and data attributes. * @param string $content @@ -147,9 +159,7 @@ public function makeSyntaxFields($content) $this->setAttribute($this->getSyntaxFieldsColumnName(), $fields); - /* - * Remove fields no longer present and add default values - */ + // Remove fields no longer present and add default values $currentFields = array_intersect_key((array) $this->getFormSyntaxData(), $parser->getFieldValues()); $currentFields = $currentFields + $parser->getFieldValues(); @@ -158,13 +168,16 @@ public function makeSyntaxFields($content) return $fields; } + /** + * getSyntaxParser + */ public function getSyntaxParser($content) { return Parser::parse($content); } /** - * Get data column name. + * getSyntaxDataColumnName returns the data column name. * @return string */ public function getSyntaxDataColumnName() @@ -173,7 +186,7 @@ public function getSyntaxDataColumnName() } /** - * Get value of the model syntax_data column. + * getSyntaxData returns value of the model syntax_data column. * @return int */ public function getSyntaxData() @@ -182,7 +195,7 @@ public function getSyntaxData() } /** - * Get fields column name. + * getSyntaxFieldsColumnName returns fields column name. * @return string */ public function getSyntaxFieldsColumnName() @@ -191,7 +204,7 @@ public function getSyntaxFieldsColumnName() } /** - * Get value of the model syntax_fields column. + * getSyntaxFields returns value of the model syntax_fields column. * @return int */ public function getSyntaxFields() From b005ac22a29413ec9b94c40ee3c2eb905b9bb6cd Mon Sep 17 00:00:00 2001 From: October CMS Date: Wed, 29 May 2024 14:53:58 +1000 Subject: [PATCH 06/12] Fixes hint --- src/Support/Facades/Site.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Support/Facades/Site.php b/src/Support/Facades/Site.php index 4b7dc575b..9e9d3c7f3 100644 --- a/src/Support/Facades/Site.php +++ b/src/Support/Facades/Site.php @@ -36,8 +36,8 @@ * @method static string|null getSiteCodeFromContext() * @method static mixed getSiteFromContext() * @method static bool hasGlobalContext() - * @method static void withGlobalContext(callable $callback) - * @method static void withContext($siteId, callable $callback) + * @method static mixed withGlobalContext(callable $callback) + * @method static mixed withContext($siteId, callable $callback) * @method static mixed getSiteFromBrowser(string $acceptLanguage) * @method static mixed getSiteForLocale(string $locale) * @method static void resetCache() From 84f3ecb04f3a5284954dce3060d22419d1a410e8 Mon Sep 17 00:00:00 2001 From: October CMS Date: Thu, 30 May 2024 14:39:42 +1000 Subject: [PATCH 07/12] Fixes sticky app url in site change --- src/Foundation/Bootstrap/RegisterOctober.php | 5 ----- src/Html/UrlServiceProvider.php | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Foundation/Bootstrap/RegisterOctober.php b/src/Foundation/Bootstrap/RegisterOctober.php index 786c530f0..633d264f6 100644 --- a/src/Foundation/Bootstrap/RegisterOctober.php +++ b/src/Foundation/Bootstrap/RegisterOctober.php @@ -41,11 +41,6 @@ class RegisterOctober */ public function bootstrap(Application $app) { - // Workaround for CLI and URL based in subdirectory - if ($app->runningInConsole()) { - $app['url']->forceRootUrl($app['config']->get('app.url')); - } - // Register singletons $app->singleton('string', function () { return new \October\Rain\Support\Str; diff --git a/src/Html/UrlServiceProvider.php b/src/Html/UrlServiceProvider.php index 28a464364..969032a1c 100644 --- a/src/Html/UrlServiceProvider.php +++ b/src/Html/UrlServiceProvider.php @@ -1,7 +1,5 @@ registerUrlGeneratorPolicy(); $this->registerRelativeHelper(); $this->registerPjaxCached(); + + $this->app['events']->listen('site.changed', function() { + $this->registerUrlGeneratorPolicy(); + }); } /** @@ -33,14 +35,13 @@ public function register() public function registerUrlGeneratorPolicy() { $provider = $this->app['url']; - $policy = Config::get('system.link_policy', 'detect'); + $policy = $this->app['config']->get('system.link_policy', 'detect'); + $appUrl = $this->app['config']->get('app.url'); switch (strtolower($policy)) { case 'force': - $appUrl = Config::get('app.url'); - $schema = Str::startsWith($appUrl, 'http://') ? 'http' : 'https'; $provider->forceRootUrl($appUrl); - $provider->forceScheme($schema); + $provider->forceScheme(str_starts_with($appUrl, 'http://') ? 'http' : 'https'); break; case 'insecure': @@ -51,6 +52,13 @@ public function registerUrlGeneratorPolicy() $provider->forceScheme('https'); break; } + + // Workaround for October CMS installed to a subdirectory since + // Laravel won't support this use case, related issue: + // https://github.com/laravel/framework/pull/3918 + if ($this->app->runningInConsole()) { + $provider->forceRootUrl($appUrl); + } } /** From d07b4b4d7b98e50371d0b74d327467bdd8c9cfb5 Mon Sep 17 00:00:00 2001 From: October CMS Date: Thu, 30 May 2024 21:07:53 +1000 Subject: [PATCH 08/12] Minor --- src/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filesystem/Filesystem.php b/src/Filesystem/Filesystem.php index f94d8160c..7f002e028 100644 --- a/src/Filesystem/Filesystem.php +++ b/src/Filesystem/Filesystem.php @@ -117,7 +117,7 @@ public function localToPublic($path) if (($event = Event::fire('filesystem.localToPublic', [$path], true)) !== null) { return $event; } - + // Check real paths $basePath = base_path(); if (strpos($path, $basePath) === 0) { From 366d0a3270a536225fe030734cd28abe19ab80e2 Mon Sep 17 00:00:00 2001 From: October CMS Date: Sun, 9 Jun 2024 14:52:37 +1000 Subject: [PATCH 09/12] Improve add/remove interface for validation rules --- src/Config/README.md | 4 ++-- src/Database/Traits/Validation.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Config/README.md b/src/Config/README.md index 798fed3c2..370e4903f 100644 --- a/src/Config/README.md +++ b/src/Config/README.md @@ -9,10 +9,10 @@ Modules and plugins can have config files in the /config directory. Plugin and m ```` // Get a configuration string from the CMS module -echo Config::get('cms::options.allowComments'); +echo Config::get('cms::options.allow_comments'); // Get a configuration string from the october/blog plugin. -echo Config::get('october.blog::options.allowComments'); +echo Config::get('october.blog::options.allow_comments'); ```` ## Overriding configuration strings diff --git a/src/Database/Traits/Validation.php b/src/Database/Traits/Validation.php index bccaca799..80830b839 100644 --- a/src/Database/Traits/Validation.php +++ b/src/Database/Traits/Validation.php @@ -134,7 +134,12 @@ public function addValidationRule(string $name, $definition) $rules = explode('|', $rules); } - $rules[] = $definition; + if (is_array($definition)) { + $rules = array_merge($rules, $definition); + } + else { + $rules[] = $definition; + } $this->rules[$name] = $rules; } @@ -142,8 +147,13 @@ public function addValidationRule(string $name, $definition) /** * removeValidationRule removes a validation rule from the stack and resets the value as a processed array */ - public function removeValidationRule(string $name, $definition) + public function removeValidationRule(string $name, $definition = '*') { + if ($definition === '*') { + unset($this->rules[$name]); + return; + } + $rules = $this->rules[$name] ?? []; if (!is_array($rules)) { $rules = explode('|', $rules); From 7cddccf2f01204d185cb5c7c89b373d59c77c8b9 Mon Sep 17 00:00:00 2001 From: October CMS Date: Thu, 13 Jun 2024 14:00:21 +1000 Subject: [PATCH 10/12] Use title name for component descriptions --- src/Scaffold/Console/component/component.stub | 2 +- src/Scaffold/GeneratorCommand.php | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Scaffold/Console/component/component.stub b/src/Scaffold/Console/component/component.stub index 0165f89b6..e2204e0b3 100644 --- a/src/Scaffold/Console/component/component.stub +++ b/src/Scaffold/Console/component/component.stub @@ -12,7 +12,7 @@ class {{studly_name}} extends ComponentBase public function componentDetails() { return [ - 'name' => '{{name}} Component', + 'name' => '{{title_name}} Component', 'description' => 'No description provided yet...' ]; } diff --git a/src/Scaffold/GeneratorCommand.php b/src/Scaffold/GeneratorCommand.php index 9c0b98637..26e7b86f0 100644 --- a/src/Scaffold/GeneratorCommand.php +++ b/src/Scaffold/GeneratorCommand.php @@ -87,17 +87,13 @@ public function makeStub(string $stubName) $destinationFile = $this->getDestinationPath() . '/' . $this->stubs[$stubName]; $destinationContent = $this->files->get($sourceFile); - /* - * Parse each variable in to the destination content and path - */ + // Parse each variable in to the destination content and path $destinationContent = Twig::parse($destinationContent, $this->vars); $destinationFile = Twig::parse($destinationFile, $this->vars); $this->makeDirectory($destinationFile); - /* - * Make sure this file does not already exist - */ + // Make sure this file does not already exist if ($this->files->exists($destinationFile) && !$this->option('force')) { throw new Exception('Stop everything!!! This file already exists: ' . $destinationFile); } @@ -125,9 +121,7 @@ protected function processVars(array $vars): array $modifiers = ['plural', 'singular', 'title']; foreach ($vars as $key => $var) { - /* - * Apply cases, and cases with modifiers - */ + // Apply cases, and cases with modifiers foreach ($cases as $case) { $primaryKey = $case . '_' . $key; $vars[$primaryKey] = $this->modifyString($case, $var); @@ -138,9 +132,7 @@ protected function processVars(array $vars): array } } - /* - * Apply modifiers - */ + // Apply modifiers foreach ($modifiers as $modifier) { $primaryKey = $modifier . '_' . $key; $vars[$primaryKey] = $this->modifyString($modifier, $var); From 0bd6864cfd8fd7f7c549371a79ec89cb59ab1467 Mon Sep 17 00:00:00 2001 From: October CMS Date: Wed, 26 Jun 2024 08:32:32 +1000 Subject: [PATCH 11/12] Typo --- src/Support/Facades/Flash.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/Facades/Flash.php b/src/Support/Facades/Flash.php index d818a2be1..2a1808f45 100644 --- a/src/Support/Facades/Flash.php +++ b/src/Support/Facades/Flash.php @@ -15,7 +15,7 @@ * @method static \October\Rain\Flash\FlashBag add(string $key, string $message) * @method static void store() * @method static void forget(string $key = null) - * @method static void purge(); + * @method static void purge() * * @see \October\Rain\Flash\FlashBag */ From 876bcb5abb9620746ada833d0b7da6bb1cbe7b99 Mon Sep 17 00:00:00 2001 From: October CMS Date: Wed, 7 Aug 2024 11:33:54 +1000 Subject: [PATCH 12/12] Fixes compat with Laravel 10 --- src/Database/Connections/MySqlConnection.php | 73 +++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/src/Database/Connections/MySqlConnection.php b/src/Database/Connections/MySqlConnection.php index 24b87b664..dfa741419 100644 --- a/src/Database/Connections/MySqlConnection.php +++ b/src/Database/Connections/MySqlConnection.php @@ -7,6 +7,7 @@ use Illuminate\Database\Schema\MySqlBuilder; use Illuminate\Database\Schema\MySqlSchemaState; use Illuminate\Filesystem\Filesystem; +use Exception; use PDO; /** @@ -14,6 +15,76 @@ */ class MySqlConnection extends Connection { + /** + * The last inserted ID generated by the server + * + * @var string|int|null + */ + protected $lastInsertId; + + /** + * Run an insert statement against the database. + * + * @param string $query + * @param array $bindings + * @param string|null $sequence + * @return bool + */ + public function insert($query, $bindings = [], $sequence = null) + { + return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) { + if ($this->pretending()) { + return true; + } + + $statement = $this->getPdo()->prepare($query); + + $this->bindValues($statement, $this->prepareBindings($bindings)); + + $this->recordsHaveBeenModified(); + + $result = $statement->execute(); + + $this->lastInsertId = $this->getPdo()->lastInsertId($sequence); + + return $result; + }); + } + + /** + * Get the last insert ID. + * + * @return int + */ + public function getLastInsertId() + { + return $this->lastInsertId; + } + + /** + * Escape a binary value for safe SQL embedding. + * + * @param string $value + * @return string + */ + protected function escapeBinary($value) + { + $hex = bin2hex($value); + + return "x'{$hex}'"; + } + + /** + * Determine if the given database exception was caused by a unique constraint violation. + * + * @param \Exception $exception + * @return bool + */ + protected function isUniqueConstraintError(Exception $exception) + { + return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage())); + } + /** * Determine if the connected database is a MariaDB database. * @@ -35,7 +106,7 @@ protected function getDefaultQueryGrammar() if (method_exists($grammar, 'setConnection')) { $grammar->setConnection($this); } - + return $this->withTablePrefix($grammar); }