CB Gallery autoaction to create an item

2 weeks 2 days ago - 2 weeks 2 days ago #337815 by activha
Replied by activha on topic CB Gallery autoaction to create an item
Great ! Did not notice the name, but it's working fine with "upload" :-)

Just one last question : how can I get the return after $item->store in the autoaction to output a json success or failure ?
something like if(true) in the autoaction is enough ?

Also are you sure that the triggers are working when calling directly the autoaction or do I need something else ? For now the file is correctly added with the good settings but it does not seem that any auto action for Gallery is triggered with gallery_onBeforeUpdateItem or gallery_onBeforeCreateItem. The gallery_privacy[] added in the formData is also not taken into account and saved.
 

Please Log in to join the conversation.

2 weeks 2 days ago #337819 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item

Just one last question : how can I get the return after $item->store in the autoaction to output a json success or failure ?
something like if(true) in the autoaction is enough ?

The below is typically what we do to ensure a successful store.
if ( $row->getError() || ( ! $row->check() ) || ( ! $row->store() ) ) {
	// FAILED
} else {
	// SUCCESS
}

It checks if errors were logged to the object, checks if validation passed, and calls store and checks if it succeeded. $row->getError() will give you any error messages if it failed.

Also are you sure that the triggers are working when calling directly the autoaction or do I need something else ? For now the file is correctly added with the good settings but it does not seem that any auto action for Gallery is triggered with gallery_onBeforeUpdateItem or gallery_onBeforeCreateItem. The gallery_privacy[] added in the formData is also not taken into account and saved.

Yes, the triggers are being called, but the direct gallery triggers aren't so you'll probably need to make a copy of "CB Gallery - Privacy - Save" and add more triggers to it. It currently is relying on the following.

gallery_onAfterUpdateGalleryItem
gallery_onAfterCreateGalleryItem

Those are only called for frontend user uploads. The below triggers are for direct storage of gallery entries.

gallery_onAfterUpdateItem
gallery_onAfterCreateItem

So in your copy you'd need to use those and adjust all the var3 substitutions to var1. So I guess something like the below.

Global
Triggers: gallery_onAfterUpdateItem, gallery_onAfterCreateItem
Type: CB Privacy
User: Specific
User IDs: [var1_user_id]
Access: Everybody
Action
Mode: Privacy
Method: Save
Asset: gallery.[var1_type].[var1_id]
Input: gallery_privacy

Might be a good idea to add a condition to check if it's from your API endpoint though otherwise it'll run on frontend/backend normal uploads too.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 weeks 2 days ago #337822 by activha
Replied by activha on topic CB Gallery autoaction to create an item
Absolutely perfect -)

I'll just deactivate the system autoactions and let mine manage the privacies.

One last thing : is it possible to set the name and description of the file at the store ?
tried :
formData.append('name', filename);
formData.append('description', summary);
but it does not take it

Please Log in to join the conversation.

2 weeks 2 days ago #337823 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item
Yes that's possible, but only upload processing is automatically handled by ->store(). So for everything else you need to use ->set on $item to set the data from $input (or even [post_name], [post_description], etc.. substitutions).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 weeks 1 day ago #337840 by activha
Replied by activha on topic CB Gallery autoaction to create an item
Ok my code works fine except for two things:

1) a small issue with privacies:
formData.append('gallery_privacy[]', '1');  works fine
but formData.append('gallery_privacy[]', 'MONIA-CO-15');  does not work for special connections.

is there some kind of special thing to do ? 
If I look at the post data from the website and from my code with the auto action they are exactly the same and both loaded into the gallery_privacy array
Any idea ?

2) an auto action works fine when uploading on the website but not from my api though it should also be called after the store item
This is a code auto action 
Triggers : gallery_onAfterCreateItem and gallery_onAfterUpdateItem
User : automatic
Access : everybody
Conditions : none
Action PHP : include_once a php file
Output : return
Substitutions : yes

the main start of the php code is 
<?php

use Joomla\CMS\Factory;
use Joomla\CMS\Http\HttpFactory;

$db  = Factory::getDbo();
$app = Factory::getApplication()->input;

// Variables initiales
// $private = 7; //public access
$userid = $action->string($user, '[var1_user_id]');
$document = $variables['var1']->path();
$documentName = basename($document);
$olddocumentname = null;
$olddocument = null;
$oldid = null;
$olddocumentname = $action->string($user, '[var2_value]');
$olddocument = $variables['var2']->path();
$oldid = $action->string($user, '[var2_id]');

$ext = $variables['var1']->extension();
$link = $variables['var1']->domain();
$id = $action->string($user, '[var1_id]');

$cbUser  = CBuser::getInstance($userid, false);
$token = $cbUser->getUserData()->getString( 'cb_token_api', '0' );
$url = JURI::base() . 'devhandle-command';

if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) {
    echo 'CB not installed'; return;
}

// Récupère toutes les données POST
$privacy_settings = $app->input->post->get('gallery_privacy', array(), 'array');
//...

This code works very well when the file is uploaded on the website after clicking on Register, but when the file is added through my API, it's well added in the gallery, the privacies are correctly set by the new autoaction (except the issue above with connections) but the second auto action is never fired.

I tried to duplicate it and change the user to [var1_user_id] but nothing seems to work and I cannot figure why
Do you have any idea about why this second auto action would not fire ? or a way to solve this ?

Apart of that all the code is ok

Please Log in to join the conversation.

2 weeks 1 day ago #337842 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item

is there some kind of special thing to do ?
If I look at the post data from the website and from my code with the auto action they are exactly the same and both loaded into the gallery_privacy array
Any idea ?

Might be being filtered out at storage if connection types aren't available to that privacy selector. Aside from that I've no idea. You'd have to trial and error until you've something that works. You can also just directly insert the privacy rule into the database as well if you wanted.

I tried to duplicate it and change the user to [var1_user_id] but nothing seems to work and I cannot figure why
Do you have any idea about why this second auto action would not fire ? or a way to solve this ?

I cannot help you debug your custom code. The trigger is likely firing (as confirmed by the privacy storing auto action), but there might be an error happening in the code somewhere.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 1.618 seconds

Facebook Twitter LinkedIn