*

kenoffice

  • **
  • 26 posts
[Bug] Email Reminder plugin - not send alerts for future actions
« on: September 29, 2023, 10:26:08 AM »
I encountered the issue with only 3 situations: Item Expire Soon, Promotion Expire Soon & Membership Expire Soon
No emails were sent to users that their listing, membership and their promotion is about to expire, I have set in module settings to alert 1 day before.

Other alerts of EMR are ok, I mean sent.

I have modified the date of expiration in database in order to be 1 day from now on - on first screenshot there is 2023-09-29 22:36:43 (current date is 2023-09-28 22:54:37); I altered cron.php to throw some echo's in order to help me understand. I managed to run cron from browser, at my discretion. On second screenshot there is capture from browser running cron. Also I altered the functions.php from plugin in order to get some echo from there too. The result of cron is on attached capture, means the array of promotions (for now only there I have put echo) is empty. Being no promotions which will expire soon of course that NO EMAIL will be sent to users :(
But I observed that the date of $from & $to are one day BEFORE, meaning 2023-09-27 !
This means [in my opinion] that TODAY (2023-09-28) the cron will look on the past (2029-09-27) to check if there are any promotions which WILL expire and send to user the email reminder... But this means that the email will be sent AFTER the promotion already expired :)
So, the documentation "Promotion Expire Soon" (the one which states: "Send reminder to user when membership in group using Osclass Pay Plugin features is about to expire. Email is sent entered number of days before expiration date") is not ok. Or maybe the script need adjustements...

On other functions, where the script must look back/in the past (like USERS WITH LAST ACCESS, INSTANT MESSENGER - UNDREAD MESSAGES, USERS PENDING VALIDATION, etc) the "minus" sign in front of days (strtotime('-' . $days . ' days'..) it is ok. But for certain functions, when script must look in the future (OSCLASS PAY - PROMOTION ABOUT EXPIRATION, OSCLASS PAY - MEMBERSHIP ABOUT EXPIRATION, SEND NOTIFICATIONS FOR ITEM ABOUT EXPIRATION) must be + not -.

Temporary I leaved the functions.php altered and it works (email reminders are sent informing users about FUTURE actions) but this assume at every update to take care about this and restore my modifications; maybe the back-end/PHP team will inspect and fix. On screen capture 3 can be seen that if I change - with + and set date of expiration after 1 day the event is triggered. - EDIT: forum don't allow 3 picture uploads so the screen capture 3 cannot be shown here, anyway the point is that now it works...

I hope it helps my long story :)
There is no perfect classifieds script. I dream to make it.

*

MB Themes

Re: [Bug] Email Reminder plugin - not send alerts for future actions
« Reply #1 on: September 29, 2023, 11:10:53 AM »
Plugin first identify last check:
Code: [Select]
  $last_check = (erm_param('last_check') == '' ? date('Y-m-d H:i:s') : erm_param('last_check'));

Then go let's say for promotion expiration:
Code: [Select]
erm_remind_osp_promotion_about_expiration($last_check);
Check how many days before to warn and create from-to:
Code: [Select]
  $days = (erm_param('osp_promotion_about_expiration_days') >= 0 ? erm_param('osp_promotion_about_expiration_days') : 3);
 
  $from = date('Y-m-d H:i:s', strtotime('-' . $days . ' days', strtotime($last_check)));
  $to = date('Y-m-d H:i:s', strtotime('-' . $days . ' days'));
 
  $promotions = ModelERM::newInstance()->getOspPromotionAboutExpiration($from, $to);

Then execute query, go to database and get results:
Code: [Select]
  $this->dao->where(sprintf('dt_expire between "%s" AND "%s"', $from, $to));
  $this->dao->where('i_paid', 1);

if you have promotion that expire in 3 days, and you have configured to notify 3 days before expiration, then this notification will go out today.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

kenoffice

  • **
  • 26 posts
Re: [Bug] Email Reminder plugin - not send alerts for future actions
« Reply #2 on: September 30, 2023, 11:32:31 AM »
Ok M., thank you for reply, but still not clear your explanations; please note that last_check is updated in preferences table at each hourly cron so the timeframe between $from & $to will be x day + 1 hour maximum.
Let assume that the email reminders, all of them which ends with "...soon" are set-up at 3 days.
This means that $from will be $today (2023-09-30) - 3 days = 2023-09-27
Also the $to will be 2023-09-27 but plus few minutes, between 0 and 60 if you manually run cron, or exactly 60 if leave the cron to run by server.
Then the:
$promotions = ModelERM::newInstance()->getOspPromotionAboutExpiration($from, $to);
will look in database table oc_t_osp_item al promotions which have expiration date in interval [from - to], I mean "in the past"

Anyway, I suggest to stop here and do some tests myself.

