Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash the whole SearchKit UI if one entity fails #25433

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions ext/search_kit/Civi/Search/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Civi\Search;

use Civi\Api4\Action\SearchDisplay\AbstractRunAction;
use Civi\Api4\Entity;
use Civi\Api4\Extension;
use Civi\Api4\Query\SqlEquation;
use Civi\Api4\Query\SqlFunction;
Expand All @@ -30,6 +31,7 @@ class Admin {
* Returns clientside data needed for the `crmSearchAdmin` Angular module.
*
* @return array
* @throws \CRM_Core_Exception
*/
public static function getAdminSettings():array {
$schema = self::getSchema();
Expand Down Expand Up @@ -119,10 +121,11 @@ public static function getStyles():array {
* Fetch all entities the current user has permission to `get`.
*
* @return array[]
* @throws \CRM_Core_Exception
*/
public static function getSchema(): array {
$schema = [];
$entities = \Civi\Api4\Entity::get()
$entities = Entity::get()
->addSelect('name', 'title', 'title_plural', 'bridge_title', 'type', 'primary_key', 'description', 'label_field', 'icon', 'dao', 'bridge', 'ui_join_filters', 'searchable', 'order_by')
->addWhere('searchable', '!=', 'none')
->addOrderBy('title_plural')
Expand All @@ -141,11 +144,17 @@ public static function getSchema(): array {
if (!empty($paths['add'])) {
$entity['addPath'] = $paths['add'];
}
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'],
'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]],
'orderBy' => ['label'],
]);
try {
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'],
'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]],
'orderBy' => ['label'],
]);
}
catch (\CRM_Core_Exception $e) {
\Civi::log()->warning('Entity could not be loaded', ['entity' => $entity['name']]);
continue;
}
foreach ($getFields as $field) {
$field['fieldName'] = $field['name'];
// Hack for RelationshipCache to make Relationship fields editable
Expand Down Expand Up @@ -408,7 +417,11 @@ private static function getJoinConditions(string $nearCol, string $farCol, strin
*
* @param string $alias
* @param array ...$entities
*
* @return array
*
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
private static function getJoinDefaults(string $alias, ...$entities):array {
$conditions = [];
Expand Down