8 	/**
9 	* Implements hook_datainfo().
10 	*/
11 	function transformers_actions_data_info() { 

It's hook_rules_data_info(). Also wrap => TRUE would give syntax errors.

        'string' => array(
          'type' => 'text',
          'label' => t('CSV string'),
          'description' => t('CSV data as text'),
        ),

The parameter name 'string' doesn't say much. As label klausi and me would suggest to use "Raw CSV text" - also add a description that explains that the text needs to contain a valid CSV - this is important as the user may configure any text for this parameter. As machine readable parameter name then perhaps 'raw_csv' would be a good choice? Analogous for the XML action.

      'provides' => array(
        'string' => array(
          'type' => 'text',
          'label' => t('CSV string'),
        ),

Always try to come up with descriptive parameter/variable names. Try to avoid 'string' at all - it's a developer term. Better say CSV text.

          'label' => t('XML doc'),

Again a bad label. Best analogously use 'Raw XML' or for the parsed representation "XML document".

* The CSV actions always use a file for interim storage. This is rather ugly, as it is unnecessary. Does the library require files? Is it possible to use without having a file? This would be much better. Else this needs commenting + are the files properly cleaned up afterwards? Perhaps you could just use split() instead? See http://php.net/manual/en/function.str-getcsv.php.

Comments

fago’s picture

forgot to review the tests:
> for ($i=0;$i<3;$i++) {

code style: missing space after ;

>class TransformersActionsTestCase
Missing doxygen comment for class.

> $this->assert($result == $string, 'Test with default delimiter');
Alway use $this->assertTrue or $this->assertEqual().

> list($result) = rules_action('xml_import', array())->execute($data);
array() is default and can be removed.

* Missing doxygen for methods. Shortly describe what is tested.

sepgil’s picture

Assigned: Unassigned » sepgil
Status: Active » Needs review

I've rewrote the csv parser actions and corrected all the things that you mentioned.

fago’s picture

Status: Needs review » Needs work

Point 1) still applies

2) there is still a 'string' name.

ad) transformers_actions_csv_import()
What happens if the CSV is not valid? Best you should through a RulesException then. The same for XML. Best also add a test-case for that to ensure it's fine. (look for RulesException in the rules tests for an example of how to test that an exception is thrown)

if (is_array($csv)) {

$csv should always be an array. Make sure your actions follow that (also import), then you don't need to check it.

> 'label' => t('XML data structure'),
Why not just call it XML document? or XML data? The DOM api calls it also document, from that point of view document would make sense.

> $this->assertEqual($result[1][1] == $this->data[1][1], 'Testing CSV import');
You used that wrong. Check the doxygen of assertEqual().

sepgil’s picture

Status: Needs work » Needs review

fixed

fago’s picture

Priority: Normal » Critical
Status: Needs review » Needs work

+ 'xml_text' => array(
'type' => 'xml',
- 'label' => t('XML data structure'),
+ 'label' => t('XML document'),
),

Why xml_text? It is a xml document object not? Thus just 'xml' should do it.

+ //Delete the last line break
+ $csv_text = drupal_substr($csv_text, 0, drupal_strlen($csv_text)-1);

Missing space after //. Also each comment has to end with a point. Apart from that instead of deleting this extra line ending better just build $csv_lines as array and implode it in the end.

Point 1) still unfixed. This is totally broken:

8 /**
9 * Implements hook_rules_data_info().
10 */
11 function transformers_actions_data_info() {
12 return array(
13 'csv' => array(
14 'label' => t('CSV'),
15 wrap => TRUE,
16 ),
17 'xml' => array(
18 'label' => t('XML'),
19 wrap => TRUE,
20 ),
21 );
22 }

116 /*
117 * Action: Import CSV data from a string.
118 */

It's /**

fago’s picture

For clarifying point 1) from the original post:

8 /**
9 * Implements hook_datainfo().
10 */
11 function transformers_actions_data_info() {

It's hook_rules_data_info(). Also wrap => TRUE would give syntax errors.

sepgil’s picture

Status: Needs work » Needs review

Fixed the hook.

sepgil’s picture

and fixed the name of xml export definition.

fago’s picture

Version: » 7.x-1.x-dev
Status: Needs review » Needs work

ok, next review:

	   foreach ($xml_info['property info'] as $key => $info) {
31 	  	     if ($key === $name) {
32 	  	       switch ($info['metatype']) {
33 	  	         case 'Attribute':
34 	  	           $return = $data->attributes->getNamedItem($name)->value;
35 	  	           break;
36 	  	         case 'Text':
37 	  	           $return = trim($data->textContent);
38 	  	           break;
39 	  	       }
40 	  	     }
41 	  	   }
42 	  	 
43 	  	   return $return;
44 	  	 }

Why this foreach() when the key is known? Also you can directly return in the switch. Then I'd suggest to use lowercase metatypes, as machine readable names are usually lowercase only.

           'metatypes' => FALSE,

Is this flag documented somewhere? At least document it at the UI class.

>TransformersActionsMetadataUI::getOptions()
I've fixed the RulesUI method in the meanwhile, so you can use it. Also I've added code for editing variable info recently so you can leverage it for your properties now. See http://drupal.org/cvs?commit=399984. Maybe you can re-use some stuff directly, if not copy&paste + modification should give you drag&drop UI. (Maybe create a separate issue for this task).

>17 // This
?!

>nodelist2array()
module namespace violation.

if (isset($info['metatypes']) && $info['metatypes'] == TRUE) { 

use !empty($info['metatypes']) instead.

46 	/**
47 	* UI for metadata
48 	*/ 

Code style: Comments have to end with a point. Note: everywhere.

ad transformers_actions_metadata_wrapper_xml_getter() & csv:
Comment should say this is a getter callback for...

fago’s picture

293 	 'property defaults' => array(
294 	'getter callback' => 'transformers_actions_metadata_wrapper_xml_getter',
295 	), 

This belongs into the data info hook.

sepgil’s picture

Status: Needs work » Needs review

done: http://drupal.org/cvs?commit=402216

>I've fixed the RulesUI method in the meanwhile, so you can use it. Also I've added code for editing variable info recently so you can leverage it for your properties now. >See http://drupal.org/cvs?commit=399984. Maybe you can re-use some stuff directly, if not copy&paste + modification should give you drag&drop UI. (Maybe create a >separate issue for this task).
I'll look in to that later, the basics ui are ready...

sepgil’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.