diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index 13c8b07f..17b79640 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -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. * diff --git a/stanford_capx.forms.inc b/stanford_capx.forms.inc index b5815119..0890b1c6 100644 --- a/stanford_capx.forms.inc +++ b/stanford_capx.forms.inc @@ -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); }