From 873ff376b05f5794cb956717435727855f390976 Mon Sep 17 00:00:00 2001 From: Martin Dub <49438284+martinoak@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:28:23 +0200 Subject: [PATCH 001/486] [5.x] Resolving PHP Deprecated errors (#10346) --- src/Git/Git.php | 2 +- src/Support/Html.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Git/Git.php b/src/Git/Git.php index a328a7dffc..a19b24d27b 100644 --- a/src/Git/Git.php +++ b/src/Git/Git.php @@ -177,7 +177,7 @@ protected function gitProcessForPath($path) */ protected function statusWithFileCounts($status) { - $lines = collect(explode("\n", $status))->filter(); + $lines = collect(explode("\n", $status ?? ''))->filter(); $totalCount = $lines->count(); diff --git a/src/Support/Html.php b/src/Support/Html.php index b3fa78094c..1dff9bb0f3 100644 --- a/src/Support/Html.php +++ b/src/Support/Html.php @@ -92,7 +92,7 @@ public static function decode($value) */ public static function entities($value) { - return htmlentities($value, ENT_QUOTES, Config::get('statamic.system.charset', 'UTF-8'), false); + return htmlentities($value ?? '', ENT_QUOTES, Config::get('statamic.system.charset', 'UTF-8'), false); } /** @@ -348,7 +348,7 @@ public static function sanitize($value, $antlers = true, $doubleEncode = true) return Arr::sanitize($value, $antlers); } - $value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode); + $value = htmlspecialchars($value ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode); if ($antlers) { $value = str_replace(['{', '}'], ['{', '}'], $value); From a9b4746fd74097da6e7b63e90624b84d71f6d6ca Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 24 Jun 2024 12:00:30 -0400 Subject: [PATCH 002/486] [5.x] Remove old logic from support details command (#10360) --- src/Console/Commands/SupportDetails.php | 36 ------------------------- 1 file changed, 36 deletions(-) diff --git a/src/Console/Commands/SupportDetails.php b/src/Console/Commands/SupportDetails.php index deda848ec0..a68abdf945 100644 --- a/src/Console/Commands/SupportDetails.php +++ b/src/Console/Commands/SupportDetails.php @@ -3,11 +3,7 @@ namespace Statamic\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Foundation\Application; -use Illuminate\Foundation\Console\AboutCommand; use Statamic\Console\RunsInPlease; -use Statamic\Facades\Addon; -use Statamic\Statamic; class SupportDetails extends Command { @@ -17,38 +13,6 @@ class SupportDetails extends Command protected $description = 'Outputs details helpful for support requests'; public function handle() - { - return class_exists(AboutCommand::class) - ? $this->handleUsingAboutCommand() - : $this->handleUsingStatamic(); - } - - private function handleUsingStatamic() - { - $this->line(sprintf('Statamic %s %s', Statamic::version(), Statamic::pro() ? 'Pro' : 'Solo')); - $this->line('Laravel '.Application::VERSION); - $this->line('PHP '.phpversion()); - $this->line(sprintf('Stache Watcher %s', config('statamic.stache.watcher') ? 'Enabled' : 'Disabled')); - $this->line(sprintf('Static Caching %s', config('statamic.static_caching.strategy') ?: 'Disabled')); - $this->addons(); - - return static::SUCCESS; - } - - private function addons() - { - $addons = Addon::all(); - - if ($addons->isEmpty()) { - return $this->line('No addons installed'); - } - - foreach ($addons as $addon) { - $this->line(sprintf('%s %s', $addon->package(), $addon->version())); - } - } - - private function handleUsingAboutCommand() { $this->replaceView(); From 875667aafe65e3aae40e1d8dbc209b7ac1f78acf Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 24 Jun 2024 12:13:16 -0400 Subject: [PATCH 003/486] [5.x] Auto stache watcher setting (#10354) --- config/stache.php | 2 +- src/Assets/AssetContainerContents.php | 3 +- src/Facades/Stache.php | 1 + src/Providers/AppServiceProvider.php | 14 ++++++++- src/Stache/Stache.php | 9 ++++++ src/Stache/Stores/CollectionsStore.php | 2 +- src/Stache/Stores/ContainerAssetsStore.php | 3 +- src/Stache/Stores/Store.php | 2 +- src/Stache/Stores/TaxonomyTermsStore.php | 2 +- tests/Stache/StacheTest.php | 30 ++++++++++++++++++- .../Stores/AssetContainersStoreTest.php | 1 + 11 files changed, 61 insertions(+), 8 deletions(-) diff --git a/config/stache.php b/config/stache.php index 71044d5ab3..7fc91d77b1 100644 --- a/config/stache.php +++ b/config/stache.php @@ -15,7 +15,7 @@ | */ - 'watcher' => env('STATAMIC_STACHE_WATCHER', true), + 'watcher' => env('STATAMIC_STACHE_WATCHER', 'auto'), /* |-------------------------------------------------------------------------- diff --git a/src/Assets/AssetContainerContents.php b/src/Assets/AssetContainerContents.php index 8919d76413..270fa1cf7f 100644 --- a/src/Assets/AssetContainerContents.php +++ b/src/Assets/AssetContainerContents.php @@ -5,6 +5,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use League\Flysystem\DirectoryListing; +use Statamic\Facades\Stache; use Statamic\Statamic; use Statamic\Support\Str; @@ -313,6 +314,6 @@ private function key() private function ttl() { - return config('statamic.stache.watcher') ? 0 : null; + return Stache::isWatcherEnabled() ? 0 : null; } } diff --git a/src/Facades/Stache.php b/src/Facades/Stache.php index 6a321cbd1a..a401fc80c3 100644 --- a/src/Facades/Stache.php +++ b/src/Facades/Stache.php @@ -24,6 +24,7 @@ * @method static mixed|null buildDate() * @method static self disableUpdatingIndexes() * @method static bool shouldUpdateIndexes() + * @method static bool isWatcherEnabled() * * @see \Statamic\Stache\Stache */ diff --git a/src/Providers/AppServiceProvider.php b/src/Providers/AppServiceProvider.php index 83e71c5dd3..4758352636 100644 --- a/src/Providers/AppServiceProvider.php +++ b/src/Providers/AppServiceProvider.php @@ -12,6 +12,7 @@ use Statamic\Facades\Addon; use Statamic\Facades\Preference; use Statamic\Facades\Site; +use Statamic\Facades\Stache; use Statamic\Facades\Token; use Statamic\Fields\FieldsetRecursionStack; use Statamic\Sites\Sites; @@ -196,7 +197,7 @@ protected function addAboutCommandInfo() AboutCommand::add('Statamic', [ 'Version' => fn () => Statamic::version().' '.(Statamic::pro() ? 'PRO' : 'Solo'), 'Addons' => $addons->count(), - 'Stache Watcher' => config('statamic.stache.watcher') ? 'Enabled' : 'Disabled', + 'Stache Watcher' => fn () => $this->stacheWatcher(), 'Static Caching' => config('statamic.static_caching.strategy') ?: 'Disabled', 'Sites' => fn () => $this->sitesAboutCommandInfo(), ]); @@ -206,6 +207,17 @@ protected function addAboutCommandInfo() } } + private function stacheWatcher() + { + $status = Stache::isWatcherEnabled() ? 'Enabled' : 'Disabled'; + + if (config('statamic.stache.watcher') === 'auto') { + $status .= ' (auto)'; + } + + return $status; + } + private function sitesAboutCommandInfo() { if (($sites = Site::all())->count() === 1) { diff --git a/src/Stache/Stache.php b/src/Stache/Stache.php index 29e164c817..ba9684da05 100644 --- a/src/Stache/Stache.php +++ b/src/Stache/Stache.php @@ -204,4 +204,13 @@ public function duplicates() return $this->duplicates = (new Duplicates($this))->load(); } + + public function isWatcherEnabled(): bool + { + $config = config('statamic.stache.watcher'); + + return $config === 'auto' + ? app()->isLocal() + : (bool) $config; + } } diff --git a/src/Stache/Stores/CollectionsStore.php b/src/Stache/Stores/CollectionsStore.php index b4ab6f94a7..81b7067b61 100644 --- a/src/Stache/Stores/CollectionsStore.php +++ b/src/Stache/Stores/CollectionsStore.php @@ -132,7 +132,7 @@ private function updateEntriesWithinIndex($index, $ids) public function handleFileChanges() { - if ($this->fileChangesHandled || ! config('statamic.stache.watcher')) { + if ($this->fileChangesHandled || ! Stache::isWatcherEnabled()) { return; } diff --git a/src/Stache/Stores/ContainerAssetsStore.php b/src/Stache/Stores/ContainerAssetsStore.php index 4d227ddd4b..c8650dbaea 100644 --- a/src/Stache/Stores/ContainerAssetsStore.php +++ b/src/Stache/Stores/ContainerAssetsStore.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Cache; use Statamic\Facades\AssetContainer; +use Statamic\Facades\Stache; use Statamic\Statamic; use Statamic\Support\Str; @@ -25,7 +26,7 @@ public function handleFileChanges() $this->fileChangesHandled = true; - if (! config('statamic.stache.watcher')) { + if (! Stache::isWatcherEnabled()) { return; } diff --git a/src/Stache/Stores/Store.php b/src/Stache/Stores/Store.php index 6ff33ca044..d630c5596d 100644 --- a/src/Stache/Stores/Store.php +++ b/src/Stache/Stores/Store.php @@ -174,7 +174,7 @@ public function handleFileChanges() // This whole process can be disabled to save overhead, at the expense of needing to update // the cache manually. If the Control Panel is being used, or the cache is cleared when // deployed, for example, this will happen naturally and disabling is a good idea. - if (! config('statamic.stache.watcher')) { + if (! Stache::isWatcherEnabled()) { return; } diff --git a/src/Stache/Stores/TaxonomyTermsStore.php b/src/Stache/Stores/TaxonomyTermsStore.php index 0c3fd5018a..d78837d3e6 100644 --- a/src/Stache/Stores/TaxonomyTermsStore.php +++ b/src/Stache/Stores/TaxonomyTermsStore.php @@ -132,7 +132,7 @@ protected function makeTerm($taxonomy, $slug) public function handleFileChanges() { - if ($this->fileChangesHandled || ! config('statamic.stache.watcher')) { + if ($this->fileChangesHandled || ! Stache::isWatcherEnabled()) { return; } diff --git a/tests/Stache/StacheTest.php b/tests/Stache/StacheTest.php index 6f835e9f76..f8be258d5e 100644 --- a/tests/Stache/StacheTest.php +++ b/tests/Stache/StacheTest.php @@ -4,12 +4,13 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Collection; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\TestCase; use Statamic\Stache\Stache; use Statamic\Stache\Stores\ChildStore; use Statamic\Stache\Stores\CollectionsStore; use Statamic\Stache\Stores\EntriesStore; +use Tests\TestCase; class StacheTest extends TestCase { @@ -17,6 +18,7 @@ class StacheTest extends TestCase public function setUp(): void { + parent::setUp(); $this->stache = new Stache; } @@ -125,4 +127,30 @@ public function it_can_record_its_build_time() { $this->markTestIncomplete(); } + + #[Test] + #[DataProvider('watcherProvider')] + public function it_can_determine_if_watcher_is_enabled($environment, $config, $expected) + { + app()['env'] = $environment; + + config(['statamic.stache.watcher' => $config]); + + $this->assertEquals($expected, $this->stache->isWatcherEnabled()); + } + + public static function watcherProvider() + { + return [ + ['local', 'config' => true, 'expected' => true], + ['production', 'config' => true, 'expected' => true], + ['local', 'config' => false, 'expected' => false], + ['production', 'config' => false, 'expected' => false], + ['local', 'config' => 'auto', 'expected' => true], + ['production', 'config' => 'auto', 'expected' => false], + ['other', 'config' => 'auto', 'expected' => false], + ['local', 'config' => null, 'expected' => false], + ['production', 'config' => null, 'expected' => false], + ]; + } } diff --git a/tests/Stache/Stores/AssetContainersStoreTest.php b/tests/Stache/Stores/AssetContainersStoreTest.php index 496c396055..8bab62bfdc 100644 --- a/tests/Stache/Stores/AssetContainersStoreTest.php +++ b/tests/Stache/Stores/AssetContainersStoreTest.php @@ -114,6 +114,7 @@ public function it_saves_to_disk() Facades\Stache::shouldReceive('shouldUpdateIndexes')->andReturnTrue(); Facades\Stache::shouldReceive('duplicates')->andReturn(optional()); Facades\Stache::shouldReceive('store')->with('users')->andReturn((new UsersStore((new Stache)->sites(['en']), app('files')))->directory($this->tempDir)); + Facades\Stache::shouldReceive('isWatcherEnabled')->andReturnTrue(); $container = Facades\AssetContainer::make('new') ->title('New Container'); From af2b4f1b21549ea975f4b85413ff6803cf9cae38 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Jun 2024 18:17:35 +0100 Subject: [PATCH 004/486] [5.x] Hide "Restore Revision" button when user is missing relevant permissions (#10314) --- resources/js/components/entries/PublishForm.vue | 1 + resources/js/components/revision-history/History.vue | 2 ++ resources/js/components/revision-history/Revision.vue | 2 ++ .../CP/Collections/RestoreEntryRevisionController.php | 5 +++++ 4 files changed, 10 insertions(+) diff --git a/resources/js/components/entries/PublishForm.vue b/resources/js/components/entries/PublishForm.vue index 42ebbdab6f..d56dbc390c 100644 --- a/resources/js/components/entries/PublishForm.vue +++ b/resources/js/components/entries/PublishForm.vue @@ -259,6 +259,7 @@ :index-url="actions.revisions" :restore-url="actions.restore" :reference="initialReference" + :can-restore-revisions="!readOnly" @closed="close" /> diff --git a/resources/js/components/revision-history/History.vue b/resources/js/components/revision-history/History.vue index c1b897911e..1c70104077 100644 --- a/resources/js/components/revision-history/History.vue +++ b/resources/js/components/revision-history/History.vue @@ -36,6 +36,7 @@ :revision="revision" :restore-url="restoreUrl" :reference="reference" + :can-restore-revisions="canRestoreRevisions" @working-copy-selected="close" /> @@ -60,6 +61,7 @@ export default { indexUrl: String, restoreUrl: String, reference: String, + canRestoreRevisions: Boolean, }, data() { diff --git a/resources/js/components/revision-history/Revision.vue b/resources/js/components/revision-history/Revision.vue index 0796fc7632..6905e40dac 100644 --- a/resources/js/components/revision-history/Revision.vue +++ b/resources/js/components/revision-history/Revision.vue @@ -33,6 +33,7 @@ >