When adding/removing custom groups, the schema map changes.
Civi already flushes the metadata cache when this happens,
but the APIv4 SchemaMap was being cached in memory (in a container service).
This changes it to be stored in the metadata cache like everything else.
public function getRecords() {
\CRM_Core_Error::deprecatedWarning('APIv4 Entity::getLinks is deprecated.');
$result = [];
public function getRecords() {
\CRM_Core_Error::deprecatedWarning('APIv4 Entity::getLinks is deprecated.');
$result = [];
- /** @var \Civi\Api4\Service\Schema\SchemaMap $schema */
- $schema = \Civi::container()->get('schema_map');
+ $schema = CoreUtil::getSchemaMap();
foreach ($schema->getTables() as $table) {
$entity = CoreUtil::getApiNameFromTableName($table->getName());
// Since this is an api function, exclude tables that don't have an api
foreach ($schema->getTables() as $table) {
$entity = CoreUtil::getApiNameFromTableName($table->getName());
// Since this is an api function, exclude tables that don't have an api
use Civi\API\Exception\UnauthorizedException;
use Civi\Api4\Service\Schema\Joinable\CustomGroupJoinable;
use Civi\API\Exception\UnauthorizedException;
use Civi\Api4\Service\Schema\Joinable\CustomGroupJoinable;
+use Civi\Api4\Service\Schema\Joiner;
use Civi\Api4\Utils\FormattingUtil;
use Civi\Api4\Utils\CoreUtil;
use Civi\Api4\Utils\SelectUtil;
use Civi\Api4\Utils\FormattingUtil;
use Civi\Api4\Utils\CoreUtil;
use Civi\Api4\Utils\SelectUtil;
if (isset($this->apiFieldSpec[$key])) {
return;
}
if (isset($this->apiFieldSpec[$key])) {
return;
}
- /** @var \Civi\Api4\Service\Schema\Joiner $joiner */
- $joiner = \Civi::container()->get('joiner');
+ $joiner = new Joiner(CoreUtil::getSchemaMap());
$pathArray = explode('.', $key);
// The last item in the path is the field name. We don't care about that; we'll add all fields from the joined entity.
$pathArray = explode('.', $key);
// The last item in the path is the field name. We don't care about that; we'll add all fields from the joined entity.
return static::checkAccessRecord($apiRequest, $record, $userID);
}
return static::checkAccessRecord($apiRequest, $record, $userID);
}
+ /**
+ * @return \Civi\Api4\Service\Schema\SchemaMap
+ */
+ public static function getSchemaMap() {
+ $cache = \Civi::cache('metadata');
+ $schemaMap = $cache->get('api4.schema.map');
+ if (!$schemaMap) {
+ $schemaMap = \Civi::service('schema_map_builder')->build();
+ $cache->set('api4.schema.map', $schemaMap);
+ }
+ return $schemaMap;
+ }
+
<service id="spec_gatherer" class="Civi\Api4\Service\Spec\SpecGatherer" public="true"/>
<service id="spec_gatherer" class="Civi\Api4\Service\Spec\SpecGatherer" public="true"/>
- <service id="schema_map_builder" class="Civi\Api4\Service\Schema\SchemaMapBuilder" public="false">
+ <service id="schema_map_builder" class="Civi\Api4\Service\Schema\SchemaMapBuilder" public="true">
<argument type="service" id="dispatcher" />
</service>
<argument type="service" id="dispatcher" />
</service>
- <service id="schema_map" class="Civi\Api4\Service\Schema\SchemaMap" public="true">
- <factory service="schema_map_builder" method="build"/>
- </service>
-
- <service id="joiner" class="Civi\Api4\Service\Schema\Joiner" public="true">
- <argument type="service" id="schema_map"/>
- </service>
-
<service id="action_object_provider" class="Civi\Api4\Provider\ActionObjectProvider" public="true">
<tag name="event_subscriber"/>
</service>
<service id="action_object_provider" class="Civi\Api4\Provider\ActionObjectProvider" public="true">
<tag name="event_subscriber"/>
</service>