diff --git a/composer.json b/composer.json index c06e5a5..b7cb588 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tobya/laravel-mssql-dateformat", - "description": "Check and set MSSQL universal date format used by Laravel to 'Ymd' to ensure universal compatibility", + "description": "Utilise an alternative Inherited MSSQL Grammar that sets universal date format", "type": "laravel-package", "license": "MIT", "autoload": { @@ -15,7 +15,7 @@ } ], "require": { - "laravel/framework": "^8.0|^9.0|^10.0|^11.0" + "laravel/framework": "^8.0|^9.0|^10.0|^11.0|^12.0" }, "extra": { "laravel": { diff --git a/readme.md b/readme.md index c5677d8..5d66bc4 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,8 @@ There is an [international date format (ISO standard)](https://www.iso.org/iso-8 and is NOT universal and incorrectly interprets `Y-m-d` as `Y-d-m` which is beyond idiotic. Laravel uses `Y-m-d` as their international format, which can lead to errors depending on SQL SERVER Settings. -There is one format `Ymd` which is absolutely gauranteed to always be interpreted by SQLServer as `Ymd`. This command patches the file in -illuminate library to use `Ymd` instead of `Y-m-d`. I [Requested](https://github.com/laravel/framework/issues/49074) that the change be made in the illuminate library but it was felt the change +There is one format `Ymd` which is absolutely gauranteed to always be interpreted by SQLServer as `Ymd`. +This command extends the SqlServer grammar to use `Ymd` instead of `Y-m-d`. I [Requested](https://github.com/laravel/framework/issues/49074) that the change be made in the illuminate library but it was felt the change was too big to be made. I hope this is helpful to those of you out there using MSSQL with PHP/Laravel. @@ -19,33 +19,8 @@ composer require tobya/laravel-mssql-dateformat ```` ### To Run -Run by calling the larvel command +No need to run, it is automatically pulled in via Provider. -````dotenv -artisan mssql:check-universal-date --update -```` -You can run without `--update` to do the check without patching the file. - -## Configuration - -It is suggested that you add the following to your project `composer.json` file so this command is automatically run -on install and update. - -````dotenv - -"scripts": { - "post-update-cmd": [ - "@php artisan mssql:check-universal-date --update" - ], - "post-install-cmd": [ - "@php artisan mssql:check-universal-date --update" - ] - } -```` -This is due to the fact that whenever `composer update` or `composer install` is run and the illuminate package -is updated it will overwrite the `SqlServerGrammar.php` with the origional version, so it is necessary to call -the command whenever this has the potential of happening. If no change has been made to the file it will -not be modified. #### Further reading on why this is necessary diff --git a/src/Console/CheckSQLGrammerDate.php b/src/Console/CheckSQLGrammerDate.php index 303a4ad..608851e 100644 --- a/src/Console/CheckSQLGrammerDate.php +++ b/src/Console/CheckSQLGrammerDate.php @@ -44,7 +44,7 @@ class CheckSQLGrammerDate extends Command * * @var string */ - protected $description = 'Checks if the illuminate files in vendor directory are using incorrect date format. '; + protected $description = 'Deprecated: Date Format is now updated by use of inherited grammar. This command is no longer required. '; /** * Create a new command instance. @@ -63,40 +63,10 @@ public function __construct() */ public function handle() { - $filetocheck = base_path('vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\SqlServerGrammar.php'); - if (file_exists($filetocheck)){ - $file_txt = Str::of(file_get_contents($filetocheck)); - $datestr = 'return \'Y-m-d H:i:s.v\';'; - if ($file_txt->contains($datestr)){ - if ($this->option('update')){ - $UpdatedFile_txt = $file_txt->replace($datestr, 'return \'Ymd H:i:s.v\';'); - file_put_contents($filetocheck,$UpdatedFile_txt); - $this->comment(" -********************************** -Incorrect Date Format value found -********************************** -File on disk: $filetocheck"); - $this->info(' ------------------- -Updated -------------------'); - return 0; - } else { - $this->warn( $this->NoUpdateMessage($filetocheck)); - $this->warn('Not Updated'); - return 0; - } - - } - } - $this->info( "Date Format Appears to be ok."); + $this->warn( "Deprecated: Date Format is now updated by use of inherited grammar. This command is no longer required. "); return 0; } - public function NoUpdateMessage($filetocheck){ - return " -$filetocheck - has been overwritten with the wrong date format. mssql:CheckSQLDate --update to update the file. "; - } + } diff --git a/src/Grammars/MSSQLGrammar.php b/src/Grammars/MSSQLGrammar.php new file mode 100644 index 0000000..ac3c539 --- /dev/null +++ b/src/Grammars/MSSQLGrammar.php @@ -0,0 +1,21 @@ +commands([ CheckSQLGrammerDate::class ]); + + DB::connection()->setQueryGrammar(new \Tobya\MSSQLDateformat\Grammars\MSSQLGrammar(DB::connection())); } - } \ No newline at end of file + }