Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Collection with 'publish dates' disabled gets queried for date anyway #10103

Closed
jorismak opened this issue May 17, 2024 · 2 comments
Closed

Comments

@jorismak
Copy link

Bug description

We have collections that were working fine in Statamic 4 through the REST API (and the Eloquent driver for entries).
After upgrading to Statamic 5, almost everything seems to work, except that the Rest API is returning empty pagination results.

If you request a certain entry id it works fine, but if you use the /entries endpoint it returns nothing.

Diving into the statamic code, I see the date query part in vendor/statamic/cms/src/Stache/Query/QueriesEntryStatus.php in the method addCollectionStatusLogicToQuery.

It looks at different date-behaviour settings because the default 'published = true' filter is added.

But on that collection, all the date settings are disabled:

image

How to reproduce

I don't know if the eloquent driver is important here, but I think it is.
So, use the eloquent driver to store entries in a database.

Create a collection with date: false (or the date property absent). In other words, the option in the CP 'Enable publish dates' is disabled. Create some entries in it. The date column in the database is now NULL for these entries. But mark them as published! The published column in the database should be a 1.

Use the /api/collections/<collectionname>/entries endpoint from the REST API, and you get a response with empty data property. No entries are returned.

What seems to happen is this is in our collection YAML:

date_behavior:
  past: public
  future: private

but without any date property.

What happened is at some time we had the date behaviour toggle enabled, and made some settings.
After that, we disabled the hole date behaviour section by just disabling the toggle in the CP.

But the REST API query code ignores the date property in the YAML, and just looks at date_behavior.

I find it hard to explain here :).
Basically, there is a big toggle to enable or disable the whole 'date behaviour' section in the CP while editing a collection. This toggles the date property true / false. And then the 'date behaviour' section appears, and you can make settings. These settings are stored in the date_behavior property. What happens if you turn the whole 'date behaviour' section off again, is that only the date property is toggled off.

Previous, in Statamic 4, that was enough. But the query code in Statamic 5 ignores the date property, and looks at the left overs in the date_behavior property anyway.

Logs

No response

Environment

Environment
Application Name: --------------
Laravel Version: 11.7.0
PHP Version: 8.3.6
Composer Version: 2.7.2
Environment: local
Debug Mode: ENABLED
URL: -----------------
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single, slack_criticals
Mail: smtp
Queue: redis
Session: file

Statamic
Addons: 3
Sites: 2 (Nederlands, Engels)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.2.0 PRO

Statamic Addons
ptchr/statamic-basics: 1.2.0
rias/statamic-redirect: 3.7.1
statamic/eloquent-driver: 4.0.0

Statamic Eloquent Driver
Asset Containers: file
Assets: eloquent
Blueprints: file
Collection Trees: eloquent
Collections: file
Entries: eloquent
Forms: eloquent
Global Sets: file
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: file
Revisions: eloquent
Taxonomies: file
Terms: eloquent

Installation

Other (please explain)

Additional details

No clue how this project is installed, it was at Laravel 10 / Statamic 4 when I joined on it.

@ryanmitchell
Copy link
Contributor

This should already be fixed by #10099, its hasn't made it into a release yet

@jorismak
Copy link
Author

14 hours ago! 😂 .
I was fighting with this yesterday, couldn't find another issue. So first thing this morning I created an issue for it.. Someone beat me to it :).

Cool, fixed is fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants