From 16a5da6549e6076dfdcecffe6234456332cf02cc Mon Sep 17 00:00:00 2001 From: Greg Garvey Date: Thu, 1 Sep 2016 16:51:32 -0700 Subject: [PATCH 1/6] added logic for invalidating image timestamp when a mapper is updated --- stanford_capx.forms.inc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/stanford_capx.forms.inc b/stanford_capx.forms.inc index b5815119..1eb77d1a 100644 --- a/stanford_capx.forms.inc +++ b/stanford_capx.forms.inc @@ -1021,6 +1021,39 @@ function stanford_capx_mapper_form_submit($form, $form_state) { else { CAPx::invalidateEtags("mapper", $mapper); drupal_set_message(t("Your mapping has been updated."), 'status', FALSE); + // 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)) { + $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); + } + } + } } // Do the save. From 2ceadc7686653d873712d28db5b0ebeebb30f9b3 Mon Sep 17 00:00:00 2001 From: Greg Garvey Date: Tue, 6 Sep 2016 09:30:16 -0700 Subject: [PATCH 2/6] moved functionality into class --- includes/CAPx/Drupal/Util/CAPx.php | 42 ++++++++++++++++++++++++++++++ stanford_capx.forms.inc | 34 +++--------------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index 13c8b07f..024ca6a5 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -364,6 +364,48 @@ public static function invalidateEtags($type, $object) { ->execute(); } + + /** + * 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 $object + * importers acquired using CAPxImporter::loadImportersByMapper($mapper); + */ + public static function invalidateTimestamp($importers) { + dpm('invalidateTimestamp'); + $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 1eb77d1a..5d348082 100644 --- a/stanford_capx.forms.inc +++ b/stanford_capx.forms.inc @@ -1020,40 +1020,12 @@ function stanford_capx_mapper_form_submit($form, $form_state) { } else { CAPx::invalidateEtags("mapper", $mapper); - drupal_set_message(t("Your mapping has been updated."), 'status', FALSE); // 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)) { - $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); - } - } - } + CAPx::invalidateTimestamp($importers); + } + drupal_set_message(t("Your mapping has been updated."), 'status', FALSE); } // Do the save. From b18c2dcfe24119b9c0d5615e4c8630342ecda2b2 Mon Sep 17 00:00:00 2001 From: Greg Garvey Date: Tue, 6 Sep 2016 10:34:59 -0700 Subject: [PATCH 3/6] removed debug --- includes/CAPx/Drupal/Util/CAPx.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index 024ca6a5..d446c315 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -375,7 +375,6 @@ public static function invalidateEtags($type, $object) { * importers acquired using CAPxImporter::loadImportersByMapper($mapper); */ public static function invalidateTimestamp($importers) { - dpm('invalidateTimestamp'); $importer_machine_names = array(); foreach ($importers as $importer) { $importer_machine_names[] = $importer->machine_name; From 35125831703772be2f177a64f9a1a4f2ce1b08b8 Mon Sep 17 00:00:00 2001 From: Greg Garvey Date: Thu, 8 Sep 2016 11:28:40 -0700 Subject: [PATCH 4/6] clearing the drupal queue on mapper config changes --- includes/CAPx/Drupal/Util/CAPx.php | 11 +++++++++++ stanford_capx.forms.inc | 1 + 2 files changed, 12 insertions(+) diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index d446c315..185999c9 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -365,6 +365,17 @@ 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($importers) { + $queue = \DrupalQueue::get('stanford_capx_profiles', TRUE); + $queue->deleteQueue(); + } + /** * Invalidates profile photo timestamp by importer. * diff --git a/stanford_capx.forms.inc b/stanford_capx.forms.inc index 5d348082..0890b1c6 100644 --- a/stanford_capx.forms.inc +++ b/stanford_capx.forms.inc @@ -1023,6 +1023,7 @@ function stanford_capx_mapper_form_submit($form, $form_state) { // 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); From 2ea4110f1138df875301633586602d1b87f6a8d1 Mon Sep 17 00:00:00 2001 From: Greg Garvey Date: Thu, 8 Sep 2016 11:52:51 -0700 Subject: [PATCH 5/6] removed unnecessary argument --- includes/CAPx/Drupal/Util/CAPx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index 185999c9..1118e897 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -371,7 +371,7 @@ public static function invalidateEtags($type, $object) { * If you need to clear the queue because of config changes, this is your method. * */ - public static function clearTheQueue($importers) { + public static function clearTheQueue() { $queue = \DrupalQueue::get('stanford_capx_profiles', TRUE); $queue->deleteQueue(); } From edda64a8c6e798702b6216ad5bf3697f4403a744 Mon Sep 17 00:00:00 2001 From: Shea McKinney Date: Thu, 8 Sep 2016 16:56:10 -0700 Subject: [PATCH 6/6] Couple of formatting fixes --- includes/CAPx/Drupal/Util/CAPx.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/CAPx/Drupal/Util/CAPx.php b/includes/CAPx/Drupal/Util/CAPx.php index 1118e897..17b79640 100644 --- a/includes/CAPx/Drupal/Util/CAPx.php +++ b/includes/CAPx/Drupal/Util/CAPx.php @@ -364,26 +364,25 @@ public static function invalidateEtags($type, $object) { ->execute(); } - + /** * 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 $object - * importers acquired using CAPxImporter::loadImportersByMapper($mapper); + * @param object $importers + * Importers acquired using CAPxImporter::loadImportersByMapper($mapper); */ public static function invalidateTimestamp($importers) { $importer_machine_names = array();