CMS MADE SIMPLE FORGE

News Module

 

[#12289] SQL bug - no news being displayed (or entries missing) after migration/upgrades from sufficiently old version

avatar
Created By: Kadigan KS/b/ (KadiganKSB)
Date Submitted: Wed Apr 08 12:03:28 -0400 2020

Assigned To:
Version: 2.51.10
CMSMS Version: 2.2.14
Severity: None
Resolution: None
State: Open
Summary:
SQL bug - no news being displayed (or entries missing) after migration/upgrades from sufficiently old version
Detailed Description:
So, I've been recently migrating a number of old CMS MS installations (as far
back as v1.5, if you'll believe it), and one thing consistently crops up - in
the News module, there's a number of entries which, after all the required
upgrades, end up having *_modules_news.start_time defined, and
*_modules_news.end_time = NULL.

This, obviously, causes the News page to not display any news. Why? Because of
this bit of SQL:

$query1 .= 'IF(start_time IS NULL AND end_time IS NULL,news_date <=
NOW(),NOw() BETWEEN start_time AND end_time)';

(/modules/News/action.default.php, line 105)


The issue is with how the logic is constructed - it will only look for news_date
<= NOW() - if and only if - both start_time and end_time are NULL -- otherwise,
it'll try to fit "now" between them. If only one of them is NULL, this obviously
fails.


The fix is to make a logical inversion here, so that we're making BETWEEN a
special case and not the norm - like so:

$query1 .= 'IF(start_time IS NOT NULL AND end_time IS NOT NULL, NOW() BETWEEN
start_time AND end_time, news_date <= NOW())';

Notice how I now check for both NOT being null, and only then try to fit them
"between" start and end; otherwise I only check if the date isn't in the future.


I suspect this is a hold-over from some old version where start_time was used in
place of news_date? Regardless, if you're upgrading form an older CMS MS
installation, this will rear its ugly head - and you can't just mass-NULL the
field in the DB, either.


History

Comments
avatar
Date: 2020-04-24 09:52
Posted By: Kadigan KS/b/ (KadiganKSB)

This bug still seems to be present in v2.51.9 (as bundled with CMS MS v2.2.14).
Thankfully I noticed that most of my news entries suddenly went missing - had to
go back into action.default.php and re-apply my proposed patch.
      
avatar
Date: 2020-04-24 09:54
Posted By: Kadigan KS/b/ (KadiganKSB)

Note: some news were displaying for me now (instead of all being missing),
because I edited a number of entries - the module seems to have corrected the
corresponding database entries. The ones showing up were specifically the ones I
have edited since discovering this issue.
      
avatar
Date: 2020-04-24 09:55
Posted By: Kadigan KS/b/ (KadiganKSB)

Bumping CMSMS Version to v2.2.14 (bug still present). Can't bump plugin version,
since 2.51.9 doesn't show up on the list.
      
avatar
Date: 2020-06-14 16:46
Posted By: Kadigan KS/b/ (KadiganKSB)

Bumping to plugin version 2.51.10 -- bug still present.
      
Updates

Updated: 2020-06-14 16:46
version_id: 31659 => 31721

Updated: 2020-04-24 09:56
summary: SQL bug - no News being displayed (v2.51.7), News missing (v2.51.9) after migration/upgrades => SQL bug - no news being displayed (or entries missing) after migration/upgrades from sufficiently old version

Updated: 2020-04-24 09:55
cmsms_version_id: 31698 => 31720

Updated: 2020-04-24 09:53
summary: SQL bug - no News being displayed (v2.51.7) after migration/upgrades => SQL bug - no News being displayed (v2.51.7), News missing (v2.51.9) after migration/upgrades

Updated: 2020-04-08 12:04
description: So, I've been recently migrating a number of old CMS MS installations (as far back as v1.5, if you'll believe it), and one thing consistently crops up - in the News module, there's a number of entries that after all the required upgrades end up having *_m => So, I've been recently migrating a number of old CMS MS installations (as far back as v1.5, if you'll believe it), and one thing consistently crops up - in the News module, there's a number of entries which, after all the required upgrades, end up having
resolution_id: => 5