Skip to content

Commit

Permalink
Merge pull request #17874 from colemanw/checkPermShort
Browse files Browse the repository at this point in the history
Use new checkPermissions shorthand in api calls
  • Loading branch information
seamuslee001 authored Jul 17, 2020
2 parents b5eb4be + fe80643 commit 19dc865
Show file tree
Hide file tree
Showing 46 changed files with 166 additions and 292 deletions.
4 changes: 2 additions & 2 deletions CRM/Contact/BAO/ContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function isActive($contactType) {
public static function basicTypeInfo($includeInactive = FALSE) {
$cacheKey = 'CRM_CT_BTI_' . (int) $includeInactive;
if (!Civi::cache('contactTypes')->has($cacheKey)) {
$contactType = ContactType::get()->setCheckPermissions(FALSE)->setSelect(['*'])->addWhere('parent_id', 'IS NULL');
$contactType = ContactType::get(FALSE)->setSelect(['*'])->addWhere('parent_id', 'IS NULL');
if ($includeInactive === FALSE) {
$contactType->addWhere('is_active', '=', 1);
}
Expand Down Expand Up @@ -887,7 +887,7 @@ public static function deleteCustomRowsForEntityID($customTable, $entityID) {
*/
protected static function getAllContactTypes() {
if (!Civi::cache('contactTypes')->has('all')) {
$contactTypes = (array) ContactType::get()->setCheckPermissions(FALSE)
$contactTypes = (array) ContactType::get(FALSE)
->setSelect(['id', 'name', 'label', 'description', 'is_active', 'is_reserved', 'image_URL', 'parent_id', 'parent_id:name', 'parent_id:label'])
->execute()->indexBy('name');

Expand Down
3 changes: 1 addition & 2 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ public static function getFormValues($id) {
* @throws \CiviCRM_API3_Exception
*/
public static function getSearchParams($id) {
$savedSearch = \Civi\Api4\SavedSearch::get()
->setCheckPermissions(FALSE)
$savedSearch = \Civi\Api4\SavedSearch::get(FALSE)
->addWhere('id', '=', $id)
->execute()
->first();
Expand Down
6 changes: 2 additions & 4 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ public static function getTemplateContribution($id, $overrides = []) {
'id' => $id,
]);
// First look for new-style template contribution with is_template=1
$templateContributions = \Civi\Api4\Contribution::get()
->setCheckPermissions(FALSE)
$templateContributions = \Civi\Api4\Contribution::get(FALSE)
->addWhere('contribution_recur_id', '=', $id)
->addWhere('is_template', '=', 1)
->addWhere('is_test', '=', $is_test)
Expand All @@ -434,8 +433,7 @@ public static function getTemplateContribution($id, $overrides = []) {
->execute();
if (!$templateContributions->count()) {
// Fall back to old style template contributions
$templateContributions = \Civi\Api4\Contribution::get()
->setCheckPermissions(FALSE)
$templateContributions = \Civi\Api4\Contribution::get(FALSE)
->addWhere('contribution_recur_id', '=', $id)
->addWhere('is_test', '=', $is_test)
->addOrderBy('id', 'DESC')
Expand Down
3 changes: 1 addition & 2 deletions CRM/Core/BAO/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ public static function sendTemplate($params) {
throw new CRM_Core_Exception(ts("Message template's option value or ID missing."));
}

$apiCall = MessageTemplate::get()
->setCheckPermissions(FALSE)
$apiCall = MessageTemplate::get(FALSE)
->addSelect('msg_subject', 'msg_text', 'msg_html', 'pdf_format_id', 'id')
->addWhere('is_default', '=', 1);

Expand Down
3 changes: 1 addition & 2 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,7 @@ public static function moveContactBelongings($mergeHandler, $tables, $tableOpera
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected static function filterRowBasedCustomDataFromCustomTables(array &$cidRefs) {
$customTables = (array) CustomGroup::get()
->setCheckPermissions(FALSE)
$customTables = (array) CustomGroup::get(FALSE)
->setSelect(['table_name'])
->addWhere('is_multiple', '=', 0)
->addWhere('extends', 'IN', array_merge(['Contact'], CRM_Contact_BAO_ContactType::contactTypes()))
Expand Down
3 changes: 1 addition & 2 deletions CRM/Upgrade/Incremental/php/FiveTwentyEight.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public function upgrade_5_28_alpha1($rev) {
}

public static function populateMissingContactTypeName() {
$contactTypes = \Civi\Api4\ContactType::get()
->setCheckPermissions(FALSE)
$contactTypes = \Civi\Api4\ContactType::get(FALSE)
->execute();
foreach ($contactTypes as $contactType) {
if (empty($contactType['name'])) {
Expand Down
5 changes: 2 additions & 3 deletions CRM/Upgrade/Incremental/php/FiveTwentyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
if ($rev == '5.21.alpha1') {
// Find any option groups that were not converted during the upgrade.
$notConverted = [];
$optionGroups = \Civi\Api4\OptionGroup::get()->setCheckPermissions(FALSE)->execute();
$optionGroups = \Civi\Api4\OptionGroup::get(FALSE)->execute();
foreach ($optionGroups as $optionGroup) {
$trimmedName = trim($optionGroup['name']);
if (strpos($trimmedName, ' ') !== FALSE) {
Expand Down Expand Up @@ -86,8 +86,7 @@ public function upgrade_5_21_alpha1($rev) {
}

public static function fixOptionGroupName() {
$optionGroups = \Civi\Api4\OptionGroup::get()
->setCheckPermissions(FALSE)
$optionGroups = \Civi\Api4\OptionGroup::get(FALSE)
->execute();
foreach ($optionGroups as $optionGroup) {
$name = trim($optionGroup['name']);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Check/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getChecksConfig() {
if (empty($this->checksConfig)) {
$this->checksConfig = Civi::cache('checks')->get('checksConfig', []);
if (empty($this->checksConfig)) {
$this->checksConfig = StatusPreference::get()->setCheckPermissions(FALSE)->execute()->indexBy('name');
$this->checksConfig = StatusPreference::get(FALSE)->execute()->indexBy('name');
}
}
return $this->checksConfig;
Expand Down
3 changes: 1 addition & 2 deletions CRM/Utils/Migrate/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ public function customFields(&$xml, &$idMap) {
}

foreach ($fields_indexed_by_group_id as $group_id => $fields) {
\Civi\Api4\CustomField::save()
->setCheckPermissions(FALSE)
\Civi\Api4\CustomField::save(FALSE)
->setDefaults(['custom_group_id' => $group_id])
->setRecords(json_decode(json_encode($fields), TRUE))
->execute();
Expand Down
4 changes: 2 additions & 2 deletions Civi/Api4/Action/Setting/AbstractSettingAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ protected function validateSettings($domain) {

protected function findDomains() {
if ($this->domainId == 'all') {
$this->domainId = Domain::get()->setCheckPermissions(FALSE)->addSelect('id')->execute()->column('id');
$this->domainId = Domain::get(FALSE)->addSelect('id')->execute()->column('id');
}
elseif ($this->domainId) {
$this->domainId = (array) $this->domainId;
$domains = Domain::get()->setCheckPermissions(FALSE)->addSelect('id')->execute()->column('id');
$domains = Domain::get(FALSE)->addSelect('id')->execute()->column('id');
$invalid = array_diff($this->domainId, $domains);
if ($invalid) {
throw new \API_Exception('Invalid domain id: ' . implode(', ', $invalid));
Expand Down
3 changes: 1 addition & 2 deletions Civi/Api4/Event/Subscriber/ActivityPreCreationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ protected function modify(DAOCreateAction $request) {
$activityType = $request->getValue('activity_type');
if ($activityType) {
\CRM_Core_Error::deprecatedFunctionWarning('Use activity_type_id:name instead of activity_type in APIv4');
$result = OptionValue::get()
->setCheckPermissions(FALSE)
$result = OptionValue::get(FALSE)
->addWhere('name', '=', $activityType)
->addWhere('option_group.name', '=', 'activity_type')
->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ private function setOptionGroupId(DAOCreateAction $request) {
return;
}
\CRM_Core_Error::deprecatedFunctionWarning('Use option_group_id:name instead of option_group in APIv4');
$optionGroup = OptionGroup::get()
->setCheckPermissions(FALSE)
$optionGroup = OptionGroup::get(FALSE)
->addSelect('id')
->addWhere('name', '=', $optionGroupName)
->execute();
Expand Down
3 changes: 1 addition & 2 deletions Civi/Api4/Generic/Traits/DAOActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ protected function getCustomFieldInfo($name) {
list($groupName, $fieldName) = explode('.', $name);
list($fieldName, $suffix) = array_pad(explode(':', $fieldName), 2, NULL);
if (empty(\Civi::$statics['APIv4_Custom_Fields'][$groupName])) {
\Civi::$statics['APIv4_Custom_Fields'][$groupName] = (array) CustomField::get()
->setCheckPermissions(FALSE)
\Civi::$statics['APIv4_Custom_Fields'][$groupName] = (array) CustomField::get(FALSE)
->addSelect('id', 'name', 'html_type', 'custom_group.extends')
->addWhere('custom_group.name', '=', $groupName)
->execute()->indexBy('name');
Expand Down
3 changes: 1 addition & 2 deletions Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function __construct($targetTable, $alias, $isMultiRecord, $columns) {
*/
public function getEntityFields() {
if (!$this->entityFields) {
$fields = CustomField::get()
->setCheckPermissions(FALSE)
$fields = CustomField::get(FALSE)
->setSelect(['custom_group.name', 'custom_group.extends', 'custom_group.table_name', '*'])
->addWhere('custom_group.table_name', '=', $this->getTargetTable())
->execute();
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Service/Schema/SchemaMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SchemaMapBuilder {
*/
public function __construct(EventDispatcherInterface $dispatcher) {
$this->dispatcher = $dispatcher;
$this->apiEntities = array_keys((array) Entity::get()->setCheckPermissions(FALSE)->addSelect('name')->execute()->indexBy('name'));
$this->apiEntities = array_keys((array) Entity::get(FALSE)->addSelect('name')->execute()->indexBy('name'));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions Civi/Api4/Service/Spec/SpecGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ private function addCustomFields($entity, RequestSpec $specification, $values =
if ($entity === 'Participant') {
$extends = ['Participant', 'ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'];
}
$customFields = CustomField::get()
->setCheckPermissions(FALSE)
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.extends', 'IN', $extends)
->addWhere('custom_group.is_multiple', '=', '0')
->setSelect(['custom_group.name', '*'])
Expand All @@ -146,8 +145,7 @@ private function addCustomFields($entity, RequestSpec $specification, $values =
* @param \Civi\Api4\Service\Spec\RequestSpec $specification
*/
private function getCustomGroupFields($customGroup, RequestSpec $specification) {
$customFields = CustomField::get()
->setCheckPermissions(FALSE)
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.name', '=', $customGroup)
->setSelect(['custom_group.name', 'custom_group.table_name', '*'])
->execute();
Expand Down
6 changes: 2 additions & 4 deletions ext/search/CRM/Search/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Add menu item when enabled.
*/
public function enable() {
\Civi\Api4\Navigation::create()
->setCheckPermissions(FALSE)
\Civi\Api4\Navigation::create(FALSE)
->addValue('parent_id:name', 'Search')
->addValue('label', E::ts('Create Search...'))
->addValue('name', 'create_search')
Expand All @@ -26,8 +25,7 @@ public function enable() {
* Delete menu item when disabled.
*/
public function disable() {
\Civi\Api4\Navigation::delete()
->setCheckPermissions(FALSE)
\Civi\Api4\Navigation::delete(FALSE)
->addWhere('name', '=', 'create_search')
->addWhere('domain_id', '=', 'current_domain')
->execute();
Expand Down
2 changes: 1 addition & 1 deletion ext/sequentialcreditnotes/sequentialcreditnotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function sequentialcreditnotes_civicrm_pre($op, $objectName, $id, &$params) {
$reversalStatuses = ['Cancelled', 'Chargeback', 'Refunded'];
if (empty($params['creditnote_id']) && in_array(CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution_status_id']), $reversalStatuses, TRUE)) {
if ($id) {
$existing = Contribution::get()->setCheckPermissions(FALSE)->addWhere('id', '=', (int) $id)->setSelect(['creditnote_id'])->execute()->first();
$existing = Contribution::get(FALSE)->addWhere('id', '=', (int) $id)->setSelect(['creditnote_id'])->execute()->first();
if ($existing['creditnote_id']) {
// Since we have it adding it makes is clearer.
$params['creditnote_id'] = $existing['creditnote_id'];
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testPostProcessWithSignature() {
'This is a test Signature',
]);
$mut->stop();
$activity = Activity::get()->setCheckPermissions(FALSE)->setSelect(['details'])->execute()->first();
$activity = Activity::get(FALSE)->setSelect(['details'])->execute()->first();
$bccUrl1 = CRM_Utils_System::url('civicrm/contact/view', ['reset' => 1, 'force' => 1, 'cid' => $bcc1], TRUE);
$bccUrl2 = CRM_Utils_System::url('civicrm/contact/view', ['reset' => 1, 'force' => 1, 'cid' => $bcc2], TRUE);
$this->assertContains("bcc : <a href='" . $bccUrl1 . "'>Mr. Anthony Anderson II</a><a href='" . $bccUrl2 . "'>Mr. Anthony Anderson II</a>", $activity['details']);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public function testMailer($schedule, $patterns) {
));
$activity->save();

ActivityContact::create()->setCheckPermissions(FALSE)->setValues([
ActivityContact::create(FALSE)->setValues([
'contact_id' => $contact['id'],
'activity_id' => $activity->id,
'record_type_id:name' => 'Activity Source',
Expand Down Expand Up @@ -2583,7 +2583,7 @@ protected function createMembershipFromFixture($fixture, $status, $emailParams =
);
$this->assertInternalType('numeric', $membership->id);
if ($emailParams) {
Civi\Api4\Email::create()->setCheckPermissions(FALSE)->setValues(array_merge([
Civi\Api4\Email::create(FALSE)->setValues(array_merge([
'contact_id' => $membership->contact_id,
'location_type_id' => 1,
], $emailParams))->execute();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function createCustomGroup($params = []) {
'max_multiple' => 0,
], $params);
$identifier = $params['name'] ?? $params['title'];
$this->ids['CustomGroup'][$identifier] = CustomGroup::create()->setCheckPermissions(FALSE)->setValues($params)->execute()->first()['id'];
$this->ids['CustomGroup'][$identifier] = CustomGroup::create(FALSE)->setValues($params)->execute()->first()['id'];
return $this->ids['CustomGroup'][$identifier];
}

Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/api/v3/ACLPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,7 @@ public function testApi4CustomEntityACL() {
$group = uniqid('mg');
$textField = uniqid('tx');

CustomGroup::create()
->setCheckPermissions(FALSE)
CustomGroup::create(FALSE)
->addValue('name', $group)
->addValue('extends', 'Contact')
->addValue('is_multiple', TRUE)
Expand Down
Loading

0 comments on commit 19dc865

Please sign in to comment.