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

CRM-21720 Cleanup search classes to use enumerators instead of hardcoded values #11600

Merged

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Jan 28, 2018

Overview

Follow on from CRM-21391 to tidy up code for search classes (specifically in relation to search tasks)

Ref #11240


@@ -326,25 +337,15 @@ public static function getModeSelect() {
*/
public function buildTaskList() {
if ($this->_context !== 'amtg') {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you figure out what amtg stands for & when it arises please comment the code. My best guess at the moment is that it is 'add member to group'

Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton i think your right as per

'amtg' => 'Add members to group',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the search classes have a few of these strings - see https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Form/Search.php#L176

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, I've inserted a comment just above that line

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Jan 28, 2018

(CiviCRM Review Template WORD-1.0)

  • (r-jira) PASS
  • (r-test) Undecided
  • (r-code) PASS - clear improvement. Thanks!
  • (r-doc) Pass no user facing change
  • (r-maint) PASS code manageablily improved
  • (r-run) Undecided:
  • (r-user) PASS: no user facing change
  • (r-tech) PASS: code cleanup


if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
Copy link
Contributor

Choose a reason for hiding this comment

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

there are still 2 places where optionalTaskTitle() is referred to that can go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think those are removed via #11764

@@ -464,7 +452,7 @@ public function buildQuickForm() {
'class' => 'crm-form-submit',
)
);
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_ADD);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still reading but GROUP_ADD doesn't exist on my version that I can see

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It exists once #11240 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now in CRM/Core/Task.php which is part of core.

@eileenmcnaughton
Copy link
Contributor

On contact search I just found the tasks missing -
before
screenshot 2018-01-29 09 36 41

after
screenshot 2018-01-29 09 36 10

Also note that they are not alphabetically sorted - I noticed an 'asort' was removed

Some thoughts about things to verify before merge

  • count of tasks - on master with a basic install I get 22 tasks before hand on contact search
  • alpha sorting of tasks
  • check for presence of 'update smart group' when in smart group context (viewing contacts in an existing smart group)
  • specifically check the Add to group works. The constant has been changed here and I'm not sure about it.
  • test creating a group & saving with different group types (set/ blank)

if (isset($formValues['group_type']) &&
is_array($formValues['group_type'])
) {
if (isset($formValues['group_type']) && is_array($formValues['group_type']) && count($formValues['group_type'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is an unrelated change. It makes sense though from what I can see - if there is no group_type but it is set & is an array save as 'no group type'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it fixes a PHP notice as the code was not checking for an empty array, but looking at it I believe it intended to as it doesn't make sense otherwise. It's pulling a group type from the form into a variable, if there isn't one it can't do that so sets an empty string in the else below.

@@ -103,15 +103,10 @@ public function taskName($controller, $formName = 'Search') {
}
$this->_controller->set('task', $value);

if ($value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea how to get to this line without $value to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was causing a bug in some situations, as it was falling back to the contact task and would try and return the default task for contact tasks no matter what context we were in (eg. in member context). I think you could trigger it by editing a smart search and changing the "View results as" to be something other than contacts. But it should not be possible to get there with no value for $value unless you are doing something wierd and it doesn't make sense (in my opinion) to fall back to the contact task handler, as it defines a different set of tasks which are potentially not applicable to the current context.

By removing the check for $value we are always calling the relevant getTask() handler for the context.

@mattwire
Copy link
Contributor Author

@eileenmcnaughton What I failed to mention was that this should be merged AFTER #11240 as it relies on changes in that PR (eg. GROUP_ADD is defined in CRM_Core_Task). Sorry!

@mattwire mattwire force-pushed the CRM-21720_core_task_search_classes branch from 9d1ed2c to eda34f9 Compare March 5, 2018 12:33
@eileenmcnaughton
Copy link
Contributor

Per comments on #11764 this works in conjunction with that so merging both

@eileenmcnaughton eileenmcnaughton merged commit 7dd2478 into civicrm:master Mar 11, 2018
@mattwire mattwire deleted the CRM-21720_core_task_search_classes branch September 25, 2018 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants