Jr Actions

nate
@nate
11 years ago
917 posts
I have a module that when installed did not support actions. I later added in the code in the include file to support actions. The modules already has item_action templates. I am also seeing "add to timeline" on my forms.

I am not seeing the actions added to the feed. Is there something else I am suppose to do?
updated by @nate: 03/24/14 10:23:26PM
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
You need to run jrAction_save at the point where you want the action to be saved.

jrAction_save function takes these params:
function jrAction_save($mode, $module, $item_id, $_data = null, $profile_check = true, $profile_id = 0)

So you'd need something like this, after the db save and before you'd reset the profile cache:
    $_data['mycustom1'] = 'joe blogs';
    $_data['mycustom2'] = '23';
    $_data['mycustom3'] = 'normal mixes';

    // Add to Actions...
    jrCore_run_module_function('jrAction_save', 'create', 'myModule', $_data);

    jrCore_form_delete_session();
    jrProfile_reset_cache();

The $_data array is where you add your custom stuff, you can save anything you need and then use it in the action template, item_action.tpl:
<span class="action_my_custom_stuff">  {$item.action_data.mycustom1} uploaded {$item.action_data.mycustom2} {$item.action_data.mycustom3} today:</span>



--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
The jrAction_save code is in place. I forgot to mention it.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
Is the action being created in the database?


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
No, they are not.

How do the listeners get registered? Is it anything like the forms?

If I change the forms, I have to manually delete the form from the db to see the changes.
updated by @nate: 02/17/14 03:50:22PM
michael
@michael
11 years ago
7,800 posts
normal 'events' and 'listeners' setup is here (think you've already seen it).

"Events and Listeners"
https://www.jamroom.net/the-jamroom-network/documentation/development/1011/events-and-listeners


for the jrAudio module it registers for them like this:
    jrCore_register_module_feature('jrCore', 'action_support', 'jrAudio', 'create', 'item_action.tpl');
    jrCore_register_module_feature('jrCore', 'action_support', 'jrAudio', 'update', 'item_action.tpl');
    jrCore_register_module_feature('jrCore', 'action_support', 'jrAudio', 'create_album', 'item_action.tpl');
    jrCore_register_module_feature('jrCore', 'action_support', 'jrAudio', 'update_album', 'item_action.tpl');

(I think your saying you've already got this working too.)

Is there any quota based settings?

in your _save() function is jrAction_save being called?

that for jrAudio is in view_jrAudio_create_save() there is this code:
    // Add to Actions...
    jrCore_run_module_function('jrAction_save', 'create', 'jrAudio', $aid);

does your _save() functions also include that call?
nate
@nate
11 years ago
917 posts
Yes, the function is being called in the save function. It isn't working for any quota. I only have 2.
michael
@michael
11 years ago
7,800 posts
From there my guesses run out.

So what I would do to find out what is going on is to put a breakpoint inside jrAction_save() at the first if
    // See if we are turned on for this module
    if (!isset($_user['quota_jrAction_allowed']) || $_user['quota_jrAction_allowed'] != 'on') {
        return true;
    }

and walk through it step-by-step until i could see where it didn't do what I wanted it to do.

Your overflowing with processing power, time to put some of it to work and setup a debugger:

"Setting up a Debugging Environment"
https://www.jamroom.net/the-jamroom-network/documentation/development/129/setting-up-a-debugging-environment

Its a real useful tool to have to fall back on.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
I'm sure Michael's advice is best, but if you dont have time to set up a debugging enviro today, use
fdebug( 'it didnt make it to here', $_user['quota_jrAction_allowed'] );
instead of breakpoints, then check the output in the debug log. I open the debug log in Console (Console is in applications/utilities on a mac, I keep it open most of the time). So add the debug (or a series of them), submit the form, switch to Console to see the fdebugs. Slow, yet quick and dirty at the same time, which can be nice sometimes. :)

Nate, can you post the code you are using to get the action data into the db? So the lines from the init function registering the action, and the lines in the form save function.

I've been testing some module stuff with actions today, so the files are still open in my editor.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
11 years ago
7,800 posts
ooh. that made me think. It would be good to have a fdebug() like function that dumps down to the firebug console. It would mean you wouldn't have to have the 'debug log' tab open and could stay on the same page.

A debugger will take a couple of hours to setup. But it is soooo worth it.
brian
@brian
11 years ago
10,149 posts
michael:
ooh. that made me think. It would be good to have a fdebug() like function that dumps down to the firebug console.

I've actually got this in my old JR5 code back from the first code base - I'll dig it up ;)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
michael
@michael
11 years ago
7,800 posts
:) you are awesome.
nate
@nate
11 years ago
917 posts
//Actions
    jrCore_register_module_feature('jrCore','action_support','xtSong','create','item_action.tpl');
    jrCore_register_module_feature('jrCore','action_support','xtSong','update','item_action.tpl');
	jrCore_register_module_feature('jrCore', 'action_support', 'xtSong', 'create_album', 'item_action.tpl');
    jrCore_register_module_feature('jrCore', 'action_support', 'xtSong', 'update_album', 'item_action.tpl');

// Add to Actions...
jrCore_run_module_function('jrAction_save','create','xtSong',$aid);
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
So the only variable is $aid. Check that $aid has a value right before // Add to Actions...

fdebug('xtraxx says aid = '.$aid);



--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
Quote:
(2014-02-18T23:05:15+00:00 0.18256000)-(mem: 13369344)-(pid: 3979)-(uri: /songs/create_save/__ajax=1) |xtraxx says aid = 92|

Still nothing.
nate
@nate
11 years ago
917 posts
I'm gonna debug the jrAction_save() function.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
Natedogg265:
Quote:
(2014-02-18T23:05:15+00:00 0.18256000)-(mem: 13369344)-(pid: 3979)-(uri: /songs/create_save/__ajax=1) |xtraxx says aid = 92|

Still nothing.

That isnt nothing, it tells you you are ok up to there (as long as id=92 is what you are expecting to see at that point ).

You should find the problem somewhere between that fdebug and the db save function.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
Or is that after the save?


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
It's after the db save function. When I said nothing, I meant in the actions table.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
And you are sure that id is correct as the xtSong id, it should save.

jrAudio update does it exactly like that:
    // Add to Actions...
    jrCore_run_module_function('jrAction_save', 'update', 'jrAudio', $_post['id']);

xtSong create update functions work exactly like jrAudio so if 92 is the correct id for the song, it should save. I dont think the template existing is important to save to the db.

Is this for an admin user or an artist updating their own xtsong?


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
Yes, 92 is the correct ID.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
I'm not sure then Nate. If you can make sure the bitbucket repo is up to date I will sync mine and take a look at the code tomorrow morning, but I can't move it to my dev site, so I can only look through the code to see if anything jumps out.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
nate
@nate
11 years ago
917 posts
Don't bother. I'll chase it down.

The only action being saved, that I can see, is from the jrFollower module.
nate
@nate
11 years ago
917 posts
Quote: [artist6] : jrAction_save() after pruning, empty result!
brian
@brian
11 years ago
10,149 posts
This errors means that when then jrAction_save() function went to 'save' the action, based on the module and ID you have given it, nothing is left to save after "pruning" (pruning basically removes quota and extraneous profile keys). Usually this indicated the actual item does not exist.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
nate
@nate
11 years ago
917 posts
What does this do?

// Let other modules cancel our action if needed
$_data = jrCore_trigger_event('jrAction', 'action_save', $_data, $_post);
brian
@brian
11 years ago
10,149 posts
It's an event trigger - for example you could listen to this event ("action_save") and inspect/change the payload by rewriting $_data and sending it back as you want it to be. You could also return "false" from your event listener and have the action save nullified.

It's just an event that lets other modules know that that an action_save is going to occur in case they care or want to do something about it.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 02/20/14 11:16:49AM
nate
@nate
11 years ago
917 posts
I've chase it down but now I don't understand the failure. The inpute is in place and it is checked by default.

Quote: (2014-02-20T20:18:14+00:00 0.20838200)-(mem: 12058624)-(pid: 32504)-(uri: /songs/create_save/__ajax=1) |jrAction fails timeline check|
brian
@brian
11 years ago
10,149 posts
Do an fdebug($_post) there and look at the actual post contents.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
nate
@nate
11 years ago
917 posts
Quote: (2014-02-21T23:48:32+00:00 0.31395000)-(mem: 12058624)-(pid: 22684)-(uri: /songs/create_save/__ajax=1) |jrAction post is: = off|

Something is turning it off.


updated by @nate: 02/21/14 03:56:47PM
nate
@nate
11 years ago
917 posts
Even in the xtSong create_save function the jraction_add_to_timeline is turned off in the post. But of course the checkbox is actually checked when posting. Some how it's getting turned off.
michael
@michael
11 years ago
7,800 posts
A debugger would let you see were its getting changed. you can 'add to watches' then keep pressing F8 as the code runs and you can see exactly where it changes.

Try seeing if it is set to 'on' in the datastore. it might just be defaulting to "off" because it hasnt been saved. (guess.)
brian
@brian
11 years ago
10,149 posts
Natedogg265:
Even in the xtSong create_save function the jraction_add_to_timeline is turned off in the post. But of course the checkbox is actually checked when posting. Some how it's getting turned off.

Check for a form_validate listener (turn on developer mode and go to the Core Info tab) - look for modules that are responding to the "form_validate" event and see if any of them are changing it.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags