[6.2] Fix category item count including expired articles #46614#46653
[6.2] Fix category item count including expired articles #46614#46653RudraHingu001 wants to merge 12 commits into
Conversation
|
I have tested this item ✅ successfully on 57f76ab I have a published article and an expired article, and now it's showing the published one.
Now that I disable the only article, it disappears, which is what we need.
Thanks for this PR. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46653. |
|
Same problem as with the original PR |
|
This is a valid concern thanks for raising it. In the context of this PR, That said, you are correct that the Categories API is generic and may be used by
I see this PR as restoring consistency for If preferred, I can follow up with an enhancement PR to make this behavior |
But I'm glad it's been found and it seems to be resolved now. |
|
I have tested this item ✅ successfully on 57f76ab But: I can NOT say anything about the possible mentioned implications in #40172 (comment) This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46653. |
|
I have tested this item 🔴 unsuccessfully on 57f76ab This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46653. |
|
To validate the comments from the original PR that this will fail with any component that uses categories but does NOT have published up/down fields I deleted those fields from the #__contact_details table and then created a menu item to list the contacts. As expected this produces an error
|
|
I understand that this now works for the table of contents. I understand that it doesn't work with another component that doesn't have those fields in the table. But why didn't we test it successfully? Otherwise, we now know it works, but not on all components. |
|
The problem is NOT that this change doesnt work with all components using categories |
|
That way. I understand. Can that function then check whether the field is present or not? |
- Check if publish_up/publish_down columns exist before filtering - Prevents SQL errors in components like com_contact, com_tags - Maintains fix for com_content article count issue - Addresses feedback from @brianteeman in joomla#46653
|
@brianteeman Thank you for catching that critical issue! I've updated the PR to safely handle components without publish date fields. What Changed:Added a field existence check before applying publish date filtering: $tableColumns = $db->getTableColumns($this->_table);
if (isset($tableColumns['publish_up']) && isset($tableColumns['publish_down'])) {
// Only apply date filtering if fields exist
}How It Works Now:
Testing Done:
This addresses your concern from #40172 while maintaining the fix for #46614. |
|
contacts DOES have the publish_up/down fields - I just removed them for testing purposes |
|
Looking at the check, it will work fine for the contacts. Because they do contain the fields, and the filter can still be activated. Has this check already been incorporated into the PR for testing purposes? It's great that it's now being thoroughly investigated and that they're working on a solution. |
|
@brianteeman If you prefer, I could make this even more explicit by: Option 1: Add a configurable option in if ($this->_options['published'] == 1) {
$subQuery->where($db->quoteName($db->escape('i.' . $this->_statefield)) . ' = 1');
// Only apply if explicitly enabled via options
if (!empty($this->_options['respectPublishDates'])) {
$tableColumns = $db->getTableColumns($this->_table);
if (isset($tableColumns['publish_up']) && isset($tableColumns['publish_down'])) {
// ... date filtering
}
}
}Option 2: Only apply for com_content specifically: if ($this->_extension === 'com_content' && $this->_options['published'] == 1) {
$tableColumns = $db->getTableColumns($this->_table);
// ... date filtering
}Which approach would you prefer? The current field-check approach seems safest to me, but I'm open to your guidance. |
|
As the bug appears everywhere I would go for option 1 |
|
@brianteeman Implemented Option 1 as suggested! The publish date filtering is now opt-in via a configurable option. Changes Made:1. Added
2. Enabled the option in com_content models:
Both models now set How It Works:For com_content (Articles):
For other components (Contacts, Tags, etc.):
Safety layer:
Testing:
This approach gives each component control while fixing the bug for com_content. Ready for testing! |
|
I've re-enabled the PR on my test site, but where can I find the options to configure this? I look at the article or category options and don't see anything. |
|
@webmasterab Thanks for testing! There's no UI option to configure - it's enabled automatically in the code for com_content. The To verify it's working:Test Setup:
Expected Result:
Does the article count now correctly exclude expired articles in your test? |
|
I have tested this item ✅ successfully on 0823ad3 And the backend remains as it is now, but the frontend is now correct, and an expired article is no longer counted. I'm glad this has been resolved and I can use this for my Yootheme template to display or hide items based on whether a category has no published articles. I want to sincerely thank you for creating this solution. And everyone who helped and contributed to this. This is how Joomla improves. I've also mentioned it here: https://yootheme.com/support/question/172237#answer-562033. Happy with it. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46653. |
|
I don't see a reason for the option and the implementation based on the idea that every tables uses the naming published_up and published_down which might not be the case so the name needs to be get by the table object. |
|
@HLeithner That's annoying. It's actually a nice addition and a solution to a problem currently in Joomla. So why wouldn't you want it? |
@webmasterab I think @HLeithner was clear in his comment. It is an overhead to use a configuration option to control if the published up and down dates should be used ot not. Furthermore, the category system is not only used for articles by the core but also for other kinds of content, including such of 3rd party extensions. Those might not provide the published up and down at all in their table, or they provide them but with different column names. So a clean implementation should check if these columns exist and if there are column alias. The table object can be used to do that. |
|
@richard67 en @HLeithner My apologies. |
|
@HLeithner Thank you for the feedback! I understand your concerns about the implementation. Questions to clarify the best approach:
$table = Table::getInstance('Content', 'Joomla\\CMS\\Table\\');
$publishUpColumn = $table->getColumnAlias('publish_up');
$publishDownColumn = $table->getColumnAlias('publish_down');
Proposed alternative approach:
Would this be more in line with what you're suggesting? I want to make sure I implement this correctly rather than adding technical debt. @richard67 @brianteeman - Your guidance would also be appreciated on the best implementation approach here. |
|
I have tested this item 🔴 unsuccessfully on dd35a3e Observation:
Published, but has expired.
|
|
@komalm The number in the backend correctly reflects the unpublished article. The number also applies to the frontend. I don't know if you've tested that. In the backend, it's correct that the article is included in the green number. But it's no longer included in the frontend, which is the intention. |
869df52 to
45ba051
Compare
|
I’ve updated the implementation in Changes made:
PHPCS issues have also been resolved and CI should now pass. Please let me know if this aligns with the expected direction or if further adjustments are needed. |
| $options['access'] = $params->get('check_access_rights', 1); | ||
| } else { | ||
| $options['countItems'] = 0; | ||
| $options['countItems'] = 0; |
There was a problem hiding this comment.
| $options['countItems'] = 0; | |
| $options['countItems'] = 0; |
@RudraHingu001 Definitely not, see my latest suggestion and the current state of the CI checks. The problem is that I have to approve the GitHub actions of the CI checks before they run, so you can't see them after you have committed a change until I have approved them to start. The reason might be that you are a new contributor in this repository, or it is because some permission settings in your fork. Maybe you should adjust your editor (or IDE) so it shows you white space (tabulators and spaces) when editing, that would avoid many code style issues. |
|
I'm not happy with this, we can't knowingly not support a core feature (column aliases) in the core... |
|
Updated the implementation to address the review comments.
Please let me know if anything further needs adjustment or if the remaining thread can be resolved. |
|
Hi @HLeithner, @richard67 — Could you please take another look when you have time and let me know if this aligns with the expected approach, or if further adjustments are needed? Thanks again for the guidance! |
|
I've implemented the MVC factory approach as discussed: Changes:
Could you please review when you have time? Happy to make any additional adjustments needed. The 6.1-beta1 deadline is approaching - let me know if there's anything else I should address! |
|
This pull request has been automatically rebased to 6.2-dev. |
|
Thank you for your contribution - closing as no changes have been done. |






Summary
Fixes incorrect article counts in frontend category views when articles are expired.
Problem
The category item count did not respect
publish_upandpublish_downdates.Articles that were expired (Finish Publishing date in the past) were still
counted as published, causing categories to show incorrect item counts and
appear non-empty even when no articles were visible in the frontend.
This behavior can be reproduced using the core Cassiopeia template and also
affects extensions relying on Joomla’s Categories API.
Solution
Apply the same publish window filtering (
publish_up/publish_down) used bycom_contentarticle queries to the category item count subquery inJoomla\CMS\Categories\Categories.Result
Fixes #46614