Skip to content

A lot of small fixes from the last year. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ publishing service. Uses Adlib service to convert files to pdf.

Dependencies
-----------
- os2web_adlib_api
- ctools
- features

Configuration
-----------
Expand Down
3 changes: 2 additions & 1 deletion os2web_esdh_provider.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion os2web_esdh_provider.info
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions os2web_esdh_provider.make
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
105 changes: 70 additions & 35 deletions os2web_esdh_provider.mmapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,15 +137,17 @@ function _os2web_esdh_provider_import_meeting($meeting_id, $force = FALSE, &$con
# [email protected] - 2013-04-14 / 2013-04-24

# is the pathauto module loades ?
if (module_exists('pathauto')) {
// Don't create aliases ([email protected])
if (module_exists('pathauto') && !(defined('MN_DISABLE_PATHAUTO') && MN_DISABLE_PATHAUTO)) {

# Loading the path auto modules
module_load_include('inc', 'pathauto', 'pathauto');

# 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(
Expand All @@ -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.
Expand Down Expand Up @@ -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'];
}
}
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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(
Expand All @@ -459,39 +460,68 @@ 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
*
* @return object
* 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;
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -730,4 +765,4 @@ function _os2web_esdh_provider_bpa_body_format() {
}
}
return $cache;
}
}
3 changes: 1 addition & 2 deletions os2web_esdh_provider.module
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down