eloquent-driver icon indicating copy to clipboard operation
eloquent-driver copied to clipboard

Support all models

Open ryanmitchell opened this issue 3 years ago • 129 comments

Sorry for the duplication of PRs here but I have reached out to the authors of both the previous PRs to try and combine efforts but have had no response from either.

As I indicated here I have taken the existing PR (#20) and added the rest of the models. I subsequently discovered the work that has since been opened in #41 and have added the additional blueprints and field sets work from it.

~~I have intentionally not included user groups and role as IMO they should be handled by Statamic core as part of the eloquent users setup.~~ Update: I've opened a PR in statamic/cms for this: https://github.com/statamic/cms/pull/5686

So to confirm this PR includes:

  • [x] taxonomies
  • [x] navigations
  • [x] globals
  • [x] collections
  • [x] form submissions
  • [x] asset containers
  • [x] assets meta
  • [x] blueprints
  • [x] field sets
  • [x] revisions

I have also refactored the code allow for devs to opt in via config to each 'model', I have ensured it uses the bound models, and I have written console import tasks to allow migration from file based data to eloquent.

Finally I have applied fixes from any open PRs and ensured they are included (with the exception of Jason's).

@jasonvarga I'd appreciate it if you could review this and let me know what you think.

ryanmitchell avatar Feb 17 '22 17:02 ryanmitchell

@ryanmitchell great work! Would it be possible to save assets metadata in the database as well?

FrittenKeeZ avatar Feb 25 '22 10:02 FrittenKeeZ

@FrittenKeeZ that had been done in #41 but I didn't carry it over as I'm not sure of why it would be wanted. I struggle to see why you would want it when you're already storing files on the filesystem and so can affect the .meta there. Can you help me understand the use case?

ryanmitchell avatar Feb 25 '22 12:02 ryanmitchell

@ryanmitchell for me it's as much about separation of logic as it is about performance - instead of having to read double amount of files from a disk, all metadata can instead be fetched from the database when needed, instead of spending resources caching it all. Having it as an option though would be appropriate, as not everyone wants or needs this separation, but for someone like us with thousands of assets, it can affect performance a great deal.

FrittenKeeZ avatar Feb 25 '22 12:02 FrittenKeeZ

@FrittenKeeZ no problem - as I said I wouldnt use it but I've added it there any way. I dont want to clutter the config too much so if you opt into asset containers then assets_meta is stored in the database too.

ryanmitchell avatar Feb 25 '22 12:02 ryanmitchell

@ryanmitchell does your PR support revisions as well?

FrittenKeeZ avatar Feb 28 '22 10:02 FrittenKeeZ

@FrittenKeeZ I've added support for it now, would be great if you could test it as I don't use this feature much so I may not have covered off everything.

ryanmitchell avatar Feb 28 '22 12:02 ryanmitchell

Hi and thank you for creating this. Any eta to get this merged?

Hesesses avatar Mar 02 '22 21:03 Hesesses

@Hesesses i wouldn’t expect it to be merged any time soon as I think there will be a significant testing and review process with changes made. You could pull it in as a composer patch in the mean time.

https://rias.be/blog/using-composer-patches

ryanmitchell avatar Mar 03 '22 06:03 ryanmitchell

does that fixes collection reordering issue ?

enespolat24 avatar Mar 09 '22 14:03 enespolat24

does that fixes collection reordering issue ?

@enespolat24 combined with a PR that has been merged in statamic core in the last release yes.

ryanmitchell avatar Mar 09 '22 14:03 ryanmitchell

thank you for your effort. looking forward to see this pr in action !

enespolat24 avatar Mar 09 '22 14:03 enespolat24

i tried this via composer patch but migrate gives error

enespolat24 avatar Mar 19 '22 13:03 enespolat24

i tried this via composer patch but migrate gives error

Can you give details of the error please?

ryanmitchell avatar Mar 19 '22 13:03 ryanmitchell

hi . Sorry for the late reply. image

enespolat24 avatar Mar 22 '22 17:03 enespolat24

@enespolat24 see if this change helps: https://github.com/statamic/eloquent-driver/pull/42/commits/c9f31d68a6d564b1247c4e17a21f8dba039b00bc

ryanmitchell avatar Mar 22 '22 17:03 ryanmitchell

I came up with more errors 🙂 i tried to migrate using a freshly created db

image

enespolat24 avatar Mar 24 '22 00:03 enespolat24

@enespolat24 you should start with a clean site (or clear your migrations). That files doesn't exist in that folder in my PR - see: https://github.com/ryanmitchell/eloquent-driver/tree/fixes-to-all-models-pr/database/migrations

ryanmitchell avatar Mar 24 '22 07:03 ryanmitchell

i have added this pull request but after i save anything in the cp it wont save it in the database

Oleafeon avatar Mar 28 '22 11:03 Oleafeon

i have added this pull request but after i save anything in the cp it wont save it in the database

Can you provide an error trace so I can look into it please.

ryanmitchell avatar Mar 28 '22 11:03 ryanmitchell

i dont get an error it just saves it to the file instead of the database

Oleafeon avatar Mar 28 '22 11:03 Oleafeon

i saw that i cant publish the config file image

Oleafeon avatar Mar 28 '22 11:03 Oleafeon

@Oleafeon i've pushed some fixes here for the issues you were experiencing. Tested on a fresh install and all seems good to me.

You'll need to run: php artisan vendor:publish --tag="statamic-eloquent-config"

then either: php artisan vendor:publish --tag="statamic-eloquent-entries-table" or php artisan vendor:publish --tag="statamic-eloquent-entries-table-with-string-ids"

ryanmitchell avatar Mar 28 '22 12:03 ryanmitchell

fixed thanks

Oleafeon avatar Mar 28 '22 12:03 Oleafeon

I have a problem with creating / saving a collection entry that has enabled revisions. When i create a new entry or try to publish / unpublish i get the following error message:

local.ERROR: Call to a member function except() on array {"userId":1,"exception":"[object] (Error(code: 0): Call to a member function except() on array at [[PROJECT-LOCATION]]\\vendor\\statamic\\eloquent-driver\\src\\Revisions\\Revision.php:47)

When reloading the page after the error message is given the entry is actually created or published / unpublished

RikHeynen avatar Mar 29 '22 13:03 RikHeynen

@RikHeynen odd, I didnt come across that in my testing. What Statamic version are you using? See if this fix helps?

ryanmitchell avatar Mar 29 '22 13:03 ryanmitchell

@ryanmitchell I have tried, but get the following error in cp when added as patch:

Call to a member function handle() on array

RikHeynen avatar Mar 29 '22 14:03 RikHeynen

@RikHeynen do you want to try debugging it and let me know what changes are required? Either that or i would need to know what version you are on to try and replicate it. Maybe you can provide access to a repo with your install?

ryanmitchell avatar Mar 29 '22 14:03 ryanmitchell

@ryanmitchell Thanks for the help! The problem was at our side, so the problem seems to be fixed. Thanks again!

RikHeynen avatar Mar 29 '22 14:03 RikHeynen

Hey @ryanmitchell i work together with @RikHeynen and get the same error: Call to a member function handle() on array

This is my setup:

Statamic 3.3.3 Pro
Laravel 9.5.1
PHP 8.1.2
aerni/font-awesome 1.2.0
rias/statamic-link-it 2.2.3
statamic/eloquent-driver 0.2.0
statamic/seo-pro 3.1.0

The only thing i have different then your package is, i turned saving blueprints en fieldsets off in the config file cause we work with multiple people on the blueprint so we need them on github to merge them.

image

The error shows up after editing the settings of a collection in the cp, saving is okay but after we go to the collection page in the cp we see the error.

I also found an error when creating a navigation that said: Call to a member function validateTree() on null

I have my log file for you here: https://pastebin.com/xYi4LsSi

Oleafeon avatar Apr 01 '22 12:04 Oleafeon

@Oleafeon happy to help you debug it but I would need a test repository which recreates the issue so I can look into it. Alternatively if you debug it yourself and send any code changes required then I can include theme here.

ryanmitchell avatar Apr 01 '22 12:04 ryanmitchell