solved JrCore_list in email template

Melih
Melih
@melih
8 years ago
198 posts
Dear all,

I am trying to apply a jrCore_list function in a email template. This is triggered by daily_maintenence. Whenever a user logs in before the daily_maintenence is done, it gets triggered and my function works normally. I mean jrCore_list function runs and sends the emails. But if daily_maintenence by itself automaticly without any user loging in or something else to trigger it, jrCore_list function doesn't work. Emails are send with constant text but without jrCore_list output data. Lines comes out empty. This function wokred for a while. I don't know when or why it stoped working properly.
updated by @melih: 10/31/16 09:47:05PM
brian
@brian
8 years ago
10,148 posts
How is your function being triggered?


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
8 years ago
198 posts
With daily_maintenance_listener
brian
@brian
8 years ago
10,148 posts
Melih:
With daily_maintenance_listener
That doesn't make sense - you say:
Quote:
Whenever a user logs in before the daily_maintenence is done, it gets triggered and my function works normally
If it is triggered by daily maintenance how does a user trigger it BEFORE daily maintenance when they log in?

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
8 years ago
198 posts
I meant daily maintenance is triggered when a user loged in if it hasn't done the daily maintenence that day.
Melih
Melih
@melih
8 years ago
198 posts
Whenever a user logs in before the daily_maintenence is done, daily_maintenence gets triggered and my function works normally.
brian
@brian
8 years ago
10,148 posts
Melih:
I meant daily maintenance is triggered when a user loged in if it hasn't done the daily maintenence that day.

OK so it works if the daily maintenance is started by a user that is logged in? Try adding:
privacy_check=false
to the {jrCore_list} call and see if that fixes it.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
8 years ago
198 posts
Thank you Brian, I will try that. I will see the result on the next automatic daily maintenence.
Melih
Melih
@melih
8 years ago
198 posts
Unfortunately it's not working. I need to check the whole thing again :(
michael
@michael
8 years ago
7,714 posts
paste the function your trying to use in here.

What I normally would do in this situation would be to create a junk.tpl page for my active skin and check that the jrCore_list function works there first. If it does, then put it into the email template and wait for it to fire.

If it didn't work I would put a {debug} into the email template to see what variables I was trying to use and expected to be there werent there.

The debug would come out as html code, but if you take that code and put it into an html file and open it in a browser you can see it as normal.

Another idea would be to put the jrCore_list call into an email template you can fire at will so you dont have to wait a day to see if it works.
Melih
Melih
@melih
8 years ago
198 posts
I deleted everything and i will start over, so i can't paste it right now :)

It is working on the site and it is working if i triggered the daily maintenance. So the code is woking actually.

I will try debug, thanks for the idea.

It already works when i become online and trigger daily maintenance or when i fire it somehow manually. But it doesn't work when it's fired by the automatic daily maintenance.
paul
@paul
8 years ago
4,326 posts
Is your jrCore_list call using a variable that may not be available when initiated by the daily maintenence event, $_user for instance?


--
Paul Asher - JR Developer and System Import Specialist
Melih
Melih
@melih
8 years ago
198 posts
First of all, i want to remind you that i don't know much information about coding. Most of the things i try to do are put stuff together :)

This is my function in include.php file in my custom module

function myFonksiyon_daily_maintenance_listener($_data, $_user, $_conf, $_args, $event)
{ $bir = date("md", strtotime("+1 days")); $iki = date("md", strtotime("+2 days")); $uc = date("md", strtotime("+3 days")); $dort = date("md", strtotime("+4 days")); $bes = date("md", strtotime("+5 days")); $alti = date("md", strtotime("+6 days")); $yedi = date("md", strtotime("+7 days")); $_sp = array( 'search' => array( "event_date like %$bir || event_date like %$iki || event_date like %$uc || event_date like %$dort || event_date like %$bes || event_date like %$alti || event_date like %$yedi", "event_type = birth || event_type = death || event_type = marriage" ), 'return_keys' => array('event_date', 'event_type'), 'skip_triggers' => true, 'privacy_check' => false, 'ignore_pending' => true, 'no_cache' => true, 'limit' => 5 ); $_rt = jrCore_db_search_items('jrGenEvent', $_sp); if ($_rt && is_array($_rt) && isset($_rt['_items'])) { $_us = array( 'search' => array( "user_email like %", ), 'return_keys' => array('_user_id', 'user_name'), 'limit' => 1000 ); $_mg = jrCore_db_search_items('jrUser', $_us); if ($_mg && is_array($_mg['_items'])) { foreach (($_mg['_items']) as $item) { $userid = $item['_user_id']; $_rp['username'] = $item['user_name']; $_rp['bir'] = $bir; $_rp['iki'] = $iki; $_rp['uc'] = $uc; $_rp['dort'] = $dort; $_rp['bes'] = $bes; $_rp['alti'] = $alti; $_rp['yedi'] = $yedi; list($sub, $msg) = jrCore_parse_email_templates('myFonksiyon', 'yildonumleri', $_rp); jrUser_notify($userid, 0, 'myFonksiyon', 'yildonumleri', $sub, $msg); } } } }

And it uses this email template

Merhaba {$username},

Önümüzdeki hafta gerçekleşecek yıldönümüleri var:

{capture name="s_tpl" assign="s_tpl"}
{literal}
	{if isset($_items)}
		{foreach $_items as $item}
			{if $item.event_type == 'marriage'}
				{if $item.profile_gender == 'female'}
					{$item.event_date|jrGenCore_get_day} {$item.event_date|jrGenCore_get_readable_month} {$item.event_date|jrGenCore_get_year} {$item.profile_first_name} ve {$item.event_linked_person|iyelikin} evlilik yıldönümü
				{/if}
			{else}
				{$item.event_date|jrGenCore_get_day} {$item.event_date|jrGenCore_get_readable_month} {$item.event_date|jrGenCore_get_year} {$item.profile_name|iyelikin} {if $item.event_type == 'birth'}doğumgünü{elseif $item.event_type == 'death'}ölüm yıldönümü{/if}
			{/if}
		{/foreach}
	{/if}
{/literal}
{/capture}

{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$bir" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$iki" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$uc" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$dort" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$bes" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$alti" template=$s_tpl privacy_check=false}
{jrCore_list module="jrGenEvent" search1="event_type = birth || event_type = death || event_type = marriage" search2="event_date like %$yedi" template=$s_tpl privacy_check=false}

I know that this worked for a while. There were also some other parts of it but i deleted them during trials. For example there was a line for it just to work once a week.

I tried many things but in the end i gave up and decided to ask you.
updated by @melih: 07/16/16 10:41:11AM
Melih
Melih
@melih
8 years ago
198 posts
This is the mail that is sent when i trigger daily maintenance

Merhaba Melih,

Önümüzdeki hafta gerçekleşecek yıldönümüleri var:


15 Temmuz 1978 Hakan Baran'ın doğumgünü
18 Temmuz 1965 Ayşe Asilbay'ın doğumgünü
19 Temmuz 1979 Çağlar Kalaycıoğlu'nun doğumgünü


---------------------------------------

Bildirim tercihlerinizi Hesap Ayarları / Bildirimler alanından değiştirebilirsiniz.

http://www.egricayir.org/user/notifications


Hemen tüm bildirimleri kapatmak için aşağıdaki linki tıklatın:

http://www.egricayir.org/user/unsubscribe/88bb...

And this is the mail that is sent when the daily maintenance is done automatically

Merhaba Melih,

Önümüzdeki hafta gerçekleşecek yıldönümüleri var:


---------------------------------------

Bildirim tercihlerinizi Hesap Ayarları / Bildirimler alanından değiştirebilirsiniz.

