Skip to content
Permalink
Browse files

- Moved non management emails to BCC in all email communication.

- Improved visualization of dashboards (column and row ordering, added extra default column).
- Fixed cron bottleneck. The Labdoo general cron job had become a bottleneck (as Labdoo project has grown), which from time to time (about once a week) was severely slowing down the server performance. This fix moves high computational tasks (dashboard generation) out of the general cron job and schedules it in a separate time slot to ensure it does interfere with critical housekeeping tasks.
- Implemented function fix_laptop_collision() to fix laptop collisions.
- Improved text in automatic email responses for various languages.
- Improved code to automatically link dootronics and dootrips.
- Some modifications for GDPR compliance (these code changes were made prior to the GDPR deadline but were not committed to the repo yet).
- Some additional functions to extract Labdoo statistics (used to help student David in Germany to do his research).
  • Loading branch information...
jrosgiralt committed Nov 4, 2018
1 parent cf4afa1 commit 7f4229cc523834e880abc7db71a6561868bed758
@@ -821,23 +821,50 @@ function labdoo_render_photo_album_header() {
}


/**
* Verifies if this user can be CC-ed instead of BCC-ed in email communications
*
* @param user The user object
*
* @return True if the user can be CC-ed, false otherwise
*
*/
function _user_can_be_cced($user) {
$userRoles = array_values($user->roles);
if(in_array('superhub manager', $userRoles) ||
in_array('edoovillage manager', $userRoles) ||
in_array('hub manager', $userRoles)) {
return True;
}

return False;
}


/**
* Generates a comma-separated list of emails that need
* to be notified upon a change of status of a dooject
*
* @param node The dooject's node
* @param canCC Set to true if we only want the list of emails that can be openly CC-ed instead of BCC-ed
*
*/
function labdoo_dooject_extract_emails($node) {
function labdoo_dooject_extract_emails($node, $canCC=False) {
$emailsList = "";
$emailsListCC = ""; // Emails that can be CC-ed (instead of BCC-ed)
$emailSet = array();

if($node->field_tagger) {
foreach(field_get_items('node', $node, 'field_tagger') as $element) {
$userObj = user_load($element['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
@@ -847,7 +874,12 @@ function labdoo_dooject_extract_emails($node) {
$userObj = user_load($element['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
@@ -858,7 +890,12 @@ function labdoo_dooject_extract_emails($node) {
$userObj = user_load($element['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
@@ -884,7 +921,12 @@ function labdoo_dooject_extract_emails($node) {
$userObj = user_load($element2['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
@@ -893,7 +935,12 @@ function labdoo_dooject_extract_emails($node) {
$userObj = user_load($element2['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
@@ -918,12 +965,22 @@ function labdoo_dooject_extract_emails($node) {
$userObj = user_load($element2['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}
}
}
}

if ($canCC) {
// Return the list of emails that can be CCed instead
$emailsList = $emailsListCC;
}

$emailsList = $emailsList . ", " . variable_get('site_mail', '');

@@ -942,15 +999,21 @@ function labdoo_dooject_extract_emails($node) {
* The dooject's node
*
*/
function labdoo_dootrip_extract_emails($node) {
function labdoo_dootrip_extract_emails($node, $canCC=False) {
$emailsList = "";
$emailsListCC = ""; // Emails that can be CC-ed (instead of BCC-ed)
$emailSet = array();

foreach(field_get_items('node', $node, 'field_dootripper_s_') as $element) {
$userObj = user_load($element['target_id']);
if(in_array($userObj->mail, $emailSet))
continue;
$emailsList = $emailsList . ", " . $userObj->mail;
if(_user_can_be_cced($userObj)) {
$emailsListCC = $emailsListCC . ", " . $userObj->mail;
}
else {
$emailsList = $emailsList . ", " . $userObj->mail;
}
array_push($emailSet, $userObj->mail);
}

@@ -963,6 +1026,11 @@ function labdoo_dootrip_extract_emails($node) {
}
}

if ($canCC) {
// Return the list of emails that can be CCed instead
$emailsList = $emailsListCC;
}

$emailsList = $emailsList . ", " . variable_get('site_mail', '');

if($emailsList[0] == ",")
@@ -1171,6 +1239,8 @@ function lbd_lock_acquire($lock_name) {
*
*/
function lbd_lock_release($lock_name) {
// Put a throtle here, waiting a certain amount X of time
// if the last call to this function happened within Y seconds.
lock_release($lock_name);
}

@@ -2425,6 +2495,21 @@ function labdoo_lib_node_view($node, $view_mode) {
global $language;
global $user;

// Temporary code to deal with GDPR
// If user not re-registered to newsletter, send friendly reminder
// if(user_is_logged_in()) {
// $query = "SELECT COUNT(*) FROM simplenews_subscription WHERE status=1 AND
// snid IN (SELECT snid FROM simplenews_subscriber WHERE uid=$user->uid)";
// $news_activated = db_query($query)->fetchField();
// if ($news_activated == 0)
// labdoo_lib_msg_info(t("We'd love to continue this journey with you!
// Due to GDPR compliance, we need to get your consent to continue sending you
// the Labdoo newsletter. Please go to the <a href=\"../newsletters\">Newsletter dashboard</a>
// to manage your subscriptions. Not subscribing again will mean we won't be able to send
// you anymore newsletters explaining all the wornderful Labdoo humanitarian stories
// occuring around the world."));
// }

$path = drupal_get_path_alias(current_path());

// TODO DE-COLORBOX: temporary fix. This forces a redirect of all photo galleries in German language
@@ -2868,7 +2953,7 @@ function labdoo_render_language_switch() {
$blockLanguage = module_invoke('lang_dropdown', 'block_view', 'language');
$languageSwitchCode = render($blockLanguage["content"]);
$languageSwitchCode = str_replace("<form ", "<form style='height:10px' ", $languageSwitchCode);
$code = "<table><tr><td>$languageSwitchCode</td></tr><tr><td>"._render_addtoany()."</td></tr></table>" . "<br/>";
$code = "<table><tr><td>$languageSwitchCode</td></tr></table>" . "<br/>";
return($code);
}

@@ -2972,7 +3057,7 @@ function labdoo_render_footer() {
$langCode = "/" . $language->language;

// Compute footer links (TODO: factor out this code into a function)
$path = explode('/', drupal_get_normal_path('content/labdoos-terms-and-conditions'));
$path = explode('/', drupal_get_normal_path('content/labdoos-terms-conditions-and-data-protection'));
$urlTerms = '"'.$langCode.'/wiki-index?field_book_language_value=All&field_reference_book_target_id='.$path[1].'"';
$path = explode('/', drupal_get_normal_path('content/source-code-development-team'));
$urlDev = '"'.$langCode.'/wiki-index?field_book_language_value=All&field_reference_book_target_id='.$path[1].'"';
@@ -4846,3 +4931,135 @@ function video_filter_youtube_html5_nocookie($video) {
return video_filter_iframe($video);
}


/**
* Supporting function to reset some fields in
* the configuration of the EU cookie compliance module
*
*/
function labdoo_lib_reset_cookie_compliance() {
$default_filter_format = filter_default_format();
if ($default_filter_format == 'filtered_html') {
$default_filter_format = 'full_html';
}
$popup_settings = variable_get('eu_cookie_compliance', array());
labdoo_lib_print_array($popup_settings);
$popup_settings['popup_info'] = array(
'value' => '<h2>We use cookies on this site to enhance your user experience</h2><p>By clicking any link on this page you are giving your consent for us to set cookies.</p>',
'format' => $default_filter_format,
);
$popup_settings['popup_agreed'] = array(
'value' => '<h2>Thank you for accepting cookies</h2><p>You can now hide this message or find out more about cookies.</p>',
'format' => $default_filter_format,
);
labdoo_lib_print_array($popup_settings);
// Enable this line to really apply changes
// variable_set('eu_cookie_compliance', $popup_settings);
}


/**
* This function can be used to fix laptop collisions.
*
* Example:
* drush php-eval "fix_laptop_collision(58491, \"000014309\");"
*
*/
function fix_laptop_collision($nid, $laptopId) {
$myCreated = db_query("SELECT created from node WHERE nid=:nodeid", array(":nodeid" => $nid))->fetchField();
$dootronics = db_query("SELECT nid,created from node WHERE type='laptop' AND title=:title", array(":title"=> $laptopId));
$iAmOldest = true;
$numberDootronics = 0;

foreach($dootronics as $dootronic) {
$numberDootronics = $numberDootronics + 1;
if ($dootronic->nid == $nid)
continue;
// If we are here, it means there is another node different than us that has the same ID (collision).
// Find out if we are the oldest node.
if ($dootronic->created < $myCreated) {
$iAmOldest = false;
}
}
if ($numberDootronics > 1 && $iAmOldest) {
print("I am oldest node");
// Find out if the previous or next IDs are available
$laptopIdPrev = strval(intval($laptopId) - 1);
$laptopIdNext = strval(intval($laptopId) + 1);
$laptopIdNew = 0;
if (db_query("SELECT COUNT(*) from node WHERE type='laptop' AND title=:title", array(":title"=> $laptopIdNext))->fetchField() == 0) {
print ("Found ID\n");
$laptopIdNew = $laptopIdNext;
}
else if(db_query("SELECT COUNT(*) from node WHERE type='laptop' AND title=:title", array(":title"=> $laptopIdPrev))->fetchField() == 0) {
$laptopIdNew = $laptopIdPrev;
}
print("New ID: " . $laptopIdNew);
if($laptopIdNew != 0) {
print("\nSetting ID");
$dootronicNode = node_load($nid);
$dootronicNode->title = sprintf("%09d", $laptopIdNew);
node_save($dootronicNode);
// Delete all aliases and create a new one
$path = path_load(array('source' => 'node/'.$nid));
path_delete($path['pid']);
$pathAlias = 'laptop/' . $dootronicNode->title;
$path = array('source' => "node/$nid", 'alias' => $pathAlias);
path_save($path);
}
}
}


function labdoo_lib_dootronics_donated_per_country($type) {
$query = "SELECT lid FROM location_instance WHERE vid IN (SELECT MIN(vid) FROM node WHERE nid IN
(SELECT entity_id FROM field_data_field_device_type WHERE field_device_type_value='$type') GROUP BY nid)";
$lids = db_query($query);
$countries = array();
foreach($lids as $lid) {
$query = "SELECT country FROM location WHERE lid=" . $lid->lid;
$country = db_query($query)->fetchField();
if (!array_key_exists($country, $countries))
$countries[$country] = 1;
else
$countries[$country]++;
}
asort($countries);
labdoo_lib_print_array($countries);
return;
}


function labdoo_lib_dootronics_received_per_country($type) {
$query = "SELECT lid FROM location_instance WHERE vid IN (SELECT MAX(vid) FROM node WHERE nid IN
(SELECT entity_id FROM field_data_field_status WHERE field_status_value='S4') AND nid IN
(SELECT entity_id FROM field_data_field_device_type WHERE field_device_type_value='$type') GROUP BY nid)";
$lids = db_query($query);
$countries = array();
foreach($lids as $lid) {
$query = "SELECT country FROM location WHERE lid=" . $lid->lid;
$country = db_query($query)->fetchField();
if (!array_key_exists($country, $countries))
$countries[$country] = 1;
else
$countries[$country]++;
}
asort($countries);
labdoo_lib_print_array($countries);
return;
}


function labdoo_lib_dootrips_total_kms() {
$totalKms = 0;

$query = "SELECT nid, vid FROM node WHERE type='dootrip'";
$dootrips = db_query($query);
foreach($dootrips as $dootrip) {
$dootripNode = node_load($dootrip->nid);
$totalKms = $totalKms + _calculate_dootrip_distance($dootripNode);
}

return($totalKms);
}

0 comments on commit 7f4229c

Please sign in to comment.
You can’t perform that action at this time.