Giter Site home page Giter Site logo

statamic / eloquent-driver Goto Github PK

View Code? Open in Web Editor NEW
105.0 12.0 72.0 340 KB

Provides support for storing your Statamic data in a database, rather than flat files.

Home Page: https://statamic.dev/tips/storing-content-in-a-database

License: MIT License

PHP 100.00%
laravel statamic eloquent database cms

eloquent-driver's Introduction

Statamic Eloquent Driver

Provides support for storing your Statamic data in a database, rather than flat files.

Installation & Usage

You can install and configure the Eloquent Driver using a single command:

php please install:eloquent-driver

The command will install the statamic/eloquent-driver package, publish the config file, then prompt you to select which repositories you wish to move to the database. The command will then publish the relevant migrations and run php artisan migrate behind the scenes.

The command will also give you the opportunity to indicate whether you'd like existing data to be imported.

Importing flat-file content

If you originally opt-out of importing existing content, then later change your mind, you can import existing content by running the relevant commands:

  • Assets: php please eloquent:import-assets
  • Blueprints and Fieldsets: php please eloquent:import-blueprints
  • Collections: php please eloquent:import-collections
  • Entries: php please eloquent:import-entries
  • Forms: php please eloquent:import-forms
  • Globals: php please eloquent:import-globals
  • Navs: php please eloquent:import-navs
  • Revisions: php please eloquent:import-revisions
  • Taxonomies: php please eloquent:import-taxonomies
  • Sites: php please eloquent:import-sites

Syncing Assets

If your assets are being driven by the Eloquent Driver and you're managing your assets outside of Statamic (eg. directly in the filesystem), you should run the php please eloquent:sync-assets command to add any missing files to the database, and remove files that no longer exist on the filesystem.

Exporting to flat files

If you wish to move back to flat-files, you may use the following commands to export your content out of the database:

  • Assets: php please eloquent:export-assets
  • Blueprints and Fieldsets: php please eloquent:export-blueprints
  • Collections: php please eloquent:export-collections
  • Entries: php please eloquent:export-entries
  • Forms: php please eloquent:export-forms
  • Globals: php please eloquent:export-globals
  • Navs: php please eloquent:export-navs
  • Revisions: php please eloquent:export-revisions
  • Taxonomies: php please eloquent:export-taxonomies
  • Sites: php please eloquent:export-sites

Configuration

The configuration file, found in config/statamic/eloquent-driver.php is automatically published when you install the Eloquent Driver.

For each of the repositories, it allows you to determine if they should be driven by flat-files (file) or Eloquent (eloquent). Some repositories also have additional options, like the ability to override the model used.

Mapping Entry data

If you want to map fields from your blueprints to columns with the same handle in your blueprint, set entries.map_data_to_columns to true. When adding new columns in a migration we recommend resaving all Entries so that column data is filled: Entry::all()->each->save().

Upgrading

After updating to a new version of the Eloquent Driver, please ensure you run php artisan migrate to update your database to the latest schema.

Questions

Can I store users in the database too?

By default, Statamic users live in the users directory of your project. If you wish to move them to the database, please follow this guide.

Can I store some collections in the database, while keeping others in flat-files?

This driver does not make it possible to have some collections flat-file driven and others Eloquent driven. If you're looking for that, you may want to checkout the Runway addon, which is part of The Rad Pack.

eloquent-driver's People

Contributors

ajcsilva avatar alt-ben avatar andreasbohman avatar dejury avatar dimitri-koenig avatar dnwjn avatar duncanmcclean avatar edalzell avatar enespolat24 avatar frittenkeez avatar georgecoca avatar helloiamlukas avatar jackmcdade avatar jasonvarga avatar jesseleite avatar jonassiewertsen avatar ken-vde avatar mkwia avatar modrictin avatar nckrtl avatar petemolinero avatar phpsa avatar piljac1 avatar robdekort avatar ryanmitchell avatar stylecibot avatar sylvesterdamgaard avatar vintagesucks avatar wonderne avatar yaser2490 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eloquent-driver's Issues

Only entries are stored in DB

After running:

composer require statamic/eloquent-driver
php artisan vendor:publish --tag="statamic-eloquent-config"
And running the steps for a fresh install,

I found that there was only an Entries table in the DB and that in the config also only Entries are specified.

How can I enable the other items as well?

[Planetscale Compatibility] Add option to skip foreign key constraints

I'm working on testing Statamic with PlanetScale and ran into this issue here:

 SQLSTATE[HY000]: General error: 1105 foreign key constraints are not allowed, see https://vitess.io/blog/2021-06-15-online-ddl-why-no-fk/ (SQL: alter table `form_submissions` add constraint `form_submissions_form_id_foreign` foreign key (`form_id`) references `forms` (`id`) on delete cascade)

I'm not quite sure what the best way to check for configure excluding this line.

Thoughts?

Filters should be case insensitive

Using the Eloquent driver for entries.

When I try to filter the entries, it's taking the search w/ case sensitivity. i.e.. I have an entry w/ title of Cochon, but I can't filter on coch, only finds it if I do Coch.

I am using Postgres, which is case SENSITIVE by default. Additionally we're in JSON land here so that may also be a factor.

Errors: Access level to Statamic\Eloquent\Fields\BlueprintRepository must be protected

I am getting errors at both php please eloquent:import-entries and just visting any page accessing data from an entry. I have been able to fix this myself by editing Statamic\Eloquent\Fields\BlueprintRepository and changing occurrences private in front of properties and methods to protected.
This is the first error I got:

Access level to Statamic\Eloquent\Fields\BlueprintRepository::BLINK_FOUND must be protected (as in class Statamic\Fields\BlueprintRepository) or weaker

Screenshot of error in console:
image

Return values from columns before data field

