At this point, I'm not terribly worried about importing/exporting Conditional Actions for use on a site, although I'd love to have that by the 2.0 final release. However, it would indeed be helpful if there was a way to generate an export that is human readable so people can help debug other users' predicates in the forums and elsewhere.

Comments

rszrama’s picture

Just for reference, here's a related thread in the forums.

rszrama’s picture

cha0s brought up the idea of an XML export, and that seems like a perfect common ground... human readable enough for us to debug in a forum post but still machine readable for when we get imports working. I like it.

cha0s’s picture

StatusFileSize
new8.87 KB

Here's the first work I've done on this over the last day and a half. Give her a spin and tell me what ya find ^^...

cha0s’s picture

Status: Active » Needs review
StatusFileSize
new13.09 KB

Update; predicate element (conditions/actions) settings are now imexported in a fully human-readable/mutable format! Also, I added much comentarios...

cha0s’s picture

StatusFileSize
new13.09 KB

Er, I made a last minute change before that patch that broke exporting. Also, I was importing actions incorrectly.

Island Usurper’s picture

Might want to add a dependencies line to ca_export.info.

Just from reading, I don't see any other problems. I'll give it a more thorough review tomorrow.

rszrama’s picture

Dependency++. Not sure about putting an extra module in core yet. Really looking for human readable summary/output still, too. I feel like cha0s and I chatted about this, but I forgot to update the issue or something. :-/

a_c_m’s picture

Version: 6.x-2.0-beta3 » 6.x-2.x-dev
StatusFileSize
new13.13 KB

Added the dependency, also changed the menu path and added the menu items to the UI for CA.

cha0s’s picture

+1

Thanks for the improvements. Looks great!

mikejoconnor’s picture

StatusFileSize
new3.83 KB

It is nice to have these as "human readable", and I'm sure outside developers would rather work with xml than arrays. That being said, I wonder if this is really the best option. Both CCK and Views simply export a text that can be ran through eval() for import. Although that method has a lot of "uglyness", it also allows me to build a predicate through the interface, export it, and embed it in my code with hook_ca_predicate.

I've attached a solution I was playing with earlier today. It is not finished, but it's a good example of the simplicity of a php based import/export.

cha0s’s picture

Haha, this never even got in?

mikejoconnor’s picture

oops, includes some stuff in that last patch, which shouldn't be there. I'll resubmit later.

@chaos
Nope, although I think there's a module for it, and this patch always runs locally on my dev box :)

mikejoconnor’s picture

StatusFileSize
new3.95 KB

ok, here's a version against a more recent dev release.

tr’s picture

I'm in favor of adding it in. Can someone review the patch?

jeremy.zerr’s picture

Status: Needs review » Needs work
StatusFileSize
new40.96 KB

I just took the patch in #14 and manually copy/pasted in the changes into 2.2 and found that the conditions are being exported with one too many levels of nesting.

Attached is a screenshot of what the Conditions page looks like.

The php code exported was:

array (
  '#pid' => '1',
  '#title' => 'Grant appropriate node access on ORDER UPDATE',
  '#description' => '',
  '#class' => 'uc_node_access',
  '#status' => '1',
  '#weight' => '0',
  '#uid' => '0',
  '#trigger' => 'uc_order_status_update',
  '#conditions' => 
  array (
    '#operator' => 'AND',
    '#conditions' => 
    array (
      0 => 
      array (
        '#operator' => 'AND',
        '#conditions' => 
        array (
          0 => 
          array (
            '#name' => 'uc_order_status_condition',
            '#title' => 'Check the order status',
            '#argument_map' => 
            array (
              'order' => 'order',
            ),
            '#settings' => 
            array (
              'negate' => 1,
              'order_status' => 'completed',
            ),
          ),
          1 => 
          array (
            '#name' => 'uc_order_status_condition',
            '#title' => 'Check the order status',
            '#argument_map' => 
            array (
              'order' => 'updated_order',
            ),
            '#settings' => 
            array (
              'negate' => 0,
              'order_status' => 'completed',
            ),
          ),
        ),
      ),
    ),
  ),
  '#actions' => 
  array (
    0 => 
    array (
      '#name' => 'uc_node_access_grant_access',
      '#title' => 'Grant node access to customer',
      '#argument_map' => 
      array (
        'order' => 'order',
      ),
      '#settings' => 
      array (
      ),
    ),
  ),
  '#created' => '1280175151',
  '#modified' => '1280175274',
)

The part that should be cleaned up is:

  '#conditions' => 
  array (
    '#operator' => 'AND',
    '#conditions' => 
    array (
      0 => 
      array (
        '#operator' => 'AND',
        '#conditions' => 
        array (
          0 => 
          array (

The '#operator' is in there twice, but only should be in there once.

I used this export function to export a CA I created by hand, removed one layer of the double nested part, and then added it to the default CA's created by the uc_node_access module successfully for a project I'm working on.

Thanks,
Jeremy

junedkazi’s picture

Hi,

I created a new module using some of the code from http://drupal.org/node/372290#comment-3056856 .

There was one problem which I noticed in the validate function.
The validate function was validating based on #pid but I thought it could be the wrong way to do it bcoz of the following reason;
1 - If we import the export on a new site which already has some predicates it will throw an error saying the predicate already exists.
2 - The same case is true if we do it on same site the same problem arises.

In the submit function when we submit it we do not consider the pid number to be in incremental order. Refer to this piece of code in ca.admin.inc

    $predicate['#pid'] = variable_get('ca_predicates_pid', 1);
    variable_set('ca_predicates_pid', $predicate['#pid'] + 1);

This is what ca module does when we create a new predicate. So I tried to implement the same thing in my module.

The project link is as follows
http://drupal.org/project/uc_ca_import_export

Credits for this project goes to
@mikejoconnor for his patch in #14
@all people part of this issue

I would like people to download the module and submit issues against it so that the module can be improved. If anyone wants to join in to improve the module are more than welcome.

longwave’s picture

Status: Needs work » Closed (won't fix)

Exists in contrib as http://drupal.org/project/uc_ca_import_export and not needed in 7.x now we have Rules.