-
Notifications
You must be signed in to change notification settings - Fork 10
/
icg_csv_import.module
120 lines (104 loc) · 3.3 KB
/
icg_csv_import.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
<?php
/**
* Include batch.inc when module loads. Required for batch processing!
*/
function icg_csv_import_init( ) {
module_load_include('inc', 'icg_csv_import', 'includes/batch');
// Turn on error reporting.
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// Explicitly set auto detection of line endings by PHP!
ini_set('auto_detect_line_endings', TRUE);
}
/**
* ICG CSV Import Menu
*
* @return array
*/
function icg_csv_import_menu() {
$items = array();
$items['islandora/object/%islandora_object/manage/csv-import'] = array(
'title' => t('CSV Import'),
'page callback' => 'drupal_get_form',
'page arguments' => array('icg_csv_import_form', 2),
'access arguments' => array(2),
'access callback' => 'icg_csv_access_callback',
'file' => 'includes/batch_form.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* ICG CSV Menu Item Access Callback
*/
function icg_csv_access_callback($object) {
if (user_access('ingest fedora objects')) {
$relation = '';
$collection_models = islandora_basic_collection_get_collection_content_models();
$collection_predicates = array(
'isMemberOfCollection',
'isMemberOf',
);
$is_a_collection = count(array_intersect($collection_models, $object->models)) > 0;
return $is_a_collection;
}
return FALSE;
}
/**
* Implements hook_fetch_CSV_defaults.
*
function icg_csv_import_fetch_CSV_defaults( ) {
$path = drupal_get_path('module', 'icg_csv_import');
$array = array(
'label_field' => '/mods/titleInfo/title',
'transform' => $path . '/tests/data/mods_to_dc.xsl',
);
return $array;
}
*/
/**
* Implements hook_fetch_OBJ.
*
function icg_csv_import_fetch_OBJ($path, $credentials) {
$ftp_username = $credentials['username'];
$ftp_userpass = $credentials['password'];
$module_name = basename(__FILE__, '.module');
// Explode the $path... should be of the form server:/dir1/dir2/dir3/filename.ext
list($server, $rest) = explode(':', $path, 2);
$parts = pathinfo($rest);
$ftp_directory = $parts['dirname'];
$filename = $parts['basename'];
// Set up a basic connection.
$conn_id = ftp_ssl_connect($server, 21, 180);
if (!$conn_id) {
watchdog($module_name, "FTP connection to server '%server' failed!", array('%server' => $server), WATCHDOG_ERROR);
return FALSE;
}
// Login with the specified FTP username and password.
$login_result = ftp_login($conn_id, $ftp_username, $ftp_userpass);
if (!$login_result) {
watchdog($module_name, "FTP login failed!", array( ), WATCHDOG_ERROR);
return FALSE;
}
// Set FTP to passive mode.
ftp_pasv($conn_id, TRUE);
// Attempt to change the remote directory as specified.
$change_dir = ftp_chdir($conn_id, $ftp_directory);
if (!$change_dir) {
watchdog($module_name, "FTP chdir to '%directory' failed!", array('%directory' => $ftp_directory), WATCHDOG_ERROR);
die("ftp_chdir failed!");
return FALSE;
} else {
$txt = "Current directory is: " . ftp_pwd($conn_id);
watchdog($module_name, $txt, array( ), WATCHDOG_INFO);
}
// Fetch a file via FTP.
$temp_file = drupal_tempnam('temporary://', 'import_content_'); // open a temp file
if (!ftp_get($conn_id, $temp_file, $filename, FTP_BINARY)) {
watchdog($module_name, "Could not download file '%filename' via FTP.", array('%filename' => $filename), WATCHDOG_ERROR);
return FALSE;
}
return $temp_file;
}
*/