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

dev/core#3961 - Move component Api4 files to component extensions #26208

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions Civi/API/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public static function create(string $entity, string $action, array $params) {
$className = CoreUtil::getApiClass($entity);
$callable = [$className, $action];
if (!$className || !is_callable($callable)) {
throw new \Civi\API\Exception\NotImplementedException("API ($entity, $action) does not exist (join the API team and implement it!)");
}
// Check enabled components
$daoName = \CRM_Core_DAO_AllCoreTables::getFullName($entity);
if ($daoName && !$daoName::isComponentEnabled()) {
throw new \Civi\API\Exception\NotImplementedException("$entity API is not available because " . $daoName::COMPONENT . " component is disabled");
throw new \Civi\API\Exception\NotImplementedException("API ($entity, $action) does not exist (or the extension it belongs to is not enabled).");
}
// Extra arguments used e.g. by dynamic entities like Multi-Record custom groups & the ECK extension
$args = (array) CoreUtil::getInfoItem($entity, 'class_args');
Expand Down
8 changes: 2 additions & 6 deletions Civi/Api4/Action/Entity/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Get the names & docblocks of all APIv4 entities.
*
* Scans for api entities in core, enabled components & enabled extensions.
* Scans for api entities in core & enabled extensions.
*
* Also includes pseudo-entities from multi-record custom groups.
*/
Expand All @@ -28,15 +28,11 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
protected $includeCustom;

/**
* Returns all APIv4 entities from core, enabled components and enabled extensions.
* Returns all APIv4 entities from core & enabled extensions.
*/
protected function getRecords() {
$provider = \Civi::service('action_object_provider');
return array_filter($provider->getEntities(), function($entity) {
// Only include DAO entities from enabled components
if (!empty($entity['dao']) && !$entity['dao']::isComponentEnabled()) {
return FALSE;
}
// Check custom group permissions
if ($this->checkPermissions && in_array('CustomValue', $entity['type']) && !\CRM_Core_Permission::customGroupAdmin()) {
// Hack to get the id from the "view" url. If that url changes tests should catch it and we'll think of a better way to get that id
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_campaign/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Campaign</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_case/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Case</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_contribute/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Contribute</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_event/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Event</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_mail/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Mailing</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_member/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Member</namespace>
<format>23.02.1</format>
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions ext/civi_pledge/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Pledge</namespace>
<format>23.02.1</format>
Expand Down
3 changes: 3 additions & 0 deletions ext/civi_report/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<mixins>
<mixin>[email protected]</mixin>
</mixins>
<civix>
<namespace>CRM/Report</namespace>
<format>23.02.1</format>
Expand Down
22 changes: 10 additions & 12 deletions tests/phpunit/api/v4/Entity/ConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public function tearDown(): void {
* @throws \CRM_Core_Exception
*/
public function getEntitiesHitech(): array {
// Ensure all components are enabled so their entities show up
foreach (array_keys(\CRM_Core_Component::getComponents()) as $component) {
\CRM_Core_BAO_ConfigSetting::enableComponent($component);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was redundant with the setUp function in this class which calls enableAllComponents()

return $this->toDataProviderArray(Entity::get(FALSE)->execute()->column('name'));
}

Expand All @@ -102,20 +98,22 @@ public function getEntitiesHitech(): array {
* @return array
*/
public function getEntitiesLotech(): array {
// TODO: Auto-scan required core extensions like search_kit
$manual['add'] = ['SearchDisplay', 'SearchSegment'];
$manual['remove'] = ['CustomValue'];
// Core + required core extensions
$directores = ['', 'ext/search_kit/', 'ext/civi_*/'];
$manual['remove'] = ['CustomValue', 'SKEntity'];
$manual['transform'] = ['CiviCase' => 'Case'];

$scanned = [];
$srcDir = dirname(__DIR__, 5);
foreach ((array) glob("$srcDir/Civi/Api4/*.php") as $name) {
$fileName = basename($name, '.php');
$scanned[] = $manual['transform'][$fileName] ?? $fileName;
$baseDir = dirname(__DIR__, 5);
foreach ($directores as $directory) {
foreach ((array) glob("$baseDir/{$directory}Civi/Api4/*.php") as $name) {
$fileName = basename($name, '.php');
$scanned[] = $manual['transform'][$fileName] ?? $fileName;
}
}

$names = array_diff(
array_unique(array_merge($scanned, $manual['add'])),
$scanned,
$manual['remove']
);

Expand Down
13 changes: 0 additions & 13 deletions tests/phpunit/api/v4/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace api\v4\Entity;

use Civi\API\Exception\NotImplementedException;
use Civi\Api4\Entity;
use api\v4\Api4TestBase;

Expand All @@ -29,14 +28,11 @@
class EntityTest extends Api4TestBase {

public function testEntityGet() {
\CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
$result = Entity::get(FALSE)
->execute()
->indexBy('name');
$this->assertArrayHasKey('Entity', $result,
"Entity::get missing itself");
$this->assertArrayHasKey('Participant', $result,
"Entity::get missing Participant");

$this->assertEquals('CRM_Contact_DAO_Contact', $result['Contact']['dao']);
$this->assertEquals(['DAOEntity'], $result['Contact']['type']);
Expand All @@ -63,15 +59,6 @@ public function testEntityComponent() {
$this->assertArrayNotHasKey('Participant', $result,
"Entity::get should not have Participant when CiviEvent disabled");

// Trying to use a CiviEvent API will fail when component is disabled
try {
\Civi\Api4\Participant::get(FALSE)->execute();
$this->fail();
}
catch (NotImplementedException $e) {
$this->assertStringContainsString('CiviEvent', $e->getMessage());
}

\CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
$result = Entity::get(FALSE)
->execute()
Expand Down