forked from ffwagency/os2web_fics_esdh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathos2web_fics_esdh.module
154 lines (137 loc) · 4.75 KB
/
os2web_fics_esdh.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @file
* This module implements FICS ESDH backend for use in os2web
*/
include_once('os2web_fics_esdh.features.inc');
include_once('os2web_fics_esdh.settings.inc');
// Default MM settings
define('MM_IMPORT_DIR', 'public://fics/DAG');
define('MM_DEFAULT_APPROVED', '');
define('MM_DEFAULT_CLOSED_BULLET_HANDLING', 'partly_import');
define('MM_CLOSED_STRING', 'Lukket');
define('MM_OPEN_STRING', 'Åben');
define('MM_BPA_BODY_FORMAT', 'os2web_fics_esdh');
define('MM_USE_ALTERNATIVE_FILE_URI_SCHEME', TRUE);
define('MN_DISABLE_PATHAUTO', TRUE);
// This constant / variable should only be set to true in development
// environments! XML files can contain information that should not be
// shared public and should be deleted.
define('MM_KEEP_XML_FILES', variable_get('os2web_fics_esdh_keep_xml_files', FALSE));
// Setting this constant / variable to false will keep enclosure files
// on the server for closed bullets. Notice these enclosures should not
// be shared public!
define('MM_DELETE_FILES_FOR_CLOSED', variable_get('os2web_fics_esdh_delete_files_for_closed', TRUE));
// Setting this constant / variable to TRUE will allow republishing of already
// published meetings without changing the meeting type.
define('MM_REPUBLISH_MEETINGS', variable_get('os2web_fics_esdh_republish_meetings', TRUE));
// Default CP import dir.
define('CP_IMPORT_DIR', 'public://fics/PUBL');
// Default CP destination dir.
define('CP_DESTINATION_DIR', 'public://fics/publ_imported');
// This constant / variable should only be set to true in development
// environments!
define('CP_KEEP_XML_FILES', variable_get('os2web_fics_esdh_cp_keep_xml_files', FALSE));
/**
* Implements hook_ctools_plugin_directory().
*
* Register as provider of ESDH plugins
*/
function os2web_fics_esdh_ctools_plugin_directory($module, $plugin) {
if ($module == 'os2web_esdh_provider') {
return "plugins/$plugin";
}
}
/**
* Implements hook_menu().
*/
function os2web_fics_esdh_menu() {
$items['admin/config/os2web/fics_esdh_cp/import-confirm'] = array(
'title' => 'Confirm re-import',
'access arguments' => array('administer os2web'),
'page callback' => 'drupal_get_form',
'page arguments' => array('_os2web_fics_esdh_cp_import_confirm'),
'type' => MENU_CALLBACK,
'file' => 'os2web_fics_esdh.admin.inc',
);
$items['admin/config/os2web/fics_esdh_cp'] = array(
'title' => 'FICS CP import',
'access arguments' => array('administer os2web'),
'page callback' => '_os2web_fics_esdh_cp_import',
'type' => MENU_LOCAL_TASK,
'file' => 'os2web_fics_esdh.admin.inc',
);
return $items;
}
/**
* Checking if the os2web_case_publishing feature is enabled.
*
* @return bool
*/
function os2web_fics_esdh_cp_enabled() {
return module_exists('os2web_case_publishing');
}
/**
* Implements hook_node_delete().
*/
function os2web_fics_esdh_node_delete($node) {
if ($node->type == 'os2web_case_publishing_case') {
// Delete documents from case.
$items = array_shift($node->field_os2web_case_documents);
if (is_array($items)) {
foreach ($items as $nids) {
node_delete($nids['target_id']);
}
}
}
elseif ($node->type == 'os2web_case_publishing_document') {
if (!empty($node->field_os2web_case_document_file[LANGUAGE_NONE][0]['fid'])) {
$file = file_load($node->field_os2web_case_document_file[LANGUAGE_NONE][0]['fid']);
if (is_object($file)) {
file_delete($file, TRUE);
}
}
}
}
/**
* Implemets hook_cron().
*/
function os2web_fics_esdh_cron() {
module_load_include('inc', 'os2web_fics_esdh', 'os2web_fics_esdh.cp');
$queue = DrupalQueue::get('os2web_fics_esdh_cp_import');
if ($queue->numberOfItems() == 0) {
$current_timestamp = time();
$last_import_time = variable_get('os2web_fics_esdh_cp_last_import', 0);
$documents = os2web_fics_esdh_cp_read_dir();
foreach ($documents as $document) {
// Only import files newer than last cron job.
if (!$last_import_time || filemtime($document) > $last_import_time) {
$queue->createItem(array('document' => $document));
}
}
$queue->createItem(array('post_import_process' => TRUE));
variable_set('os2web_fics_esdh_cp_last_import', $current_timestamp);
}
}
/**
* Implements hook_cron_queue_info().
*/
function os2web_fics_esdh_cron_queue_info() {
$queues['os2web_fics_esdh_cp_import'] = array(
'worker callback' => '_os2web_fics_esdh_cron_queue_worker',
'time' => 30,
);
return $queues;
}
/**
* Worker function for a single import.
*
* @param array $args
* Document data for the import.
*/
function _os2web_fics_esdh_cron_queue_worker($args) {
if (isset($args['document'])) {
module_load_include('inc', 'os2web_fics_esdh', 'os2web_fics_esdh.cp');
_os2web_esdh_fics_cp_import_document($args['document']);
}
}