<commit_before><?php

require_once 'pcpteams.civix.php';
require_once 'CRM/Pcpteams/Constant.php';

/**
 * Implementation of hook_civicrm_config
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
 */
function pcpteams_civicrm_config(&$config) {
  _pcpteams_civix_civicrm_config($config);
}

/**
 * Implementation of hook_civicrm_xmlMenu
 *
 * @param $files array(string)
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
 */
function pcpteams_civicrm_xmlMenu(&$files) {
  _pcpteams_civix_civicrm_xmlMenu($files);
}

/**
 * Implementation of hook_civicrm_install
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
 */
function pcpteams_civicrm_install() {
  //create custom group from xml file 
  // Create OptionGroup, OptionValues, RelationshipType, CustomGroup and CustomFields
  $extensionDir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  $customDataXMLFile = $extensionDir  . '/xml/CustomGroupData.xml';
  $import = new CRM_Utils_Migrate_Import( );
  $import->run( $customDataXMLFile );
  
  //Create Contact Subtype
  $params = array('parent_id' => 3, 'is_active' => 1, 'is_reserved' => 0);
  foreach (array(
    CRM_Pcpteams_Constant::C_CONTACT_SUB_TYPE
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_MEM
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_CELEB
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_BRANCH
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_PARTNER
    ) as $subTypes) {
    if(!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $subTypes, 'id', 'name')){
      $params['name']  = $subTypes;
      $params['label'] = str_replace('_', ' ', $subTypes);
      CRM_Contact_BAO_ContactType::add($params);
    }
  }
  
  //set foreignkey
  $sql = "ALTER TABLE `civicrm_value_pcp_custom_set`
  MODIFY `team_pcp_id` int(10) unsigned DEFAULT NULL,
  ADD CONSTRAINT `FK_civicrm_value_pcp_custom_set_team_pcp_id` FOREIGN KEY (`team_pcp_id`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL";
  CRM_Core_DAO::executeQuery($sql);
  
  $messageHtmlSampleTeamInviteFile  = $extensionDir . '/message_templates/sample_team_invite.html';
  $messageHtml      = file_get_contents($messageHtmlSampleTeamInviteFile);
  $message_params = array(<commit_msg>Added foreign keys for custom_relationship table in install hook<commit_after><?php

require_once 'pcpteams.civix.php';
require_once 'CRM/Pcpteams/Constant.php';

/**
 * Implementation of hook_civicrm_config
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
 */
function pcpteams_civicrm_config(&$config) {
  _pcpteams_civix_civicrm_config($config);
}

/**
 * Implementation of hook_civicrm_xmlMenu
 *
 * @param $files array(string)
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
 */
function pcpteams_civicrm_xmlMenu(&$files) {
  _pcpteams_civix_civicrm_xmlMenu($files);
}

/**
 * Implementation of hook_civicrm_install
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
 */
function pcpteams_civicrm_install() {
  //create custom group from xml file 
  // Create OptionGroup, OptionValues, RelationshipType, CustomGroup and CustomFields
  $extensionDir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  $customDataXMLFile = $extensionDir  . '/xml/CustomGroupData.xml';
  $import = new CRM_Utils_Migrate_Import( );
  $import->run( $customDataXMLFile );
  
  //Create Contact Subtype
  $params = array('parent_id' => 3, 'is_active' => 1, 'is_reserved' => 0);
  foreach (array(
    CRM_Pcpteams_Constant::C_CONTACT_SUB_TYPE
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_MEM
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_CELEB
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_BRANCH
    , CRM_Pcpteams_Constant::C_CONTACTTYPE_PARTNER
    ) as $subTypes) {
    if(!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $subTypes, 'id', 'name')){
      $params['name']  = $subTypes;
      $params['label'] = str_replace('_', ' ', $subTypes);
      CRM_Contact_BAO_ContactType::add($params);
    }
  }
  
  //set foreignkey
  $sql = "ALTER TABLE `civicrm_value_pcp_custom_set`
  MODIFY `team_pcp_id` int(10) unsigned DEFAULT NULL,
  ADD CONSTRAINT `FK_civicrm_value_pcp_custom_set_team_pcp_id` FOREIGN KEY (`team_pcp_id`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL";
  CRM_Core_DAO::executeQuery($sql);
  
  //set foreignkey for pcp_a_b and pcp_b_a on delete make null
  $alterSql = "ALTER TABLE `civicrm_value_pcp_relationship_set`
  MODIFY `pcp_a_b` int(10) unsigned DEFAULT NULL, MODIFY `pcp_b_a` int(10) unsigned DEFAULT NULL,
  ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_a_b` FOREIGN KEY (`pcp_a_b`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_b_a` FOREIGN KEY (`pcp_b_a`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL
  ";
  CRM_Core_DAO::executeQuery($alterSql);
  
  $messageHtmlSampleTeamInviteFile  = $extensionDir . '/message_templates/sample_team_invite.html';
  $messageHtml      = file_get_contents($messageHtmlSampleTeamInviteFile);
  $message_params = array(
{'fraction_non_alphanumeric': 0.11767005473025802, 'fraction_numerical': 0.002736512900703675, 'mean_word_length': 5.568677792041078, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '707546', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1954, 'n_words': 296}