-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create command to update the config file if it exists
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Reach\StatamicLivewireFilters\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Statamic\Console\RunsInPlease; | ||
|
||
class UpdateLivewireFilters extends Command | ||
{ | ||
use RunsInPlease; | ||
|
||
protected $signature = 'statamic-livewire-filters:update'; | ||
|
||
protected $description = 'Needed upgrades for Livewire Filters'; | ||
|
||
public function handle() | ||
{ | ||
$this->updateConfigForCustomQueryString(); | ||
} | ||
|
||
protected function updateConfigForCustomQueryString() | ||
{ | ||
$configPath = config_path('statamic-livewire-filters.php'); | ||
|
||
if (! File::exists($configPath)) { | ||
return; | ||
} | ||
|
||
// Read file content as string | ||
$contents = File::get($configPath); | ||
|
||
// Check if options already exist | ||
$hasCustomQueryString = preg_match("/['\"']custom_query_string['\"']\s*=>/", $contents); | ||
$hasAliases = preg_match("/['\"']custom_query_string_aliases['\"']\s*=>/", $contents); | ||
|
||
if ($hasCustomQueryString && $hasAliases) { | ||
return; | ||
} | ||
|
||
// New options using nowdoc for exact formatting | ||
$newOptions = <<<'EOT' | ||
// Enable custom query string | ||
'custom_query_string' => false, | ||
// Set the aliases for each custom query string parameter | ||
'custom_query_string_aliases' => [ | ||
// | ||
], | ||
|
||
EOT; | ||
|
||
// Find position of last closing bracket | ||
$pos = strrpos($contents, '];'); | ||
|
||
if ($pos !== false) { | ||
// Insert new options before closing bracket | ||
$contents = substr_replace($contents, $newOptions, $pos, 0); | ||
} | ||
|
||
File::put($configPath, $contents); | ||
|
||
$this->info('Statamic Livewire Filters config file updated successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters