Skip to content

Commit 0656924

Browse files
author
MathiasGajhede
committed
Merge pull request #1 from syddjurs/master
Hotfix 1.0.7 and all fixes before.
2 parents 48916c3 + 00509b4 commit 0656924

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

os2web_cp_service.drush.inc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function os2web_cp_service_drush_command() {
1616
'aliases' => array('cp-up'),
1717
);
1818
$items['cp-cleanup'] = array(
19-
'description' => 'Delete all refenreces which are broken to a Stub.',
19+
'description' => 'Delete all documents with a broken reference.',
2020
'arguments' => array(),
2121
'aliases' => array('cp-cl'),
2222
);
@@ -64,17 +64,17 @@ function drush_os2web_cp_service_cp_update_ref() {
6464
*/
6565
function drush_os2web_cp_service_cp_cleanup() {
6666

67+
// Find all documents which has no references from a case.
6768
$nodes = db_query("SELECT *
68-
FROM node n
69-
WHERE n.type = 'os2web_cp_service_cp_document'
70-
AND n.title = 'Stub'
71-
AND n.nid IN (
72-
SELECT field_os2web_cp_service_doc_ref_target_id
73-
FROM field_data_field_os2web_cp_service_doc_ref
74-
)");
69+
FROM node n
70+
WHERE n.type = 'os2web_cp_service_cp_document'
71+
AND n.nid NOT IN (
72+
SELECT field_os2web_cp_service_doc_ref_target_id
73+
FROM field_data_field_os2web_cp_service_doc_ref
74+
)");
7575

7676
foreach ($nodes as $node) {
7777
node_delete($node->nid);
78-
drush_log(t('Deleted stub: :node', array(':node' => $node->nid)), 'success');
78+
drush_log(t('Deleted document: !node', array('!node' => $node->nid)), 'success');
7979
}
8080
}

os2web_cp_service.module

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ function os2web_gf_service_handler($file_id) {
7373
'application/vnd.ms-outlook',
7474
);
7575

76+
$disallowed_mimes = array_merge($disallowed_mimes, explode(',', variable_get('os2web_cp_service_disallow_mimes', '')));
77+
$case_exceptions = explode(',', variable_get('os2web_cp_service_disallow_mimes_exceptions', ''));
78+
7679
if ($url = variable_get('os2web_cp_service_cp_document_fileurl')) {
7780

7881
$username = variable_get('os2web_cp_service_endpoint_user');
@@ -87,7 +90,22 @@ function os2web_gf_service_handler($file_id) {
8790
$header = curl_getinfo($ch);
8891
curl_close($ch);
8992
if ($header['http_code'] === 200) {
90-
if (!in_array($header['content_type'], $disallowed_mimes)) {
93+
// Load the title to use it as the filename, and for conditions.
94+
$query = new EntityFieldQuery();
95+
$result = $query
96+
->entityCondition('entity_type', 'node')
97+
->propertyCondition('type', 'os2web_cp_service_cp_document')
98+
->propertyCondition('status', 1)
99+
->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
100+
->execute();
101+
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
102+
103+
$node = node_load(array_pop($nids));
104+
$case_id = NULL;
105+
if ($node) {
106+
$case_id = $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'];
107+
}
108+
if (!in_array($header['content_type'], $disallowed_mimes) || ($case_id && in_array($case_id, $case_exceptions))) {
91109
drupal_add_http_header('Content-Type', $header['content_type']);
92110
drupal_add_http_header('Content-Length', $header['download_content_length']);
93111
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
@@ -103,22 +121,12 @@ function os2web_gf_service_handler($file_id) {
103121
drupal_add_http_header('Pragma', 'no-cache');
104122
}
105123

106-
// Load the title to use it as the filename.
107-
$query = new EntityFieldQuery();
108-
$result = $query
109-
->entityCondition('entity_type', 'node')
110-
->propertyCondition('type', 'os2web_cp_service_cp_document')
111-
->propertyCondition('status', 1)
112-
->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
113-
->execute();
114-
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
115-
116-
$node = node_load(array_pop($nids));
117-
124+
$filename = str_replace('/', '_', $file_id . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
118125
if ($node) {
126+
// If we can find the doc in DB, give it a real name.
119127
$filename = str_replace('/', '_', $node->field_os2web_cp_service_doc_id[LANGUAGE_NONE][0]['value'] . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
120-
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
121128
}
129+
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
122130
echo $data;
123131
drupal_exit();
124132
}
@@ -319,13 +327,6 @@ function os2web_cp_service_create_case(array $data) {
319327
node_submit($node);
320328
node_save($node);
321329

322-
// Trigger a cache reload by calling the URL for the node.
323-
$cache_trigger = curl_init(url('sag/' . $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'], array('absolute' => TRUE)));
324-
// Stop the call after 1 sec. Dont care about the response.
325-
curl_setopt($cache_trigger, CURLOPT_TIMEOUT, 1);
326-
curl_exec($cache_trigger);
327-
curl_close($cache_trigger);
328-
329330
return TRUE;
330331
}
331332
catch (Exception $e) {
@@ -643,7 +644,6 @@ function os2web_cp_service_delete($guid) {
643644
$query = new EntityFieldQuery();
644645
$result = $query
645646
->entityCondition('entity_type', 'node')
646-
->propertyCondition('status', 1)
647647
->fieldCondition('field_os2web_cp_service_key', 'value', $guid, '=')
648648
->execute();
649649
$nids = (isset($result['node']))?array_keys($result['node']) : array();
@@ -674,20 +674,21 @@ function os2web_cp_service_node_delete($node) {
674674
$result = $query
675675
->entityCondition('entity_type', 'node')
676676
->propertyCondition('type', 'os2web_cp_service_cp_case')
677-
->propertyCondition('status', 1)
678677
->fieldCondition('field_os2web_cp_service_doc_ref', 'target_id', $node->nid, '=')
679678
->execute();
680-
$nids = array_keys($result['node']);
681-
$new_nids = array();
682-
foreach ($nids as $nid) {
683-
$cnode = node_load($nid);
684-
foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
685-
if ($value['target_id'] != $node->nid) {
686-
$new_nids[] = $value;
679+
if (!empty($result['node'])) {
680+
$nids = array_keys($result['node']);
681+
$new_nids = array();
682+
foreach ($nids as $nid) {
683+
$cnode = node_load($nid);
684+
foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
685+
if ($value['target_id'] != $node->nid) {
686+
$new_nids[] = $value;
687+
}
687688
}
689+
$cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] = $new_nids;
690+
node_save($cnode);
688691
}
689-
$cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] = $new_nids;
690-
node_save($cnode);
691692
}
692693
}
693694
}
@@ -879,6 +880,18 @@ function os2web_cp_service_form_os2web_settings_settings_form_alter(&$form, &$fo
879880
'#description' => 'Vises når den modtagede filtype ikke er godkendt til Download.',
880881
'#default_value' => variable_get('os2web_cp_service_access_denied_message'),
881882
);
883+
$form['os2web_cp_service_config_group']['os2web_cp_service_disallow_mimes'] = array(
884+
'#type' => 'textfield',
885+
'#title' => 'Filers MIME type, som ikke må downloades af brugere.',
886+
'#description' => 'Tillad kun filer som ikke har disse mimes. Seperer mimes med komma. Standard:.msg',
887+
'#default_value' => variable_get('os2web_cp_service_disallow_mimes'),
888+
);
889+
$form['os2web_cp_service_config_group']['os2web_cp_service_disallow_mimes_exceptions'] = array(
890+
'#type' => 'textfield',
891+
'#title' => 'Sager hvor ALLE mimes er tilladt.',
892+
'#description' => 'Tillad brugere at hente ALLE mime typer på angivende sager. Seperer sager med komma.',
893+
'#default_value' => variable_get('os2web_cp_service_disallow_mimes_exceptions'),
894+
);
882895
}
883896

884897
/**

0 commit comments

Comments
 (0)