? ? ?
avatar marcorensch
marcorensch
12 Jan 2021

Steps to reproduce the issue

Create some sample articles
Create a new instance of mod_articles_category
Set filter for date to relative

Expected result

Get all articles x days in the past till now

Actual result

$items returns false and this leads into the follwing error in the frontend:

Warning: Invalid argument supplied for foreach() in /Users/marcorensch/Sites/joomla4b5/components/com_content/src/Model/ArticlesModel.php on line 713

Warning: Invalid argument supplied for foreach() in /Users/marcorensch/Sites/joomla4b5/modules/mod_articles_category/src/Helper/ArticlesCategoryHelper.php on line 257

System information (as much as possible)

Joomla 4 Beta 6
MAMP local
PHP 7.4.12
MySQL 5.7.32

Additional comments

I've found this issue while checking the code for a module (because mine worked either) and even if all looks good (and similar to J3 its not working in J4 when doing this in the model:

case 'relative':
				$relativeDate = (int) $this->getState('filter.relative_date', 0);
				$query->where(
					$db->quoteName($dateField) . ' IS NOT NULL AND '
					. $db->quoteName($dateField) . ' >= ' . $query->dateAdd($nowDate, -1 * $relativeDate, 'DAY')
				);
				break;

ArticlesModel.php line 571 and below.
the $nowDate has to be 'quoted' in J4:
It should look like:

case 'relative':
				$relativeDate = (int) $this->getState('filter.relative_date', 0);
				$query->where(
					$db->quoteName($dateField) . ' IS NOT NULL AND '
					. $db->quoteName($dateField) . ' >= ' . $query->dateAdd($db->quote($nowDate), -1 * $relativeDate, 'DAY')
				);
				break;

When i change it its working on my installation.
Did someone else expecting the same error?

avatar marcorensch marcorensch - open - 12 Jan 2021
avatar joomla-cms-bot joomla-cms-bot - change - 12 Jan 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 12 Jan 2021
avatar marcorensch marcorensch - change - 12 Jan 2021
The description was changed
avatar marcorensch marcorensch - edited - 12 Jan 2021
avatar marcorensch marcorensch - change - 12 Jan 2021
The description was changed
avatar marcorensch marcorensch - edited - 12 Jan 2021
avatar marcorensch marcorensch - change - 12 Jan 2021
Title
[4] Articles get by Relative Date Error (mod_articles_category)
[4.0] Articles get by Relative Date Error (mod_articles_category)
avatar marcorensch marcorensch - edited - 12 Jan 2021
avatar chmst chmst - change - 12 Jan 2021
Labels Added: ? ?
avatar chmst chmst - labeled - 12 Jan 2021
avatar chmst chmst - labeled - 12 Jan 2021
avatar chmst
chmst - comment - 12 Jan 2021

confirmed

avatar bembelimen
bembelimen - comment - 13 Jan 2021

@marcorensch could you create a PR please?

avatar marcorensch
marcorensch - comment - 13 Jan 2021

@bembelimen : Sorry i have no clue what to do to create a PR - is there any guide somewhere?

avatar marcorensch
marcorensch - comment - 16 Jan 2021

@gostn @bembelimen : Sorry i don't get it - this Tutorial is just to old - I've tried now several times via PHP Storm to setup the environment... I am able to handle my extension updates on github but find no way how to create workspace for Joomla and contribute.

Edit:
I'm not sure but i think i've done something wrong it. took all other commits into my pr too....

avatar gostn
gostn - comment - 17 Jan 2021

in #32063 you try to make a change for J4 in stage-branche (which is j3).

avatar alikon alikon - change - 17 Jan 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-01-17 08:37:02
Closed_By alikon
Labels Added: ? ?
Removed: ? ?
avatar alikon alikon - close - 17 Jan 2021
avatar alikon
alikon - comment - 17 Jan 2021

closing as we have a pr to test #32064

Add a Comment

Login with GitHub to post a comment