From a9cee87bab8a999022bf3c587334e803bacc0cca Mon Sep 17 00:00:00 2001 From: Stefano Balietti Date: Wed, 17 Aug 2011 11:52:09 +0200 Subject: [PATCH] Small Changes --- components/taxonomy.inc | 215 +++++++++++++++++++++++----------------- includes/core.batch.inc | 38 ++++--- includes/utils.inc | 2 +- 3 files changed, 151 insertions(+), 104 deletions(-) diff --git a/components/taxonomy.inc b/components/taxonomy.inc index fb25b26..c44b9dc 100644 --- a/components/taxonomy.inc +++ b/components/taxonomy.inc @@ -43,16 +43,16 @@ function taxonomy_patterns_prepare ($action, $tag, &$data = NULL) { if ($tag == 'vocabulary') { if ( $action == PATTERNS_DELETE ) { - $data = _taxonomy_patterns_prepare_vocabulary_delete($data); + $data = _taxonomy_patterns_prepare_vocabulary_delete($action, $data); } else { // Create or Modify - $data = _taxonomy_patterns_prepare_vocabulary($data); + $data = _taxonomy_patterns_prepare_vocabulary($action, $data); } } // TERM else if ($tag == 'term') { - $data = _taxonomy_patterns_prepare_term($data); + $data = _taxonomy_patterns_prepare_term($action, $data); } // TERMS @@ -112,21 +112,30 @@ function taxonomy_patterns_build ($action, $tag, &$data = NULL, $form_id) { } // Build a patterns actions and parameters -function taxonomy_patterns_params($action, $tag, &$data = NULL) { +function taxonomy_patterns_params($action, $form_id, &$data = NULL) { - if ($tag == 'vocabulary') { + if ($form_id == 'taxonomy_form_vocabulary') { if ($data['vid']) { - $result = array((array)taxonomy_vocabulary_load($data['vid'])); + $result = (array)taxonomy_vocabulary_load($data['vid']); } - else { - $result = array(array()); + } + else if ( $form_id == 'taxonomy_vocabulary_confirm_delete') { + if ($data['vid']) { + $result = array($data['vid']); + } + else if (!isset($data['machine_name'])) { + $taxo = taxonomy_vocabulary_machine_name_load($data['machine_name']); + $vid = $taxo->vid; + if (!empty($vid)) { + (array)taxonomy_vocabulary_load($data['vid']); + } } } - else if ( $tag == 'term' && $action == PATTERNS_CREATE ) { + else if ( $form_id == 'taxonomy_form_term') { $vocab = taxonomy_vocabulary_load($data['vid']); $result = array($data, $vocab); } - else if ( $tag == 'term' && $action == PATTERNS_DELETE ) { + else if ( $form_id == 'taxonomy_term_confirm_delete') { $result = array($data['tid']); } @@ -138,81 +147,6 @@ function taxonomy_patterns_cleanup($action, $tag, &$data = NULL) { unset($_POST['op']); } -// Return a summary of an action -//function taxonomy_patterns_summary ($id = NULL, &$data = NULL) { -// -// switch ($id) { -// case 'taxonomy_form_vocabulary': -// if (!$data['name'] && $data['vid']) { -// $data['name'] = db_query('SELECT name FROM {taxonomy_vocabulary} WHERE vid = :vid', array('vid' => $data['vid']))->fetchField(); -// } -// -// if (!taxonomy_vocabulary_machine_name_load($data['name'])) { -// return t('Create vocabulary %vocab', array('%vocab' => $data['name'])); -// } -// else { -// return t('Edit vocabulary %vocab', array('%vocab' => $data['name'])); -// } -// break; -// } -//} - - -// Pre validate actions -// Need to check for required tags etc... -//function taxonomy_patterns_validate($action, $tag, &$data = NULL) { -// -// if ($tag = 'vocabulary') { -// if (!empty($data['vid']) && !taxonomy_vocabulary_load($data['vid'])) { -// return t("Invalid vid: %vid. This vocabulary doesn't exist", array('%vid' => $data['vid'])); -// } -// } -//} - -// Return the form_id('s) for each action -//function taxonomy_patterns_form_id ($id = NULL, &$data = NULL) { -// -// // VOCABULARY -// if ($id =='vocabulary') { -// if (isset($data['delete'])) { -// return 'taxonomy_vocabulary_confirm_delete'; -// } -// else { -// return 'taxonomy_form_vocabulary'; -// } -// } -// // TERM -// elseif ($id == 'term') { -// if (isset($data['delete'])) { -// return 'taxonomy_term_confirm_delete'; -// } -// else { -// return 'taxonomy_form_term'; -// } -// } -//} - -// // Return term/vocab identifiers -// case 'identifier': -// switch ($id) { -// case 'taxonomy_form_term': -// if (is_numeric($data['tid'])) { -// return $data['tid']; -// } -// else { -// return db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE LOWER(t.name) = LOWER(:name) AND LOWER(v.name) = LOWER(:voc)', array('name' => $data['name'], 'voc' => $data['vocabulary']))->fetchField(); -// } -// break; -// case 'taxonomy_form_vocabulary': -// if (is_numeric($data['vid'])) { -// return $data['vid']; -// } -// else { -// return db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE LOWER(name) = LOWER(:name)', array('name' => $data['name']))->fetchField(); -// } -// break; -// } -// break; @@ -223,7 +157,7 @@ function taxonomy_patterns_cleanup($action, $tag, &$data = NULL) { /* * Does the standard prepararion for a single term given the vocabulary id */ -function _taxonomy_patterns_prepare_term ($data, $vid = NULL) { +function _taxonomy_patterns_prepare_term ($action, $data, $vid = NULL) { // Get the vid first @@ -296,7 +230,30 @@ function _taxonomy_patterns_prepare_term ($data, $vid = NULL) { return $data; } -function _taxonomy_patterns_prepare_vocabulary ($data) { +function _taxonomy_patterns_prepare_vocabulary ($action, $data) { + + if ($action == PATTERNS_MODIFY) { + if (!isset($data['vid'])){ + + // We are modifying the machine_name as well + if (isset($data['old_machine_name'])){ + $taxo = taxonomy_vocabulary_machine_name_load($data['old_machine_name']); + $vid = $taxo->vid; + } + // We are changing other stuff + else if (isset($data['machine_name'])){ + $taxo = taxonomy_vocabulary_machine_name_load($data['machine_name']); + $vid = $taxo->vid; + // The old_machine_name must be set equal to machine_name + $data['old_machine_name'] = $data['machine_name']; + } + + if(!empty($vid)) { + $data['vid'] = $vid; + } + + } // End: vid missing + } // End: PATTERNS_MODIFY $default_weight = 0; $default_hierarchy = 0; @@ -308,11 +265,12 @@ function _taxonomy_patterns_prepare_vocabulary ($data) { if (!isset($data['hierarchy'])) { $data['hierarchy'] = $default_hierarchy; } - - return $data; + + + return $data; } -function _taxonomy_patterns_prepare_vocabulary_delete ($data) { +function _taxonomy_patterns_prepare_vocabulary_delete ($action, $data) { // Firt use the vid, if we have it if (isset($data['vid'])) { $taxo = taxonomy_vocabulary_load($data['vid']); @@ -331,6 +289,83 @@ function _taxonomy_patterns_prepare_vocabulary_delete ($data) { return $data; } +// Return a summary of an action +//function taxonomy_patterns_summary ($id = NULL, &$data = NULL) { +// +// switch ($id) { +// case 'taxonomy_form_vocabulary': +// if (!$data['name'] && $data['vid']) { +// $data['name'] = db_query('SELECT name FROM {taxonomy_vocabulary} WHERE vid = :vid', array('vid' => $data['vid']))->fetchField(); +// } +// +// if (!taxonomy_vocabulary_machine_name_load($data['name'])) { +// return t('Create vocabulary %vocab', array('%vocab' => $data['name'])); +// } +// else { +// return t('Edit vocabulary %vocab', array('%vocab' => $data['name'])); +// } +// break; +// } +//} + + +// Pre validate actions +// Need to check for required tags etc... +//function taxonomy_patterns_validate($action, $tag, &$data = NULL) { +// +// if ($tag = 'vocabulary') { +// if (!empty($data['vid']) && !taxonomy_vocabulary_load($data['vid'])) { +// return t("Invalid vid: %vid. This vocabulary doesn't exist", array('%vid' => $data['vid'])); +// } +// } +//} + +// Return the form_id('s) for each action +//function taxonomy_patterns_form_id ($id = NULL, &$data = NULL) { +// +// // VOCABULARY +// if ($id =='vocabulary') { +// if (isset($data['delete'])) { +// return 'taxonomy_vocabulary_confirm_delete'; +// } +// else { +// return 'taxonomy_form_vocabulary'; +// } +// } +// // TERM +// elseif ($id == 'term') { +// if (isset($data['delete'])) { +// return 'taxonomy_term_confirm_delete'; +// } +// else { +// return 'taxonomy_form_term'; +// } +// } +//} + +// // Return term/vocab identifiers +// case 'identifier': +// switch ($id) { +// case 'taxonomy_form_term': +// if (is_numeric($data['tid'])) { +// return $data['tid']; +// } +// else { +// return db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE LOWER(t.name) = LOWER(:name) AND LOWER(v.name) = LOWER(:voc)', array('name' => $data['name'], 'voc' => $data['vocabulary']))->fetchField(); +// } +// break; +// case 'taxonomy_form_vocabulary': +// if (is_numeric($data['vid'])) { +// return $data['vid']; +// } +// else { +// return db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE LOWER(name) = LOWER(:name)', array('name' => $data['name']))->fetchField(); +// } +// break; +// } +// break; + + /////////////////////////////////////////////////////////////////////////// // @TODO: Check This // FROM NOW ON THIS WAS IN pattern.module, but it is all for taxonomy.inc diff --git a/includes/core.batch.inc b/includes/core.batch.inc index cdea4cd..0aa6cad 100644 --- a/includes/core.batch.inc +++ b/includes/core.batch.inc @@ -46,7 +46,14 @@ function patterns_execute_pattern($pattern, $params = array()) { // Ste: Actions_map seems to be used with includes. Probably we do not need it now. // $actions_map = array('patterns' => $pattern_details['info'], 'map' => $pattern_details['actions_map']); - $actions_map = array('patterns' => $infos, 'map' => NULL); + +// TODO: Patterns details was returning this in case of recursive includes +// $result['actions_map'][] = array( +// 'pid' => $pattern->pid, +// 'index' => $key, +// ); + + $actions_map = array('patterns' => $infos, 'map' => NULL); // Fix this //////////////////////////////////////// @@ -141,12 +148,15 @@ function patterns_prepare_actions(&$actions, $actions_map) { ///////////////////////////////////////////////////////// // This is in case of included patterns. Not for now - $action_location = patterns_locate_action ($data['tag'], $actions_map); - $index = $action_location['key']; - $pattern_title = $action_location['title']; - $pattern_file = $action_location['file']; - +// $action_location = patterns_locate_action ($data['tag'], $actions_map); +// $index = $action_location['key']; +// $pattern_title = $action_location['title']; +// $pattern_file = $action_location['file']; ///////////////////////////////////////////////////////// + + // TODO: manage multiple pattern includes + $pattern_info = reset($actions_map['patterns']); + $pattern_title = $pattern_info['title']; if (!array_key_exists($data['tag'], $tag_modules)) { $errors[] = t('Action #%num (%tag) in pattern %title: <%tag> is not a valid tag', array('%num' => $index+1, '%tag' => $data['tag'], '%title' => $pattern_title)); @@ -156,6 +166,7 @@ function patterns_prepare_actions(&$actions, $actions_map) { // Validate tags with their appropriate components ////////////////////////////////////////////////// $results = patterns_invoke('validate', $key, &$data); + if ($results['status'] == PATTERNS_ERR) { $errors[] = t('Action #%num (%tag) in pattern %title: !msg', array('!msg' => $error, '%num' => $index+1, '%tag' => $data['tag'], '%title' => $pattern_title)); } @@ -204,10 +215,10 @@ function patterns_batch_actions($action, $data, $place, $actions_map, &$context) $result = patterns_implement_action($action, $data, $context['results']['identifiers'], $place, $actions_map); - if (!$result['success']) { + if ($result['status'] == PATTERNS_ERROR) { // we use 'results' to keep track of errors and abort execution if required $context['results']['abort'] = TRUE; - $context['results']['error_message'] = $result['error_message']; + $context['results']['error_message'] = $result['msg']; } if (timer_read('patterns_action') < 1000) { @@ -299,6 +310,7 @@ function patterns_implement_action($action, $data, &$identifiers, $place = 0, $a $result = patterns_invoke('params', $action, $clone, $form_id, $action_state); if ($result['status'] == PATTERNS_ERROR) { + drupal_set_message($result['msg'],'error'); return $result; } @@ -314,11 +326,6 @@ function patterns_implement_action($action, $data, &$identifiers, $place = 0, $a /////////////////// patterns_execute_action($form_id, $action_state, $params); - - if ($result['status'] == PATTERNS_ERROR) { - return $result; - } - // @TODO: do we need this? if ($errors = form_get_errors()) { $result['error_message'] = t('Above error(s) occured while executing action #%num (%action) in %title pattern. Error location(s) are: %errors', array('%num' => $index, '%action' => $action_description, '%title' => $pattern_title, '%errors' => str_replace('][', '->', implode(', ', array_keys($errors))))); @@ -330,6 +337,11 @@ function patterns_implement_action($action, $data, &$identifiers, $place = 0, $a // CLEAN UP: Let a component cleanup after each action //////////////////// $return = patterns_invoke('cleanup', $action, $clone, $form_id, $action_state); + + if ($result['status'] == PATTERNS_ERROR) { + drupal_set_message($result['msg'],'error'); + // do not return here + } } diff --git a/includes/utils.inc b/includes/utils.inc index 98ec1b6..b3944aa 100644 --- a/includes/utils.inc +++ b/includes/utils.inc @@ -679,7 +679,7 @@ function patterns_results ($status = PATTERNS_SUCCESS, $msg = 'Execution success function _patterns_is_patterns_results ($results) { // It is the only mandatory field - if (!isset($return['status'])){ + if (!isset($results['status'])){ return FALSE; }