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

PCHR-3411: Remove unnecesary relationship types #2554

Conversation

reneolivo
Copy link
Member

@reneolivo reneolivo commented Mar 29, 2018

Overview

This PR removes relationships type that are not needed by CiviHR. The relationships types are:

  • Case Coordinator is
  • Employee of
  • Head of Household for
  • Household member of

Before

{

    "is_error": 0,
    "version": 3,
    "count": 4,
    "values": [
        {
            "id": "9",
            "name_a_b": "Case Coordinator is"
        },
        {
            "id": "5",
            "name_a_b": "Employee of"
        },
        {
            "id": "7",
            "name_a_b": "Head of Household for"
        },
        {
            "id": "8",
            "name_a_b": "Household Member of"
        }
    ]
}

After

{
    "is_error": 0,
    "version": 3,
    "count": 0,
    "values": []
}

Technical Details

A new upgrader was implemented for HRCore since this is a change that affects all extensions:

<?php

trait CRM_HRCore_Upgrader_Steps_1012 {

  /**
   * Removes relationship types that are not necessary for CiviHR.
   */
  public function upgrade_1012() {
    $relationshipsToBeDeleted = [
      'Case Coordinator is',
      'Employee of',
      'Head of Household for',
      'Household member of'
    ];

    // finds the relationships by name
    $result = civicrm_api3('RelationshipType', 'get', [
      'name_a_b' => [ 'IN' => $relationshipsToBeDeleted ]
    ]);

    foreach($result['values'] as $relationship) {
      // deletes them one by one
      civicrm_api3('RelationshipType', 'delete', [
        'id' => $relationship['id']
      ]);
    }

    return TRUE;
  }
}

Copy link
Contributor

@mickadoo mickadoo left a comment

Choose a reason for hiding this comment

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

The code looks very nice. However I'm going to leave a comment about this below

@mickadoo
Copy link
Contributor

@reneolivo I'm a bit concerned about deleting these relationship types. Running

SELECT name_a_b FROM civicrm_relationship_type WHERE is_reserved = 1;

On a vanilla CiviCRM site will return 3 rows

name
Employee of
Head of Household for
Household Member of

And all 3 of them would be deleted by this PR. Maybe that might be fine and they're just reserved for fun, but looking through the code I see places like this, this and this. I tested this out by deleting the relationship types from your PR and then trying to create a new contact in CiviCRM with "Current Employer" set it gave me this:

image

There are also places where this error isn't thrown but it does depend on one of these relationship types. For example this code seems to depend on two relationship types. And indeed after deleting these types, going to "Advanced search", selecting some contacts and choosing "print mailing label" from the actions, and checking "Merge labels for contacts belonging to the same household" I got

image

I'm guessing if I can find these problems in a few minutes there are plenty more that I've missed. If we really don't want to show these in CiviHR it might be a better option to try to hide them.

Copy link
Contributor

@mickadoo mickadoo left a comment

Choose a reason for hiding this comment

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

Just two codestyle comments

/**
* Returns the Ids of the the relationship types to be disabled.
*
* @return Array[int]
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the IDE not complain about this? I thought the standard way was to use int[]

Copy link
Member Author

Choose a reason for hiding this comment

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

The IDE even makes it pretty (Atom IDE).... I'll change it anyways!

'id' => $relationship['id']
]);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Unforgivable, no empty line before closing bracked 😁 Did you run civilint on this file?

/**
* Returns all the relationships associated with a given type.
*
* @param int[] $relationshipTypeId
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny mistake, this is int and not int[]

@reneolivo reneolivo force-pushed the PCHR-3411-delete-unnecesary-relationship-types branch from c348166 to b3125ec Compare March 29, 2018 15:44
Copy link
Contributor

@mickadoo mickadoo left a comment

Choose a reason for hiding this comment

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

looks good 🏎️

@reneolivo reneolivo merged commit 24a529a into PCHR-3369-tasks-and-workflows-ux-improvements Mar 29, 2018
@reneolivo reneolivo deleted the PCHR-3411-delete-unnecesary-relationship-types branch March 29, 2018 15:47
@reneolivo reneolivo restored the PCHR-3411-delete-unnecesary-relationship-types branch April 27, 2018 15:52
@reneolivo reneolivo deleted the PCHR-3411-delete-unnecesary-relationship-types branch August 20, 2018 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants