Closed wolispace closed 1 month ago
Have you tested this after using the increment
function?
{% do craft.entryCount.increment(entry.id) %}
{% set count = craft.entryCount.count(entry.id) %}
Entry count: {{ count }}
No I havnt yet, I must admit I havnt read any doco yet or seen how it was implemented.
But my question is: Should I be seeing the existing logged entry counts on the /entry-count?site=default page?
I can see records in the DB, with current dates. Should I see values in entries
after {% set entries = craft.entryCount.entries.all() %}
?
or has something in a craft4 upgrade stopped this from happening and Im the first to notice?
Im not seeing an related errors on the logs.
Ill go diving onto your code to try and debug it with xdebug, but just checking its still working for you and its probably something unique to our setup.
You should, provided those entries exist as live entry in the primary site. Before you start code-diving, try incrementing the count of an existing entry first.
Yes.. when I add
{% set count = craft.entryCount.count(entry.id) %}
Entry count: {{ count }}
To my template I see the count increase each time the page is refreshed.
And running this sql:
select id,entryId,count,dateUpdated from entrycount order by dateUpdated desc limit 10;
I see the same count, and I see it increment in the most recently updated row.
So the incrementing is working, and we definitely have records in the DB.. but I get an empty array when trying to view the page /entry-count?site=default
(with or without the site)
Looking in EntryCountService.php I see:
// Return entry query
return Entry::find()
->id($entryIds)
// ->site('*')
->fixedOrder();
On a whim, I enabled the remarked-out line so it gets site('*') and bingo! we see results on the page.
So the reason we don't see any data on the page is because the counts are recorded for a specific site site=goodliving
.
Intriguingly, the twig that relies on the Entry count data, is working just fine:
{% set popularArticles =
craft.entryCount.entries.section('goodlivingArticles').postDate('and', '>= ' ~ weeksAgo).limit(
6
).with(
['contentBuilder', 'teaserImage', 'goodlivingHeroImage']
).all()
%}
I cannot imagine how this use of craft.entryCount.entries...
finds what we expect when other craft.entryCount.entries...
return nothing.
Maybe you can re-instate the ->site('*')
?
Ideally add a Sites filter to the top, so we can choose the counts for different sites... but thats probably asking a bit too much :-)
Ah yes, that explains it. The plugin is intended for educational purposes and only works with single site use-cases.
Bug Report
I know this isn't a super-important plugin, but it does still exist so Im wondering why I see no entries on the page that lists all counts?
/entry-count?site=default
Removing or changing the
?site=
makes no difference.I see in the template: /vendor/putourlightson/craft-entry-count/src/templates/index.twig
And when I {% dd entries %} I just get an empty array
[]
When I run this sql I see I have a lot of entries counted:
Looking in the debug console I see this query is being run:
This returns data as above, when I run it manually.
We uses this plugin to find out which entries are popular.
Plugin Version
3.0.1
Craft CMS Version
4.11.5
PHP Version
8.0.30