cms icon indicating copy to clipboard operation
cms copied to clipboard

Stache store doesn't handle different app paths correctly

Open simonworkhouse opened this issue 6 months ago • 0 comments

Bug description

The \Statamic\Stache\Stores::handleFileChanges() method erroneously removes valid items from the stache when switching between multiple app directories. We have noticed this when utilising symlinks and/or separate containers with separate mounts.

When this issue occurs it causes errors such as the following:

$php artisan statamic:stache:warm 

   Error 

  Call to a member function requiresSlugs() on null

  at vendor/statamic/cms/src/Stache/Stores/CollectionEntriesStore.php:87
     83▕             ->data($data);
     84▕ 
     85▕         $slug = (new GetSlugFromPath)($path);
     86▕ 
  ➜  87▕         if (! $collection->requiresSlugs() && $slug == $id) {
     88▕             $entry->slug(null);
     89▕         } else {
     90▕             $entry->slug($slug);
     91▕         }

      +2 vendor frames 

  3   [internal]:0
      Statamic\Stache\Stores\Store::Statamic\Stache\Stores\{closure}()
      +39 vendor frames 

  43  artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

Also attempting a second time fails on entries:

$php artisan statamic:stache:warm 

   Error 

  Call to a member function id() on null

  at vendor/statamic/cms/src/Stache/Repositories/EntryRepository.php:166
    162▕ 
    163▕     public function applySubstitutions($items)
    164▕     {
    165▕         return $items->map(function ($item) {
  ➜ 166▕             return $this->substitutionsById[$item->id()] ?? $item;
    167▕         });
    168▕     }
    169▕ 
    170▕     public function updateUris($collection, $ids = null)

  1   [internal]:0
      Statamic\Stache\Repositories\EntryRepository::Statamic\Stache\Repositories\{closure}()
      +39 vendor frames 

  41  [internal]:0
      Statamic\Stache\Query\EntryQueryBuilder::Statamic\Stache\Query\{closure}()

How to reproduce

Execute php artisan statamic:stache:warm in your app folder and attempt to execute it again in a symlink to that folder. Assuming that you have at least one collection configured it will fail with an error Call to a member function requiresSlugs() on null or a Call to a member function id() on null when attempting to process entries.

Logs

N/A

Environment

N/A

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

simonworkhouse avatar Jun 11 '25 05:06 simonworkhouse