statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 73 forks source link

Assets can not be stached after being moved to database #135

Closed Tomodo531 closed 1 year ago

Tomodo531 commented 1 year ago

I am migrating our site's content from flat files to a Postgres database to improve performance. The site works and the files are migrated, but every time I try to run php please stache:refresh, I get the following error when the $handle = 'all':

 TypeError

  Statamic\Eloquent\Assets\AssetContainerRepository::findByHandle(): Return value must be of type ?Statamic\Contracts\Assets\AssetContainer, Illuminate\Support\Collection returned

  at vendor/statamic/eloquent-driver/src/Assets/AssetContainerRepository.php:41
     37▕                 return null;
     38▕             }
     39▕
     40▕             return app(AssetContainerContract::class)->fromModel($model);
  ➜  41▕         });
     42▕     }
     43▕
     44▕     public function make(string $handle = null): AssetContainerContract
     45▕     {

      +33 vendor frames
  34  please:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

When I access the site without the stache is it able to get the assets using the individual $handles, and when I hardcode the $handle inside AssetContainerRepository it works fine but it fails on $handle = 'all'. I presume it is because it gets a collection of AssetContainers but is there a way to fix this?

I also get the following when trying to access assets in the control panel:

TypeError
Statamic\Eloquent\Assets\AssetContainerRepository::all(): Return value must be of type Illuminate\Support\Collection, Statamic\Eloquent\Assets\AssetContainer returned (View: /Users/martin/Sites/sd-statamic/vendor/statamic/cms/resources/views/layout.blade.php) 

Setup:

Statamic 3.4.5 Pro Laravel 8.83.27 PHP 8.1.16 Stache Watcher Enabled Static Caching Disabled adapt/tfa 1.0.1 statamic/eloquent-driver 1.2.0 thehome/statamic-elasticsearch dev-ADP-1213-loadtide-statamic-update

ryanmitchell commented 1 year ago

Should be fixed by https://github.com/statamic/eloquent-driver/pull/136