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
Comment #1
fagoforgot 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.
Comment #2
sepgil commentedI've rewrote the csv parser actions and corrected all the things that you mentioned.
Comment #3
fagoPoint 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)
$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().
Comment #4
sepgil commentedfixed
Comment #5
fagoWhy xml_text? It is a xml document object not? Thus just 'xml' should do it.
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:
It's /**
Comment #6
fagoFor clarifying point 1) from the original post:
Comment #7
sepgil commentedFixed the hook.
Comment #8
sepgil commentedand fixed the name of xml export definition.
Comment #9
fagook, next review:
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.
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.
use !empty($info['metatypes']) instead.
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...
Comment #10
fagoThis belongs into the data info hook.
Comment #11
sepgil commenteddone: 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...
Comment #12
sepgil commented