Merge pull request #20251 from larssandergreen/change-registration-button-text
[civicrm-core.git] / Civi / Api4 / Generic / BasicBatchAction.php
index d1787bd44a127ca9ee3208c571a9cdfccbd28596..bc3d6a51e6a3f91c5be4f3d8461fad4daf84dc8d 100644 (file)
  +--------------------------------------------------------------------+
  */
 
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-
-
 namespace Civi\Api4\Generic;
 
 use Civi\API\Exception\NotImplementedException;
+use Civi\API\Exception\UnauthorizedException;
+use Civi\Api4\Utils\CoreUtil;
 
 /**
  * $ACTION one or more $ENTITIES.
@@ -48,13 +43,19 @@ class BasicBatchAction extends AbstractBatchAction {
    *
    * @param string $entityName
    * @param string $actionName
-   * @param string|array $select
-   *   One or more fields to select from each matching item.
    * @param callable $doer
    */
-  public function __construct($entityName, $actionName, $select = 'id', $doer = NULL) {
-    parent::__construct($entityName, $actionName, $select);
+  public function __construct($entityName, $actionName, $doer = NULL) {
+    parent::__construct($entityName, $actionName);
     $this->doer = $doer;
+    // Accept doer as 4th param for now, but emit deprecated warning
+    $this->doer = func_get_args()[3] ?? NULL;
+    if ($this->doer) {
+      \CRM_Core_Error::deprecatedWarning(__CLASS__ . ' constructor received $doer as 4th param; it should be the 3rd as the $select param has been removed');
+    }
+    else {
+      $this->doer = $doer;
+    }
   }
 
   /**
@@ -65,6 +66,9 @@ class BasicBatchAction extends AbstractBatchAction {
    */
   public function _run(Result $result) {
     foreach ($this->getBatchRecords() as $item) {
+      if ($this->checkPermissions && !CoreUtil::checkAccessRecord($this, $item, \CRM_Core_Session::getLoggedInContactID() ?: 0)) {
+        throw new UnauthorizedException("ACL check failed");
+      }
       $result[] = $this->doTask($item);
     }
   }