@@ -159,7 +159,6 @@ function os2web_cs_service_create_case(array $data) {
159
159
$result = $query
160
160
->entityCondition('entity_type', 'node')
161
161
->propertyCondition('type', 'os2web_cp_service_cp_case')
162
- ->propertyCondition('status', 1)
163
162
->fieldCondition('field_os2web_cp_service_sysid', 'value', $data['fields']['SystemID'], '=')
164
163
->execute();
165
164
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
@@ -170,13 +169,13 @@ function os2web_cs_service_create_case(array $data) {
170
169
}
171
170
}
172
171
else {
173
- $node = node_load($nids);
172
+ $node = node_load(array_pop( $nids) );
174
173
}
175
174
176
175
// See if the triggered rules on the published node, is approved
177
176
// in the vocabulary. Otherwise the node will be unpublished.
178
- $vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_approved_rules');
179
- $approved_rules = taxonomy_get_tree($vocabulary ->vid);
177
+ $approved_vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_approved_rules');
178
+ $approved_rules = taxonomy_get_tree($approved_vocabulary ->vid);
180
179
$approved = FALSE;
181
180
foreach ($data['rules'] as $trigger_rule) {
182
181
foreach ($approved_rules as $approved_rule) {
@@ -229,7 +228,17 @@ function os2web_cs_service_create_case(array $data) {
229
228
230
229
unset($node->field_os2web_cp_service_rules[LANGUAGE_NONE]);
231
230
foreach ($data['rules'] as $name) {
232
- $term = array_pop(taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_approved_rules'));
231
+ $term = taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_rules');
232
+ if (empty($term)) {
233
+ $rules_vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_rules');
234
+ $term = new stdClass();
235
+ $term->vid = $rules_vocabulary->vid;
236
+ $term->name = $name;
237
+ taxonomy_term_save($term);
238
+ }
239
+ if (is_array($term)) {
240
+ $term = array_pop($term);
241
+ }
233
242
$node->field_os2web_cp_service_rules[LANGUAGE_NONE][]['tid'] = $term->tid;
234
243
}
235
244
@@ -363,7 +372,6 @@ function os2web_cs_service_create_document(array $data) {
363
372
$result = $query
364
373
->entityCondition('entity_type', 'node')
365
374
->propertyCondition('type', 'os2web_cp_service_cp_document')
366
- ->propertyCondition('status', 1)
367
375
->fieldCondition('field_os2web_cp_service_sysid', 'value', $data['fields']['SystemID'], '=')
368
376
->execute();
369
377
$node = new stdClass();
@@ -424,7 +432,17 @@ function os2web_cs_service_create_document(array $data) {
424
432
425
433
unset($node->field_os2web_cp_service_rules[LANGUAGE_NONE]);
426
434
foreach ($data['rules'] as $name) {
427
- $term = array_pop(taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_approved_rules'));
435
+ $term = taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_rules');
436
+ if (empty($term)) {
437
+ $rules_vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_rules');
438
+ $term = new stdClass();
439
+ $term->vid = $rules_vocabulary->vid;
440
+ $term->name = $name;
441
+ taxonomy_term_save($term);
442
+ }
443
+ if (is_array($term)) {
444
+ $term = array_pop($term);
445
+ }
428
446
$node->field_os2web_cp_service_rules[LANGUAGE_NONE][]['tid'] = $term->tid;
429
447
}
430
448
@@ -437,28 +455,29 @@ function os2web_cs_service_create_document(array $data) {
437
455
return FALSE;
438
456
}
439
457
440
- // Update case .
458
+ // Update reference on cases .
441
459
$query = new EntityFieldQuery();
442
460
$result = $query
443
461
->entityCondition('entity_type', 'node')
444
462
->propertyCondition('type', 'os2web_cp_service_cp_case')
445
- ->propertyCondition('status', 1)
446
463
->fieldCondition('field_os2web_cp_service_sysid', 'value', $data['fields']['Sag SystemID'], '=')
447
464
->execute();
448
- $nids = array_keys($result['node']);
449
- foreach ($nids as $nid) {
450
- $cnode = node_load($nid);
451
- $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][]['value'] = $cnode->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'];
452
- node_save($node);
453
- $is_missing = TRUE;
454
- foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
455
- if ($value['target_id'] == $node->nid) {
456
- $is_missing = FALSE;
465
+ if (!empty($result['node'])) {
466
+ $nids = array_keys($result['node']);
467
+ foreach ($nids as $nid) {
468
+ $cnode = node_load($nid);
469
+ $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][]['value'] = $cnode->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'];
470
+ node_save($node);
471
+ $is_missing = TRUE;
472
+ foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
473
+ if ($value['target_id'] == $node->nid) {
474
+ $is_missing = FALSE;
475
+ }
476
+ }
477
+ if ($is_missing) {
478
+ $cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE][]['target_id'] = $node->nid;
479
+ node_save($cnode);
457
480
}
458
- }
459
- if ($is_missing) {
460
- $cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE][]['target_id'] = $node->nid;
461
- node_save($cnode);
462
481
}
463
482
}
464
483
return TRUE;
0 commit comments