X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FApi4%2FGeneric%2FDAOGetAction.php;h=2b73f18a8ffb3d33a172cd6cc9f4dc8d516baf0a;hb=fe71a72e510e046d7f21d7064802a15f64c6b957;hp=d922781ada2e049574a2d065aec703437733213e;hpb=8fd77486da8ade32a9cacd6b4669a84836e48ba0;p=civicrm-core.git diff --git a/Civi/Api4/Generic/DAOGetAction.php b/Civi/Api4/Generic/DAOGetAction.php index d922781ada..2b73f18a8f 100644 --- a/Civi/Api4/Generic/DAOGetAction.php +++ b/Civi/Api4/Generic/DAOGetAction.php @@ -71,20 +71,31 @@ class DAOGetAction extends AbstractGetAction { public function _run(Result $result) { $this->setDefaultWhereClause(); $this->expandSelectClauseWildcards(); - $result->exchangeArray($this->getObjects()); + $this->getObjects($result); } /** - * @return array|int + * @param \Civi\Api4\Generic\Result $result */ - protected function getObjects() { - $query = new Api4SelectQuery($this); - - $result = $query->run(); - if (is_array($result)) { - \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($result); + protected function getObjects(Result $result) { + $getCount = in_array('row_count', $this->getSelect()); + $onlyCount = $this->getSelect() === ['row_count']; + + if (!$onlyCount) { + $query = new Api4SelectQuery($this); + $rows = $query->run(); + \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($rows); + $result->exchangeArray($rows); + // No need to fetch count if we got a result set below the limit + if (!$this->getLimit() || count($rows) < $this->getLimit()) { + $result->rowCount = count($rows) + $this->getOffset(); + $getCount = FALSE; + } + } + if ($getCount) { + $query = new Api4SelectQuery($this); + $result->rowCount = $query->getCount(); } - return $result; } /**