SearchKit - Add task to refresh smart/parent group cache
authorcolemanw <coleman@civicrm.org>
Thu, 1 Jun 2023 15:22:40 +0000 (11:22 -0400)
committercolemanw <coleman@civicrm.org>
Thu, 1 Jun 2023 16:33:23 +0000 (12:33 -0400)
ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
ext/search_kit/ang/crmSearchTasks/crmSearchBatchRunner.component.js
ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.ctrl.js
ext/search_kit/ang/crmSearchTasks/crmSearchTaskApiBatch.html
ext/search_kit/ang/crmSearchTasks/traits/searchTaskBaseTrait.service.js

index 68aaa044f50b5b7515220b6bb052c48ea3f704f4..9676e096d33768db8c350686d4c6ac2073a15731 100644 (file)
@@ -135,6 +135,24 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
       ];
     }
 
+    /*
+     * ENTITY-SPECIFIC TASKS BELOW
+     * FIXME: Move these somewhere?
+     */
+
+    if ($entity['name'] === 'Group') {
+      $tasks['Group']['refresh'] = [
+        'title' => E::ts('Refresh Group Cache'),
+        'icon' => 'fa-refresh',
+        'apiBatch' => [
+          'action' => 'refresh',
+          'runMsg' => E::ts('Refreshing %1 %2...'),
+          'successMsg' => E::ts('%1 %2 Refreshed.'),
+          'errorMsg' => E::ts('An error occurred while attempting to refresh %1 %2.'),
+        ],
+      ];
+    }
+
     if ($entity['name'] === 'Contact') {
       // Add contact tasks which support standalone mode
       $contactTasks = $this->checkPermissions ? \CRM_Contact_Task::permissionedTaskTitles(\CRM_Core_Permission::getPermission()) : NULL;
index 6ccffdacaf9b790d37da397423c775b9760b7d06..0a056f787dc78425705c89c79a6761cafab2a41a 100644 (file)
@@ -17,6 +17,7 @@
         ctrl = this,
         currentBatch = 0,
         totalBatches,
+        processedCount = 0,
         incrementer;
 
       this.progress = 0;
           function(result) {
             stopIncrementer();
             ctrl.progress = Math.floor(100 * ++currentBatch / totalBatches);
+            processedCount += result.count;
             if (ctrl.last >= ctrl.ids.length) {
               $timeout(function() {
+                result.batchCount = processedCount;
                 ctrl.success({result: result});
               }, 500);
             } else {
index cb06c22f534f818f1d42c8f1efd0b1fec168a1e2..b2fc5953742c4347007a49de5585f11b710f744f 100644 (file)
@@ -14,8 +14,9 @@
       ctrl.start(ctrl.apiBatch.params);
     }
 
-    this.onSuccess = function() {
-      CRM.alert(ts(ctrl.apiBatch.successMsg, {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('%1 Complete', {1: ctrl.taskTitle}), 'success');
+    this.onSuccess = function(result) {
+      var entityTitle = this.getEntityTitle(result.batchCount);
+      CRM.alert(ts(ctrl.apiBatch.successMsg, {1: result.batchCount, 2: entityTitle}), ts('%1 Complete', {1: ctrl.taskTitle}), 'success');
       this.close();
     };
 
index a4ce4c5aabbbd958aab94ce1b9a8c99cbc04eee1..6352890efba5f25e71264e60679d2fcad48ddf87 100644 (file)
@@ -4,7 +4,7 @@
     <hr />
     <div ng-if="$ctrl.run" class="crm-search-task-progress">
       <h5>{{:: ts(model.apiBatch.runMsg, {1: model.ids.length, 2: $ctrl.entityTitle}) }}</h5>
-      <crm-search-batch-runner entity="model.entity" action="{{:: model.apiBatch.action }}" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess()" error="$ctrl.onError()" id-field="{{:: $ctrl.entityInfo.primary_key[0] }}"></crm-search-batch-runner>
+      <crm-search-batch-runner entity="model.entity" action="{{:: model.apiBatch.action }}" params="$ctrl.run" ids="model.ids" success="$ctrl.onSuccess(result)" error="$ctrl.onError()" id-field="{{:: $ctrl.entityInfo.primary_key[0] }}"></crm-search-batch-runner>
     </div>
 
     <crm-dialog-button text="ts('Cancel')" icons="{primary: 'fa-times'}" on-click="$ctrl.cancel()" disabled="$ctrl.run" ></crm-dialog-button>
index c6ae0c6ce7bbf3ea7c7937c22b22598bc5a6582f..68149e0f4a3445e585f19d365339b9b721c884b8 100644 (file)
@@ -8,8 +8,11 @@
     // Trait properties get mixed into task controller using angular.extend()
     return {
 
-      getEntityTitle: function() {
-        return this.ids.length === 1 ? this.entityInfo.title : this.entityInfo.title_plural;
+      getEntityTitle: function(count) {
+        if (typeof count !== 'number') {
+          count = this.ids.length;
+        }
+        return count === 1 ? this.entityInfo.title : this.entityInfo.title_plural;
       },
 
       start: function(runParams) {