diff --git a/README.md b/README.md index 3d9fc4d..96407c0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ publishing service. Uses Adlib service to convert files to pdf. Dependencies ----------- -- os2web_adlib_api - ctools +- features Configuration ----------- diff --git a/os2web_esdh_provider.admin.inc b/os2web_esdh_provider.admin.inc index 728b131..0d9ac33 100644 --- a/os2web_esdh_provider.admin.inc +++ b/os2web_esdh_provider.admin.inc @@ -34,6 +34,7 @@ function _os2web_esdh_provider_status() { // Show a table of watchdog entries if the debug flag is on. $watchdog_table = ''; if (variable_get('os2web_esdh_provider_debug_info')) { + $watchdog_rows = array(); $watchdog_messages = db_query('SELECT * FROM {watchdog} w WHERE w.type = :type AND w.severity = :severity ORDER BY w.timestamp DESC', array(':type' => 'acadre MM', ':severity' => WATCHDOG_WARNING)); $watchdog_head = array(t('Warning messages in descending order'), t('Date')); foreach ($watchdog_messages as $row) { @@ -160,7 +161,7 @@ function _os2web_esdh_provider_status_confirm_submit($form, &$form_state) { 'file' => drupal_get_path('module', 'os2web_esdh_provider') . '/os2web_esdh_provider.mmapi.inc', 'init_message' => t('Scanner filer'), ); - $meetings = os2web_esdh_provider_invoke('mm', 'get_import_list'); + $meetings = os2web_esdh_provider_invoke('mm', 'get_import_list', $force, $focus); foreach ($meetings as $meeting) { if (empty($focus) || in_array($meeting['id'], $focus)) { $batch['operations'][] = array( diff --git a/os2web_esdh_provider.info b/os2web_esdh_provider.info index e2adf2a..41fd650 100644 --- a/os2web_esdh_provider.info +++ b/os2web_esdh_provider.info @@ -7,5 +7,4 @@ version = 7.x-1.0-beta1 project = os2web_esdh_provider dependencies[] = ctools dependencies[] = features -dependencies[] = os2web_adlib_api features[features_api][] = api:1 diff --git a/os2web_esdh_provider.make b/os2web_esdh_provider.make index 4463042..a02b733 100644 --- a/os2web_esdh_provider.make +++ b/os2web_esdh_provider.make @@ -16,11 +16,13 @@ core = 7.x # projects[os2web_print_send_to_friend][download][url] = "https://github.com/OS2web/os2web_print_send_to_friend.git" projects[os2web_esdh_field][type] = "module" +projects[os2web_esdh_field][subdir] = contrib projects[os2web_esdh_field][download][type] = "git" projects[os2web_esdh_field][download][branch] = "master" projects[os2web_esdh_field][download][url] = "https://github.com/OS2web/os2web_esdh_field.git" projects[os2web_adlib_api][type] = "module" +projects[os2web_adlib_api][subdir] = contrib projects[os2web_adlib_api][download][type] = "git" projects[os2web_adlib_api][download][branch] = "master" projects[os2web_adlib_api][download][url] = "https://github.com/OS2web/os2web_adlib_api.git" diff --git a/os2web_esdh_provider.mmapi.inc b/os2web_esdh_provider.mmapi.inc index 59aa98d..04cae02 100644 --- a/os2web_esdh_provider.mmapi.inc +++ b/os2web_esdh_provider.mmapi.inc @@ -90,10 +90,8 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con // Meeting already exist. // Either republish, delete or skip. if ($nid) { - - if ($force) { + if ($force || (defined('MM_REPUBLISH_MEETINGS') && MM_REPUBLISH_MEETINGS)) { err_debug('Republish nid: ' . $nid); - $node = node_load($nid); watchdog('acadre MM', 'Using %nid for import.', array('%nid' => $nid), WATCHDOG_DEBUG); } @@ -139,7 +137,8 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con # skifter@bellcom.dk - 2013-04-14 / 2013-04-24 # is the pathauto module loades ? - if (module_exists('pathauto')) { + // Don't create aliases (vitaliy.sekan@propeople.com.ua) + if (module_exists('pathauto') && !(defined('MN_DISABLE_PATHAUTO') && MN_DISABLE_PATHAUTO)) { # Loading the path auto modules module_load_include('inc', 'pathauto', 'pathauto'); @@ -147,7 +146,8 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con # Setting the new title with committee name and meeting date substring $my_date = date_create(substr($meeting['meeting_date_start'], 0,10)); $format = "d-m-Y"; - $node->title = $meeting['committee'] . ' - ' . date_format($my_date,$format); + $committee_name = is_array($meeting['committee']) ? $meeting['committee']['esdh_name'] : $meeting['committee']; + $node->title = $committee_name . ' - ' . date_format($my_date,$format); # adding the alias and setting pathauto to 0 for this content type. otherwise we get 2 aliases. $path_alias = array( @@ -160,8 +160,7 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con $node->path = $path_alias; } - - $node->field_os2web_meetings_abbr[LANGUAGE_NONE][0]['value'] = substr($meeting['description'], 0, 49); + $node->field_os2web_meetings_abbr[LANGUAGE_NONE][0]['value'] = mb_substr($meeting['description'], 0, 49); // If field has a format, you need to define it. Here we define a default filtered_html format for a body field. $node->field_os2web_meetings_abbr[LANGUAGE_NONE][0]['format'] = 'filtered_html'; // The date. @@ -204,11 +203,13 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con } // Delete all bullet points before importing. - $bullets = array_shift($node->field_os2web_meetings_bullets); - if (is_array($bullets)) { - $nids_to_delete = array(); - foreach ($bullets as $nids) { - $nids_to_delete[$nids['target_id']] = $nids['target_id']; + if(property_exists($node,'field_os2web_meetings_bullets') && is_array($node->field_os2web_meetings_bullets)) { + $bullets = array_shift($node->field_os2web_meetings_bullets); + if (is_array($bullets)) { + $nids_to_delete = array(); + foreach ($bullets as $nids) { + $nids_to_delete[$nids['target_id']] = $nids['target_id']; + } } } @@ -414,7 +415,7 @@ function _os2web_esdh_provider_import_file($file_meta) { return FALSE; } - if (file_uri_scheme($uri) != 'public') { + if (!(defined('MM_USE_ALTERNATIVE_FILE_URI_SCHEME') && MM_USE_ALTERNATIVE_FILE_URI_SCHEME) && file_uri_scheme($uri) != 'public') { watchdog('acadre MM', 'Invalid scheme for uri %uri, Possibly absolut path ? ' . $uri, array( '%uri', $uri), WATCHDOG_ERROR); error_log("Var: \$uri = " . print_r($uri, 1)); @@ -443,7 +444,7 @@ function _os2web_esdh_provider_import_file($file_meta) { // Schedule for PDF conversion // $convert = FALSE; // DEBUG. - if ($convert) { + if ($convert && module_exists('os2web_adlib_api')) { drupal_load('module', 'os2web_adlib_api'); os2web_adlib_api_convert_to_pdf($file->fid, $file->filename); watchdog('os2web_adlib_api', 'File %filename (fid: %fid) queued for PDF conversion.', array( @@ -459,8 +460,10 @@ function _os2web_esdh_provider_import_file($file_meta) { /** * Imports a termname into a vacabulary. Does dupe check. * - * @param string $term_name - * Term machine name + * @param mixed $term_name + * Term name, or array containing term name and ESDH ID for + * the term. + * * @param string $vocab * Vocabulary machine name * @@ -468,30 +471,57 @@ function _os2web_esdh_provider_import_file($file_meta) { * Drupal standard Term object */ function _acadre_esdh_import_term($term_name, $vocab) { + // Some MM plugins provide both term name and the ESDH ID for the + // term. The latter makes it possible to handle multiple terms with + // same name and automatically updating of term names based on data + // from the ESDH system. + if (is_array($term_name)) { + $term_esdh_id = $term_name['esdh_id']; + $term_esdh_id_field = $term_name['esdh_id_field']; + $term_name = $term_name['esdh_name']; + } err_debug('Start import term'); // TODO: Process members of the committee. // FIXME: MAke vocab name configurable. $vid = db_select('taxonomy_vocabulary', 'tv') - ->fields('tv', array('vid')) - ->condition('machine_name', $vocab) - ->execute() - ->fetchField(); + ->fields('tv', array('vid')) + ->condition('machine_name', $vocab) + ->execute() + ->fetchField(); $term = new stdClass(); $term->vid = $vid; $term->name = $term_name; - $tid = db_select('taxonomy_term_data', 'td') - ->fields('td', array('tid')) - ->condition('name', $term->name) - ->condition('vid', $term->vid) - ->execute()->fetchObject(); + // Searching for an existing term based on the provided ESDH ID. + if (!empty($term_esdh_id_field) && !empty($term_esdh_id) && $term_esdh_id > 0) { + $term->{$term_esdh_id_field}['und'][0]['value'] = $term_esdh_id; + + $query = new EntityFieldQuery(); + $result = $query->entityCondition('entity_type', 'taxonomy_term') + ->propertyCondition('vid', $vid) + ->fieldCondition($term_esdh_id_field, 'value', $term_esdh_id, '=') + ->execute(); + if (isset($result['taxonomy_term'])) { + $tid = array_shift($result['taxonomy_term']); + } + } + // If no ESDH ID is provided are we falling back and selecting on the + // term name. + else { + $tid = db_select('taxonomy_term_data', 'td') + ->fields('td', array('tid')) + ->condition('name', $term->name) + ->condition('vid', $term->vid) + ->execute()->fetchObject(); + } if (isset($tid->tid) && $tid->tid > 0) { $term->tid = (int) $tid->tid; } + taxonomy_term_save($term); return $term; @@ -564,15 +594,20 @@ function _os2web_esdh_provider_node_tab_page($nid, $op = FALSE) { * Sanetized filename with same extension. */ function _os2web_esdh_provider_sanetize_filename($filename) { - // Replace whitespace. - // $filename = str_replace(' ', '_', $filename); - // Remove remaining unsafe characters. - // $filename = preg_replace('![^0-9A-Za-z_.- ]!', '', $filename); - $filename = preg_replace('![/"]!', '-', $filename); - // Remove multiple consecutive non-alphabetical characters. - $filename = preg_replace('/(_)_+|(\.)\.+|(-)-+/', '\\1\\2\\3', $filename); - // Force lowercase to prevent issues on case-insensitive file systems. - // $filename = strtolower($filename); + if (module_exists('transliteration')) { + $filename = transliteration_clean_filename($filename); + } + else { + // Replace whitespace. + // $filename = str_replace(' ', '_', $filename); + // Remove remaining unsafe characters. + // $filename = preg_replace('![^0-9A-Za-z_.- ]!', '', $filename); + $filename = preg_replace('![/"]!', '-', $filename); + // Remove multiple consecutive non-alphabetical characters. + $filename = preg_replace('/(_)_+|(\.)\.+|(-)-+/', '\\1\\2\\3', $filename); + // Force lowercase to prevent issues on case-insensitive file systems. + // $filename = strtolower($filename); + } $pi = pathinfo($filename); if (isset($pi['extension'])) { return substr(trim($pi['filename']), 0, 160) . '.' . $pi['extension']; @@ -730,4 +765,4 @@ function _os2web_esdh_provider_bpa_body_format() { } } return $cache; -} \ No newline at end of file +} diff --git a/os2web_esdh_provider.module b/os2web_esdh_provider.module index f03fa30..fbbe000 100644 --- a/os2web_esdh_provider.module +++ b/os2web_esdh_provider.module @@ -170,10 +170,9 @@ function os2web_esdh_provider_node_delete($node) { */ function os2web_esdh_provider_cron() { if (os2web_esdh_provider_has_api('mm')) { - $meetings = os2web_esdh_provider_invoke('mm', 'get_import_list'); $queue = DrupalQueue::get('acadre_mm_import'); if ($queue->numberOfItems() == 0) { - + $meetings = os2web_esdh_provider_invoke('mm', 'get_import_list'); $current_timestamp = time(); $last_mm_import_time = variable_get('os2web_esdh_provider_last_mm_import', FALSE);