http://www.egricayir.org/user/notifications


Hemen tüm bildirimleri kapatmak için aşağıdaki linki tıklatın:

http://www.egricayir.org/user/unsubscribe/88bb...

updated by @melih: 07/16/16 10:39:01AM
michael
@michael
8 years ago
7,714 posts
It looks like it should work the same whether the user is logged in or fired by daily maintenance.

Good explanation of the problem.

Seams like the issue is those 3 lines are not getting output but there are 5 jrCore_list calls, so the first thing to do is figure out which are firing which are failing.

(guess, because i've not checked it) try adding $_params.search2 in at the beginning of the template to see which one is which.

{capture name="s_tpl" assign="s_tpl"}
{literal}
THE SEARCH IS: {$_params.search2} <br>
	{if isset($_items)}
		{foreach $_items as $item}
			{if $item.event_type == 'marriage'}
				{if $item.profile_gender == 'female'}
					{$item.event_date|jrGenCore_get_day} {$item.event_date|jrGenCore_get_readable_month} {$item.event_date|jrGenCore_get_year} {$item.profile_first_name} ve {$item.event_linked_person|iyelikin} evlilik yıldönümü
				{/if}
			{else}
				{$item.event_date|jrGenCore_get_day} {$item.event_date|jrGenCore_get_readable_month} {$item.event_date|jrGenCore_get_year} {$item.profile_name|iyelikin} {if $item.event_type == 'birth'}doğumgünü{elseif $item.event_type == 'death'}ölüm yıldönümü{/if}
			{/if}
		{/foreach}
	{/if}
{/literal}
{/capture}

So you know the {jrCore_list} calls are firing even though they are returning no results that fit your if/else conditions to display a line of text. Try that.

--edit---
Alternatively make a copy of the template for each jrCore_list with an identifier in it if $_params.search2 doesnt output anything.
updated by @michael: 07/17/16 01:54:09AM
Melih
Melih
@melih
8 years ago
198 posts
Hello Michael,

there is no output for {$_params.search2} the line is coming out empty
updated by @melih: 07/17/16 02:12:24PM
michael
@michael
8 years ago
7,714 posts
Go for the second idea then to identify which ones are firing and which aren't.
Melih
Melih
@melih
8 years ago
198 posts
I will try it
michael
@michael
8 years ago
7,714 posts
What we have is:
* jrCore_list calls that are not firing for some reason.

Given that the calls are exactly the same all the time they should produce the same results all the time.

If the calls did not contain any variables then we could easily conclude that the issue is not with the calls.

What we are trying to figure out is if its the calls that are the problem or somewhere else that is the problem.
Melih
Melih
@melih
8 years ago
198 posts
After the trials i did, i realise that the problem was caused by event_date.

In the call i did without using event_date the results came back:

{jrCore_list module="jrGenEvent" search="event_type = birth" privacy_check=false template=$s_tpl}

But if i use event_date, the results came back empty:
{jrCore_list module="jrGenEvent" search="event_date like %0726" privacy_check=false template=$s_tpl}

Do you think that there is a problem about the syntax of this part: search="event_date like %0726"

As you know, dates are written like 20100726. The reason i use the parameter like "event_date like %0726" is i want to call the events without looking at he year according to day and month.

I want to remind you that this code works under normal conditions. But it doesn't work with automatic daily_maintenance.

Can you please advise if
search="event_date like %0726"
is right or wrong?
If it's right why daily_maintenance can't make this work?
michael
@michael
8 years ago
7,714 posts
If it works under normal conditions then its right.

What you should try now is to put that hard-coded version into the email template
THE HARD CODED VERSION
{jrCore_list module="jrGenEvent" search="event_date like %0726" privacy_check=false template=$s_tpl}

THE VERSION WITH THE VARIABLE
{jrCore_list module="jrGenEvent" search="event_date like %$yedi" privacy_check=false template=$s_tpl}

SOME DEBUGGING CODE
search="event_date like %$yedi"
And see if there is any difference. What we're trying to figure out is if that variable is being rendered to the way we think/expect it should be. Because if the variable IS being rendered the way it should be the jrCore_list should work.

If that doesn't work I'll set up a development environment and help figure out the issue ( if you want a hand with it, or I can just keep throwing ideas if you'd prefer that).
Melih
Melih
@melih
8 years ago
198 posts
Hello Michael,
This code didn't work:
{jrCore_list module="jrGenEvent" search="event_date like %0726" privacy_check=false template=$s_tpl}

Now i did this one and waiting daily_maintenance to run automatically
{jrCore_list module="jrGenEvent" search="event_date like 19410726" privacy_check=false template=$s_tpl}

After that if that won't work, i will try lots of combination :) It gets annoying

Hard part is waiting...
updated by @melih: 07/22/16 04:55:49PM
michael
@michael
8 years ago
7,714 posts
Nice idea, If that 19410726 does work it tells us the email system is likely doing something to either '%' or '%$'

What came out for the
SOME DEBUGGING CODE
search="event_date like %$yedi"
??
Melih
Melih
@melih
8 years ago
198 posts
i will try that next time
Melih
Melih
@melih
8 years ago
198 posts
I add it, i will see the result of this:
SOME DEBUGGING CODE
search="event_date like %$yedi"
next daily_maintenance, soon i hope :)
michael
@michael
8 years ago
7,714 posts
give me a few minutes, I'll build a tool to send out test emails.
michael
@michael
8 years ago
7,714 posts
ok, done. I have made a module and sent you an email invite to the channel. Add that channel to your jamroom system and you will be able to install the module "Test Email".

In the ACP there is a tool to test the email sending:
ACP -> MODULES -> CUSTOM -> TEST EMAIL -> TOOLS -> SEND EMAIL

When you click on the tool it will send one email to the registered address in the GLOBAL CONFIG tab of the module.

It will also display whatever is in the TEMPLATES files to the screen at the same time.

So adjust the contents of the files via the TEMPLATES tab, save, then activate them and you will be able to test out things quicker than having to wait for daily maintenance to run.

In case you haven't used the TEMPLATES tab before:

Docs: "Using the Template Editor"
https://www.jamroom.net/the-jamroom-network/documentation/jamroom-admin-handbook/3183/using-the-template-editor
Melih
Melih
@melih
8 years ago
198 posts
Thank you Michael,

I installed it. It looks very usefull to see how an email will look. But those jrCore_list calls works when i trigger the daily_maintenance for example by logging in. My problem is with automatically running daily_maintenance :(
updated by @melih: 07/22/16 05:55:23PM
michael
@michael
8 years ago
7,714 posts
?? daily_maintenance doesnt run as a user, it runs as a system process, so it shouldn't make any difference if its triggered by a bot visiting the site or by a logged in user.

How did you reach the conclusion it was different?
michael
@michael
8 years ago
7,714 posts
There is also an hourly_maintenance function that fires every hour.
Melih
Melih
@melih
8 years ago
198 posts
Because the results are different. If i logged in daily maintenance runs and email sends correctly but if the daily maintenance runs itself say middle of the night emails comes empty. This is how i reached the conclusion.

I didn't try to trigger with hourly maintenance. I will try it too. But now in here it's 4 am :) i will try it tomorrow
Melih
Melih
@melih
8 years ago
198 posts
I finally solved this.

I removed the event_date search part from the jrCore_list call. And arranged them with date_format in the template.

And found out the difference between daily_maintenances coused by site privacy settings.

So i did it the way i want it :)

Thank you all for your concern.
michael
@michael
8 years ago
7,714 posts
You Rock! :)

Good on you for persisting and finding and fixing the problem, and most of all reporting back so others can use the info too.
Melih
Melih
@melih
8 years ago
198 posts
Thank you Michael ;)

Tags