I tried to use a sitemap addon (https://github.com/pecotamic/sitemap) and updated_at was always giving errors.

EntryModel will always get values from the data-column before any other column. I think this should be changed to be the other way around -> First read column values then values from the data-column.

The following code is the issue:

return Arr::get($this->getAttributeValue('data'), $key, parent::getAttribute($key));

After I changed the code it worked:
return parent::getAttribute($key) ?? Arr::get($this->getAttributeValue('data'), $key);

I think it would also be a good idea to filter out values from data if column for that value exists. Currently updated_at exist as column and gets saved in data

Postgres: Can't create entry

Description

When using Postgres, the following error will be thrown when trying to create a new entry:

SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "id" violates not-null constraint

The driver tries to use null as value for the id column for new entries.

return $class::findOrNew($this->id())->fill([
'id' => $this->id(),
'origin_id' => $this->origin()?->id(),

Can we just delete this line, so that the id will not be written? Or is there any case where we need the id to be there?

Reorder collection does not working

Hey, i'm using statamic 3.2.37 with eloquent driver and i'm having this issue https://github.com/statamic/cms/issues/3620

any idea how to solve this ?

CollectionRepository does not use custom models

The driver allows to specify a different EntryModel in config/statamic-eloquent-driver.php by setting entries.model.

image

However, the CollectionRepository is currently hardcoded to use the shipped EntryModel:

image

This leads to errors when updating entries. A PR will be provided to fix it.

Required Date Field Issue

Hi,

i don't know if it is an eloquent driver issue but this issue occurred since i installed this driver.

I have a date field in a collection:
handle: date
field:
type: date
validate:
- required

  • Creating an entry, no problem.
  • Editing an entry ->
    image
    but this field has a value.
    After setting a value and editing this entry again the date error occurred again.

KR M

Paginated entry queries get their values overwritten

Example code:

$paginator = Entry::query()
	->where('collection', 'guest_reviews')
	->paginate($args['first'] ?? 1, ['*'], 'testPageName', 3);

In the above example, I'm explicitly setting the requested page to 3, however, this is always overwritten back to 1. I think this is occurring in EntryQueryBuilder.php:70 where the page and pageName variables are being set back to page and 1 respectively.

Statamic version 3.3.43
Eloquent driver version 1.0.1

Use different Eloquent models for different collections

I would really like to use Statamic in a project with a traditional datbase layout, but it looks like it's impossible or very difficult.

I have tried following the code in this repository (and the guide in the knowledge base) to implement this myself. It seemed promising since Statamic uses a repository, but currently this driver (and Statamic in general) assumes that all entries, in any collection, are stored in a single database table. This approach works when using a JSON data column, but fails when trying to apply it to a more traditional database layout where different kinds of content are stored in different tables.

Also when trying to see if I could somehow get around this limitation by making a clever QueryBuilder implementation I noticed that many of the interfaces (like Statamic\Contracts\Entries\QueryBuilder) are empty, so it's difficult to know what methods need to be implemented.

Anyway, is this feature even possible to implement?

Live Preview Error

Hi,

when i use the live preview on a new entry and the entry is not saved, i get the following error.

Trying to get property 'origin' of non-object

Bildschirmfoto 2021-01-27 um 17 37 12

Uuid model database migration does not place unique constraint on id column

As the title says. Ironically enough, the migration does not make the first id column unique, which means multiple entries could exist with the same Uuid. In most cases, that wouldn't be an issue as the same Uuid wouldn't be generated twice, but I stumbled upon it while browsing the database in phpMyAdmin. The following warning is shown there:
image
I cannot edit any entries directly in the database browser, because there is no single column uniquely identifying the entry.

Simple fix would be to add ->primary(); at the end of the id column definition in the UuidEntryModel migration, although that will not fix existing installations.

Where on join query with alias not work

Where on join query with alias not work

When a where clause apply on join query with alias, it cannot parse the correct where.

Let us consider the following query.

PHP Query

$query = Entry::query()
  // join self as e
  ->join('entries as e',fn($join) => $join
  ->whereColumn('e.id', 'entries.id')
  ->where('e.collection', 'properties')
  ->where('e.published', 1)
);
// join locations
$query->leftJoin('entries as locations', function($join) {
    $join
        ->where('locations.collection', 'locations')
        ->on('locations.id', 'e.data->location')
        ;
});
// where on joint clause
$query
  // this is expected to search on the JSON data field for property_type
  ->where('e.data->property_type', 'lodge')
  // this is expected to search on the locations slug for value 'shaldon'
  ->where('locations.slug', 'shaldon')
;

SQL Generated

The where property_type putting the e.data in the json key field but not the data field

select * from `entries`
  inner join `entries` as `e`
    on `e`.`id` = `entries`.`id` and `e`.`collection` = 'properties' and `e`.`published` = '1'
  left join `entries` as `locations`
    on `locations`.`collection` = 'locations' and `locations`.`id` = json_unquote(json_extract(`e`.`data`, '$."location"'))
  where
    json_unquote(json_extract(`data`, '$."e.data"."property_type"')) = 'lodge' // Wrong SQL
    and json_unquote(json_extract(`data`, '$."locations.slug"')) = 'shaldon' // Wrong SQL

SQL Expected

select * from `entries`
  inner join `entries` as `e`
    on `e`.`id` = `entries`.`id` and `e`.`collection` = 'properties' and `e`.`published` = '1'
  left join `entries` as `locations`
    on `locations`.`collection` = 'locations' and `locations`.`id` = json_unquote(json_extract(`e`.`data`, '$."location"')) 
  where
    json_unquote(json_extract(`e`.`data`, '$."property_type"')) = 'lodge' // SQL expected
    and `locations`.`slug` = 'shaldon' // SQL expected

Cause

The problem caused by the column check in src/Entries/EntryQueryBuilder.php.

protected function column($column)
{
    if ($column == 'origin') {
        $column = 'origin_id';
    }

    if (! in_array($column, self::COLUMNS)) {
        $column = 'data->'.$column;
    } else {
        $column = parent::column($column);
    }

    return $column;
}

Multiple taxonomy terms returned when same term exists for multiple taxonomies

When multiple terms with same slugs exists in different taxonomies, e.g.
Taxonomy: Tags, Term: Pop
Taxonomy: Genres, Term: Pop
then for a collection entry where only one taxonomy is attached (e.g. Genres), both Terms (tags/pop and genres/pop) are returned on control panel listing (and who knows where else)
It's an issue in Taxonomies/TermQueryBuilder.php where and whereIn functions, because the taxonomy-wheres aren't applied in this case.

origin_id in localized entries are causing error

I was trying to import 8804 entries from a current page with php please eloquent:import-entries.

It stopped with:

Call to a member function id() on string

  at vendor/statamic/eloquent-driver/src/Entries/Entry.php:46
     42▕         }
     43▕
     44▕         return $class::findOrNew($this->id())->fill([
     45▕             'id'         => $this->id(),
  ➜  46▕             'origin_id'  => $this->origin()?->id(),
     47▕             'site'       => $this->locale(),
     48▕             'slug'       => $this->slug(),
     49▕             'uri'        => $this->uri(),
     50▕             'date'       => $this->hasDate() ? $this->date() : null,

When I removed the translated data folders (with about 587 entries), it finishes without any problems. Any ideas?

Statamic 3.3.43 Pro
Laravel 8.83.25
PHP 8.0.16
statamic/collaboration 0.4.0
statamic/eloquent-driver 1.0.1

Clear Cache Error

Hi,

clearing the content Stache cache manually runs into an error:

ErrorException
Trying to get property 'origin' of non-object
/admin/utilities/cache/cache/stache

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
vendor/statamic/eloquent-driver/src/Entries/Entry.php:72

Query params on content API broken

Hi!

After migrating my existing data to the db, query params on the content API stoped working. For example, when
I try to set fields=id,title,slug I am getting

local.ERROR: Call to a member function cascade() on null {"exception":"[object] (Error(code: 0): Call to a member function cascade() on null at /Volumes/Daten/meso/statamic-v3/vendor/statamic/cms/src/Entries/Entry.php:705)

Setup:
Statamic 3.1.9 Pro
Laravel 7.30.4
PHP 8.0.3
statamic/eloquent-driver 0.1.1

Any ideas?

Internal Server Error while refreshing Statamic stache

While clearing the content stache from the Statamic control panel, I am getting a Trying to get property 'origin' of non-object error. Not sure what is going wrong or why, but it is definitely not supposed to happen. Let me know if I should add any more information.

Full stacktrace below:

ErrorException:
Trying to get property 'origin' of non-object

  at vendor/statamic/eloquent-driver/src/Entries/Entry.php:79
  at Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
     (vendor/statamic/eloquent-driver/src/Entries/Entry.php:79)
  at Statamic\Eloquent\Entries\Entry->origin()
     (vendor/statamic/cms/src/Stache/Indexes/Origin.php:9)
  at Statamic\Stache\Indexes\Origin->getItemValue()
     (vendor/statamic/cms/src/Stache/Indexes/Value.php:12)
  at Statamic\Stache\Indexes\Value->Statamic\Stache\Indexes\{closure}()
  at array_map()
     (vendor/laravel/framework/src/Illuminate/Collections/Collection.php:664)
  at Illuminate\Support\Collection->map()
     (vendor/statamic/cms/src/Stache/Indexes/Value.php:13)
  at Statamic\Stache\Indexes\Value->getItems()
     (vendor/statamic/cms/src/Stache/Indexes/Index.php:90)
  at Statamic\Stache\Indexes\Index->update()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60)
  at Illuminate\Support\HigherOrderCollectionProxy->Illuminate\Support\{closure}()
     (vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:242)
  at Illuminate\Support\Collection->each()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61)
  at Illuminate\Support\HigherOrderCollectionProxy->__call()
     (vendor/statamic/cms/src/Stache/Stores/Store.php:393)
  at Statamic\Stache\Stores\Store->warm()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60)
  at Illuminate\Support\HigherOrderCollectionProxy->Illuminate\Support\{closure}()
     (vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:242)
  at Illuminate\Support\Collection->each()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61)
  at Illuminate\Support\HigherOrderCollectionProxy->__call()
     (vendor/statamic/cms/src/Stache/Stores/AggregateStore.php:75)
  at Statamic\Stache\Stores\AggregateStore->warm()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60)
  at Illuminate\Support\HigherOrderCollectionProxy->Illuminate\Support\{closure}()
     (vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:242)
  at Illuminate\Support\Collection->each()
     (vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61)
  at Illuminate\Support\HigherOrderCollectionProxy->__call()
     (vendor/statamic/cms/src/Stache/Stache.php:109)
  at Statamic\Stache\Stache->warm()
     (vendor/statamic/cms/src/Stache/Stache.php:98)
  at Statamic\Stache\Stache->refresh()
     (vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261)
  at Illuminate\Support\Facades\Facade::__callStatic()
     (vendor/statamic/cms/src/Http/Controllers/CP/Utilities/CacheController.php:91)
  at Statamic\Http\Controllers\CP\Utilities\CacheController->clearStacheCache()
     (vendor/statamic/cms/src/Http/Controllers/CP/Utilities/CacheController.php:76)
  at Statamic\Http\Controllers\CP\Utilities\CacheController->clear()
     (vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54)
  at Illuminate\Routing\Controller->callAction()
     (vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45)
  at Illuminate\Routing\ControllerDispatcher->dispatch()
     (vendor/laravel/framework/src/Illuminate/Routing/Route.php:262)
  at Illuminate\Routing\Route->runController()
     (vendor/laravel/framework/src/Illuminate/Routing/Route.php:205)
  at Illuminate\Routing\Route->run()
     (vendor/laravel/framework/src/Illuminate/Routing/Router.php:695)
  at Illuminate\Routing\Router->Illuminate\Routing\{closure}()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/CountUsers.php:18)
  at Statamic\Http\Middleware\CP\CountUsers->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/Localize.php:19)
  at Statamic\Http\Middleware\CP\Localize->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/Authorize.php:25)
  at Statamic\Http\Middleware\CP\Authorize->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/AddToasts.php:22)
  at Statamic\Http\Middleware\CP\AddToasts->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/AuthGuard.php:14)
  at Statamic\Http\Middleware\CP\AuthGuard->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CP/ContactOutpost.php:21)
  at Statamic\Http\Middleware\CP\ContactOutpost->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:50)
  at Illuminate\Routing\Middleware\SubstituteBindings->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:78)
  at Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49)
  at Illuminate\View\Middleware\ShareErrorsFromSession->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:121)
  at Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
     (vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64)
  at Illuminate\Session\Middleware\StartSession->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37)
  at Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67)
  at Illuminate\Cookie\Middleware\EncryptCookies->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/SwapExceptionHandler.php:19)
  at Statamic\Http\Middleware\SwapExceptionHandler->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
  at Illuminate\Pipeline\Pipeline->then()
     (vendor/laravel/framework/src/Illuminate/Routing/Router.php:697)
  at Illuminate\Routing\Router->runRouteWithinStack()
     (vendor/laravel/framework/src/Illuminate/Routing/Router.php:672)
  at Illuminate\Routing\Router->runRoute()
     (vendor/laravel/framework/src/Illuminate/Routing/Router.php:636)
  at Illuminate\Routing\Router->dispatchToRoute()
     (vendor/laravel/framework/src/Illuminate/Routing/Router.php:625)
  at Illuminate\Routing\Router->dispatch()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:167)
  at Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/DisableFloc.php:18)
  at Statamic\Http\Middleware\DisableFloc->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CheckMultisite.php:14)
  at Statamic\Http\Middleware\CheckMultisite->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/CheckComposerJsonScripts.php:21)
  at Statamic\Http\Middleware\CheckComposerJsonScripts->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php:19)
  at Statamic\Http\Middleware\PoweredByHeader->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
  at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31)
  at Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
  at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php:40)
  at Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27)
  at Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:86)
  at Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/fruitcake/laravel-cors/src/HandleCors.php:38)
  at Fruitcake\Cors\HandleCors->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/fideloper/proxy/src/TrustProxies.php:57)
  at Fideloper\Proxy\TrustProxies->handle()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
     (vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
  at Illuminate\Pipeline\Pipeline->then()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:142)
  at Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
     (vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:111)
  at Illuminate\Foundation\Http\Kernel->handle()
     (public/index.php:52)
$ php please support:details
Statamic 3.2.21 Pro
Laravel 8.69.0
PHP 7.4.3
doublethreedigital/simple-commerce 2.3.50
statamic/eloquent-driver 0.2.0
statamic/seo-pro 2.3.2

Editing parents of mounted entries don't always update child entry uris

  • When editing the slug of a parent to a set of mounted entries, child uris are not updated
  • When editing the tree nesting of a parent to a set of mounted entries, child uris are not updated

This is because eloquent is much more heavy-handed about filtering ids for performance reasons, etc. See https://github.com/statamic/eloquent-driver/blob/master/src/Entries/CollectionRepository.php#L13-L15...

if ($ids) {
    $query->whereIn('id', $ids);
}

Though I created the issue here, I'm wondering if the best fix might be in Statamic core; Maybe we could pass a smarter list of $ids into this function, taking mounted entries into account.

Moving assets from one folder to another does not work

When I try to move an asset from one folder to another I get an error. Console logs identifies the problem and it looks like it searches for an actual metafile for the assets.

196404007-897ddbce-bfb6-41df-8d14-17a69b0b4e25

Support details:
Statamic 3.3.43 Pro
Laravel 8.83.23
PHP 8.0.23
r8edge/imagemap dev-main
r8edge/welcome-widget dev-main
statamic/eloquent-driver 1.0.1

Importing taxonomy terms separately from taxonomies

Taxonomies and Terms can be configured separately to use file or eloquent driver.
But only one command exists, which would import both of them.
If you need to import taxonomies or terms only, you can't do it.

Can it be done by creating a new command for importing terms, and call e.g. php please eloquent:import-terms?
And delete the import terms part from import-taxonomies command?
Or was there a certain reason for using them together?

Support multi-site

Trying to convert a site to multisite via php please multisite results in:

  Call to a member function hydrate() on null

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:548
    544▕      * @return \Illuminate\Database\Eloquent\Model[]|static[]
    545▕      */
    546▕     public function getModels($columns = ['*'])
    547▕     {
  ➜ 548▕         return $this->model->hydrate(
    549▕             $this->query->get($columns)->all()
    550▕         )->all();
    551▕     }
    552▕ 

      +2 vendor frames 
  3   app/Tables/EntryQueryBuilder.php:43
      Statamic\Query\EloquentQueryBuilder::get()

  4   app/Tables/CollectionRepository.php:29
      App\Tables\EntryQueryBuilder::get()

Problem with entries coming from a seeder

Everything works fine with the CP where you can add/edit entries. In the front index and show works fine. Single taxonomy pages are also working as normal.

Than you insert 1000 entries through a seeder.

 $news = new Entry();
 $news->site = 'default';
 $news->published = 1;
 $news->status = 'published';
 $news->slug = $slug;
 $news->uri = 'news/' . $slug;
 $news->collection = 'news';
 $news->data = $data;
 $news->created_at = \Carbon\Carbon::now();
 $news->save();

$data and the other variables are working just fine and you end up with the following code in the DB:
id: 10 (incremental), site: 'default', origin_id: null, published: 1, status: 'published', slug: 'porro-eveniet-ipsam-tempora-et', uri: 'news/porro-eveniet-ipsam-tempora-et', date: null, collection: 'news', data: {"tags": ["clothes", "games", "space"], "title": "Porro eveniet ipsam tempora et.", "author": 1, "content": "Itaque quos qui sint..", "gallery": [], "pub_date": "2019-03-09", "updated_at": 1607932935, "updated_by": 1, "featured_image": null, "news_categories": ["nature", "fashion"]}, created_at: '2020-12-14 09:41:53'

Absolutely the same as the entries that you create from the CP. You can see/edit/delete the seeder ones normally. But in the front the Show page gives Not Found. In the taxonomy pages (/news/tags/nature) {{ tags }} lists only the CP created entries. The problem is fixed if you edit and save a seeder entry in the CP.

If you follow the code chain of the Not Found error you get to
Statamic/cms/sc/Stache/Repositories/EntryRepository.php findByUri() function
If you dd() the following for the seeder entry you get NULL and for a normal CP entry - Statamic\Eloquent\Entries\Entry:

 $entry = $this->query()
                ->where('uri', $uri)
                ->where('site', $site)
                ->first();

I have the users in the database and I use incremented ID for entries, following the instructions in the Eloquent package.

Fatal error exception after upgrade of statamic/cms to version v3.3.57

Symfony\Component\ErrorHandler\Error\FatalError
Access level to Statamic\Eloquent\Fields\BlueprintRepository::BLINK_FOUND must be protected (as in class Statamic\Fields\BlueprintRepository) or weaker

It looks like the visibility has been changed from protected to private of several constants methods in the class: src/Fields/BlueprintRepository.php from the statamic/cms package and Statamic\Eloquent\Fields\BlueprintRepository extends this class.

This is the commit where the change occurred: https://github.com/statamic/cms/pull/6588/files

In the context of this package its obviously a breaking change, so unsure whether this should actually be raised in the statamic/cms repository instead, happy to move the issue over there if this is the case.

Class name must be a valid object or a string

I just installed this package, ran the migrations and get the error Class name must be a valid object or a string when accessing the CP or any Collection in the frontend.

Error is in file vendor/statamic/eloquent-driver/src/ServiceProvider.php on line 44. Am I missing something important? There's not really much documented for the setup so I'd figure it was straightforward.

Screenshot 2021-03-01 at 13 51 28

Parent not valid when creating a Child in a Structured Collection

When I use the "Create Child Entry" option to create a new entry with a particular parent the parent does not seem to be valid.

image

image

When I convert the request parameter to type int in the create method of the EntriesController (here) the issue seems to be resolved.
Even though this is not part of the eloquent-driver I imagine the problem being that the eloquent driver somewhere expects an int id where it gets the string from the request parameter.

Support for optional slugs

Since Statamic 3.2.27, slugs can be optional. However, currently, the database table prohibits entries with missing slugs.

If someone tries to save an entry from a collection that has no slugs, it leads to this exception:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null

`fresh()` not returning new instance

Description

If you are editing an entry, save it and try to get a new instance with the fresh() method you will get the outdated entry back.

Example

$entry->set('title', 'New Title');
$entry->save();

dd(
    $entry->fresh()->title,
    \Statamic\Facades\Entry::query()->where('id', $entry->id)->first()->title,
);

This will output two different values.

Existing UUIDs are not used

Hi!

I tried to migrate my data from an existing site into the db following the instructions from the readme.
It seems like the UuidEntryModel creates new Ids? That, to me, fails the purpose of preserving existing relations.

I replaced line 17

$entry->{$entry->getKeyName()} = (string) Str::uuid();

with

$entry->{$entry->getKeyName()} = (string) $entry->getAttribute('id');

and now its fine.

Is this a bug or did I miss something?

Structured Collection: Entry URI only saved after second save

When I modify the slug on the entry page in a structured collection and save it, the URI doesn't get updated.
If I then open the entry admin and save it again the URI is now updated.

Looks like the cause of this behaviour is in statamic/cms/src/Entries/Entry.php

        if ($structure = $this->structure()) {
            return $structure->entryUri($this);
        }

However it might be resolved if we modify the toModel method in statamic/eloquent-driver/src/Entries/Entry.php like so:

        return $class::findOrNew($this->id())->fill([
            'id' => $this->id(),
            'origin_id' => $this->originId(),
            'site' => $this->locale(),
            'slug' => $this->slug(),
-            'uri' => $this->uri(),
+            'uri' => $this->slug(),
            'date' => $this->hasDate() ? $this->date() : null,
            'collection' => $this->collectionHandle(),
            'data' => $data->except(EntryQueryBuilder::COLUMNS),
            'published' => $this->published(),
            'status' => $this->status(),
        ]);

Or is this something that should be addressed in the core repository?

Thanks in advance

Content API: Selecting Fields not working / error

Bug Description

If you try to select just specific fields (exactly as described in the documentation), nothing happens or an error will be thrown.

How to Reproduce

Problem 1: Selecting Fields has no effect

Request

http://statamic.test/api/collections/newsletters/entries?fields=title

Response

Bildschirmfoto 2021-08-09 um 14 00 31

I would expect only the `title` attribute of each entry shown here.

Problem 2: Error when specifying specific fields

Request

http://statamic.test/api/collections/newsletters/entries?fields=id
or
http://statamic.test/api/collections/newsletters/entries?fields=date
or
http://statamic.test/api/collections/newsletters/entries?fields=uri

Response

Error: Call to a member function cascade() on null
Bildschirmfoto 2021-08-09 um 14 09 34

Environment

Statamic 3.1.32 Pro
Laravel 8.40.0
PHP 7.4.19
statamic/collaboration 0.1.0

Install method (choose one):

  • Fresh install from statamic/statamic

Updated timestamp not working

The TracksLastModified trait has the function :

public function lastModified()
    {
        return $this->has('updated_at')
            ? Carbon::createFromTimestamp($this->get('updated_at'))
            : $this->fileLastModified();
    }

It expects the updated_at to be a timestamp, but the Eloquent driver set a Carbon object.

We use this patch :

diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php
index 3344c2e..42e732c 100644
--- a/src/Entries/Entry.php
+++ b/src/Entries/Entry.php
@@ -25,7 +25,9 @@ class Entry extends FileEntry
             ->model($model);

         if (config('statamic.system.track_last_update')) {
-            $entry->set('updated_at', $model->updated_at ?? $model->created_at);
+            if ($updated_at = $model->updated_at ?? $model->created_at) {
+                $entry->set('updated_at', $updated_at->timestamp);
+            }
         }

         return $entry;

Problems importing existing file based content into database

I have installed the eloquent driver and the migrations were successfully created and the tables also seem to be correct at the database.
However, when I try to import existing data, such as assets, by running the command: php please eloquent import-assets I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'handle' in 'where clause' (SQL: select * from entries where (handle = assets::./.meta/d126fbc4557e94c2844e1b16db7a434b.png.yaml) limit 1)

Although the assets_meta table has the column "handle" in its structure, the entries table do not have that column:

ddbe674597a13c6afff9726fba62c647

Should I create it manually or did I maybe skip a step at the installation?

Image Meta Issue?

Hi,

maybe i found an issue or a miss configuration on my side?
After editing images while editing an entry, the metadatas are stored in the database but after reloading and editing the image again all fields are empty:
image
image

Any idea?

Eloquent Driver not supporting taxonomies, navigations, globals, or form submissions

Hello Team,

I want to implement Statamic Eloquent Driver in my current existing statamic project, But I've found that this is not supporting taxonomies, navigations, globals, or form submissions.

I want to use Eloquent Driver in all above points, So Can you please provide me any solution for same.

Please let me know in case any other details required.

Waiting for your reply, Please provide me ASAP

Can't select other sites on publish form with eloquent driver and multi site enabled

Bug Description

When using the eloquent driver with multi-site enabled, an Carbon\Exceptions\InvalidFormatException is thrown.
After debugging, I saw that this line is responsible: https://github.com/statamic/cms/blob/3.1/src/Entries/Entry.php#L421

Usually, the date is already a Carbon instance. But because the data field is casted to json (source), it isn't a Carbon instance in this case.

Line 413 checks for the length of the date and tries to create a Carbon instance.

 if (strlen($date) === 10) {
    return Carbon::createFromFormat('Y-m-d', $date)->startOfDay();
}

The problem is, that the format is wrong. The date is a linux timestamp, which has also a length of 10. Therefore the line gets hit, but it expects a different format.

How to Reproduce

  • Setup Multi-Site Installation with at least 2 sites
  • Install & setup eloquent driver
  • Create and save a new page on the default site
  • Click on the other site in the publish form --> error occurs

Extra Detail

image

Environment

Statamic 3.1.26 Pro
Laravel 8.49.0
PHP 8.0.3
statamic/eloquent-driver dev-feature/support-all-models

We are using a dev version of the eloquent driver. But as far as I can see, the issue is not linked to these changes.

Statamic version: 3.1.26

PHP version: 8.0.3

Install method (choose one):

  • Fresh install from statamic/statamic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.