I have installed a fresh copy OSC 8.1.2 and 2 plugins (OSC Pay & Email reminder) on an empty domain.
Setting up crons in Cpanel
Disabled the option "Warn about expiration" in main OSC settings: Listings -> Settings, in order not to mix up with plugin option
Set in "For sale" category the duration to be 3 days in order to reduce the time for tracking/analyzing
Made few adjustements in osc_pay plugin in order to test also "membership expire soon" and "promotion expire soon"
Set in Email Reminder plugin only 3 alerts: "item expire soon", "membership expire soon" and "promotion expire soon" with value "1" so with 1 day before expiration should send alert that WILL expire.
On 2023-09-30 I have done:
- Registered the user
- bought Silver membership (valid only for 2 days; will expire 2023-10-02 11:26:03)
- added one listing (valid only for 3 days but after that I modified in database to expire after 2 days and 4 hours in order NOT to be catched by same cron together with membership reminder, so will expire on 2023-10-02 15:34:50)
- promote as "Premium" that listing. (valid only for 2 days, will expire 2023-10-02 13:39:08)
- took screen capture from 3 tables in database to show their date of expiration (item, membership, premium) if someone will ask me :)

What to expect:
Considering today is 2023-09-30 and all 3 reminders to observe will need to be fired with 1 day before as is set on plugin EMR settings, also all 3 of them have expiration date 2023-10-02, then tomorow 2023-10-01 the test user will receive 3 email alerts, each one informing that something is about to expire, at different hours as I made small adjustements of hour in order not to receive all emails once.

Let see...
There is no perfect classifieds script. I dream to make it.

*

kenoffice

  • **
  • 26 posts
Re: [Bug] Email Reminder plugin - not send alerts for future actions
« Reply #3 on: October 01, 2023, 05:42:51 PM »
I feel like I need to come with updates.
So, I have 2 websites:
1. the main one which I work on it (is unfinished yet); is the one where I saw malfunction of email reminder plugin and I modified the functions.php of the plugin, by replacing - with + only in 3 functions, in order to correct the bug (for now I am the only one which believe is a bug)
2. the second one just installed 2 days ago as fresh copy of OSC on an empty domain, only for diagnose the problem; here I leave untouched the functions.php of the pugin, to see the real behavior.

On both websites I have set 1 day before on plugin email reminder for 3 reminders (item expire soon, membership expire soon, promotion expire soon).
On both websites I have set expiration date of those 3 situations (mentioned above) for today, 01.10.2023

Until now, 01.10.2023 18:00 I already received email alerts regarding ...expire soon (listing, membership, promotion) from main website, where I previously modified the functions.php file.
But from second website (test website) I didn't receive any email alert. There the functions.php is the original one. We must wait another 2 days in my opinion to draw the final conclusion (I think in functions.php having "+ x days" the alert will be sent after 1 day after expiration; conisdering that I have manually setup the expiration on 02.10.2023 different hours like 11:26, 15:24, 13:39, I expect that on 03.10.2023 to receive the alerts that item, promotion, membership will expire soon.

I will come with updates on 03.10
There is no perfect classifieds script. I dream to make it.

*

kenoffice

  • **
  • 26 posts
Re: [Bug] Email Reminder plugin - not send alerts for future actions
« Reply #4 on: October 03, 2023, 09:50:47 PM »
Update (final one):
On testing website (fresh copy of OSC 8.1.2, latest version of Email reminder plugin & Osclass Pay plugin) I DID NOT RECEIVED on test user email neither one email alert regarding events which will occur soon. More specific: item will expire soon, promotion will expire soon, membership will expire soon.
Indeed, I have received some email alerts AFTER some events, like promotion & membership EXPIRED. But no email warning the user that item/promotion/membership will expire. So, plugin works for certain functions, except some of them: the ones which must alert before event.
My point is that I have set in Email Reminder plugin 3 alerts (just mentioned above) with 1 day before, so theoretically, the test user should receive them (item/promotion/membership expire in 1 day). Such email alerts were not sent.

On real website (which is under construction, still) I have modified the 3 functions (erm_remind_item_about_expiration, erm_remind_osp_promotion_about_expiration, erm_remind_osp_membership_about_expiration) by replacing "...strtotime('-' . $days..." WITH "...strtotime('+' . $days..." -> I mean to look in the future, not in the past. On that website the alerts WERE SENT ! Exactly as they should, with 1 day before expiration occur.

M., if you want, I can give access to Cpanel account and admin / user account of the TEST website, in order to check and make additonal tests. For a while I will keep that testing website only for you, soon I will clear/erase everything. On the other hand I am sure that you can do same tests without me being involved.
The final thing which I/we can do on test site is: to modify the functions.php of Email reminder plugin and replace - with + on those 3 functions mentioned above. And then the email alerts that "something" will expire soon will be sent before event. I can bet on this. Agree ?

Conclusion: bug in plugin. Temporary solution: modified 3 function (replace - with +). Definitive solution: dev PHP team patch those 3 functions in order at next update/release to include them (otherwise I need to modify myself after each update)

cheers !
« Last Edit: October 03, 2023, 09:55:05 PM by kenoffice »
There is no perfect classifieds script. I dream to make it.

*

MB Themes

Re: [Bug] Email Reminder plugin - not send alerts for future actions
« Reply #5 on: October 04, 2023, 03:34:22 PM »
@kenoffice
That is correct, for expiration type of notification (notify XY days before) interval must be moved into future instead of moving it back to pas.
Means change '-' to '+'.
Plugin was updated.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots