Skip to content

Commit

Permalink
Merge branch '7.x-2.x' into php54-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sherakama committed Sep 8, 2016
2 parents c5b4650 + 9b0a96c commit c8caa48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
51 changes: 51 additions & 0 deletions includes/CAPx/Drupal/Util/CAPx.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,57 @@ public static function invalidateEtags($type, $object) {

}

/**
* Clears the stanford_capx_profiles queue.
*
* If you need to clear the queue because of config changes, this is your method.
*/
public static function clearTheQueue() {
$queue = \DrupalQueue::get('stanford_capx_profiles', TRUE);
$queue->deleteQueue();
}

/**
* Invalidates profile photo timestamp by importer.
*
* When a mapper changes we need to invalidate the timestamp on the
* profile photos associated with it.
*
* @param object $importers
* Importers acquired using CAPxImporter::loadImportersByMapper($mapper);
*/
public static function invalidateTimestamp($importers) {
$importer_machine_names = array();
foreach ($importers as $importer) {
$importer_machine_names[] = $importer->machine_name;
}
$q = db_select('capx_profiles', 'cp');
$q->addfield('cp', 'entity_id');
$q->condition('cp.importer', $importer_machine_names, 'IN');
$r = $q->execute()->fetchAll();
$profile_ids = array();
if (!empty($r)) {
foreach ($r as $id) {
$profile_ids[] = $id->entity_id;
}
$q = db_select('field_data_field_s_person_profile_picture', 'pp');
$q->addfield('pp', 'field_s_person_profile_picture_fid');
$q->condition('pp.entity_id', $profile_ids, 'IN');
$r = $q->execute()->fetchAll();
$fids = array();
if (!empty($r)) {
foreach ($r as $fid) {
$fids[] = (int) $fid->field_s_person_profile_picture_fid;
}
$q = db_update('file_managed');
$q->fields(array('timestamp' => 0));
$q->condition('fid', $fids, 'IN');
$q->execute();
cache_clear_all('*', 'cache_image', TRUE);
}
}
}

/**
* Remove a profile record.
*
Expand Down
6 changes: 6 additions & 0 deletions stanford_capx.forms.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,12 @@ function stanford_capx_mapper_form_submit($form, $form_state) {
}
else {
CAPx::invalidateEtags("mapper", $mapper);
// Add logic for invalidating timestamp and clearing image cache here so that profile images are updated when mapper is saved with potetially different profile image settings.
$importers = CAPxImporter::loadImportersByMapper($mapper);
if (!empty($importers)) {
CAPx::clearTheQueue();
CAPx::invalidateTimestamp($importers);
}
drupal_set_message(t("Your mapping has been updated."), 'status', FALSE);
}

Expand Down

0 comments on commit c8caa48

Please sign in to comment.