Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Providers/ExtensionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class ExtensionServiceProvider extends ServiceProvider
Updates\AddTimezoneConfigOptions::class,
Updates\RemoveParentField::class,
Updates\UpdateGlobalVariables::class,
Updates\PublishMigrationForNocacheUrlColumn::class,
Updates\PublishMigrationForTwoFactorColumns::class,
Updates\PublishMigrationForWebauthnTable::class,
Updates\AddAddonSettingsToGitConfig::class,
Expand Down
4 changes: 2 additions & 2 deletions src/StaticCaching/NoCache/DatabaseSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function write()

public function restore()
{
$regions = DatabaseRegion::where('url', $this->url)->get(['key']);
$regions = DatabaseRegion::where('url', md5($this->url))->get(['key']);

$this->regions = $regions->map->key;

Expand All @@ -38,7 +38,7 @@ protected function cacheRegion(Region $region)
DatabaseRegion::updateOrCreate([
'key' => $region->key(),
], [
'url' => $this->url,
'url' => md5($this->url),
'region' => serialize($region),
]);
}
Expand Down
40 changes: 40 additions & 0 deletions src/UpdateScripts/PublishMigrationForNocacheUrlColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Statamic\UpdateScripts;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

class PublishMigrationForNocacheUrlColumn extends UpdateScript
{
public function shouldUpdate($newVersion, $oldVersion)
{
return $this->isUpdatingTo('6.0.0')
&& config('statamic.static_caching.nocache', 'cache') === 'database';
}

public function update()
{
if (! $this->migrationExists('update_nocache_url_column')) {
$stub = __DIR__.'/stubs/update_nocache_url_column.php.stub';
$filename = date('Y_m_d_His').'_update_nocache_url_column.php';

File::put(database_path("migrations/$filename"), File::get($stub));

$this->console->line(sprintf(
'Migration <info>database/migrations/%s</info> created successfully.',
$filename
));

$this->console->line('Run <comment>php artisan migrate</comment> to apply the migration.');
}
}

protected function migrationExists(string $name): bool
{
return collect(File::allFiles(database_path('migrations')))
->map->getFilename()
->filter(fn (string $filename) => Str::contains($filename, $name))
->isNotEmpty();
}
}
29 changes: 29 additions & 0 deletions src/UpdateScripts/stubs/update_nocache_url_column.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
DB::transaction(function () {
DB::connection(config('statamic.static_caching.nocache_db_connection'))
->table('nocache_regions')
->whereLike('url', 'http%')
->orderBy('key')
->chunk(100, function ($regions) {
foreach ($regions as $region) {
DB::connection(config('statamic.static_caching.nocache_db_connection'))
->table('nocache_regions')
->where('key', $region->key)
->where('url', $region->url)
->update(['url' => md5($region->url)]);
}
});
});
}
};