<commit_before><?php
abstract class CRM_Contract_Form_History extends CRM_Core_Form{

  function preProcess(){
    $this->getParams();
    $this->validateStartStatus();
    parent::preProcess();
  }

  function buildQuickForm(){
    CRM_Utils_System::setTitle($this->title);
    $this->addButtons(array(
        array('type' => 'cancel', 'name' => 'Cancel'),
        array('type' => 'submit', 'name' => $this->buttonText, 'isDefault' => true)
    ));
    $this->assign('elementNames', $this->getRenderableElementNames());
    parent::buildQuickForm();
  }

  function getParams(){
    $this->id = CRM_Utils_Request::retrieve('id', 'Integer');
    if(!$this->id){
      CRM_Core_Error::fatal('Missing a membership ID');
    }
    try{
      $this->membership = civicrm_api3('Membership', 'getsingle', array('id' => $this->id));
    }catch(Exception $e){
      CRM_Core_Error::fatal('Not a valid membership ID');
    }
    $this->_contactId = $this->membership['contact_id']; //useful?
  }

  function validateStartStatus(){
    $this->membershipStatus = civicrm_api3('MembershipStatus', 'getsingle', array('id' => $this->membership['status_id']));
    if(!in_array($this->membershipStatus['name'], $this->validStartStatuses)){
      CRM_Core_Error::fatal("You cannot run '{$this->title}' when the membership status is '{$this->membershipStatus['name']}'.");
    }
  }

  function getTemplateFileName(){
    return 'CRM/Contract/Form/History.tpl';
  }

  function getRenderableElementNames() {
    // The _elements list includes some items which should not be
    // auto-rendered in the loop -- such as "qfKey" and "buttons".  These
    // items don't have labels.  We'll identify renderable by filtering on
    // the 'label'.
    $elementNames = array();
    foreach ($this->_elements as $element) {
      /** @var HTML_QuickForm_Element $element */
      $label = $element->getLabel();
      if (!empty($label)) {
        $elementNames[] = $element->getName();
      }
    }
    return $elementNames;
  }
}
<commit_msg>change membership status and record blank activity on form submission<commit_after><?php
abstract class CRM_Contract_Form_History extends CRM_Core_Form{

  function preProcess(){
    $this->getParams();
    $this->validateStartStatus();
    parent::preProcess();
  }

  function buildQuickForm(){
    CRM_Utils_System::setTitle(ucfirst($this->action).' contract');
    $this->addButtons(array(
        array('type' => 'cancel', 'name' => 'Cancel'),
        array('type' => 'submit', 'name' => ucfirst($this->action), 'isDefault' => true)
    ));
    $this->assign('elementNames', $this->getRenderableElementNames());
    parent::buildQuickForm();
  }

  function getParams(){
    $this->id = CRM_Utils_Request::retrieve('id', 'Integer');
    if($this->id){
      $this->set('id', $this->id);
    }
    if(!$this->get('id')){
      CRM_Core_Error::fatal('Missing a membership ID');
    }
    try{
      $this->membership = civicrm_api3('Membership', 'getsingle', array('id' => $this->get('id')));
    }catch(Exception $e){
      CRM_Core_Error::fatal('Not a valid membership ID');
    }
    ; //useful?
  }

  function validateStartStatus(){
    $this->membershipStatus = civicrm_api3('MembershipStatus', 'getsingle', array('id' => $this->membership['status_id']));
    if(!in_array($this->membershipStatus['name'], $this->validStartStatuses)){
      CRM_Core_Error::fatal("You cannot run '{$this->action}' when the membership status is '{$this->membershipStatus['name']}'.");
    }
  }

  function getTemplateFileName(){
    return 'CRM/Contract/Form/History.tpl';
  }

  function getRenderableElementNames() {
    // The _elements list includes some items which should not be
    // auto-rendered in the loop -- such as "qfKey" and "buttons".  These
    // items don't have labels.  We'll identify renderable by filtering on
    // the 'label'.
    $elementNames = array();
    foreach ($this->_elements as $element) {
      /** @var HTML_QuickForm_Element $element */
      $label = $element->getLabel();
      if (!empty($label)) {
        $elementNames[] = $element->getName();
      }
    }
    return $elementNames;
  }

  function postProcess(){
    $this->membership['status_id'] = $this->endStatus;
    $this->membership['is_override'] = $this->membership['status_id'] == 'Current' ? 0 : 1;
    var_dump(civicrm_api3('Activity', 'create', array('target_id'=> $this->membership['contact_id'], 'activity_type_id' => CRM_Contract_Utils_ActionProperties::getByClass($this)['activityType'])));
    civicrm_api3('Membership', 'create', $this->membership);
  }
}

{'fraction_non_alphanumeric': 0.17553423462712603, 'fraction_numerical': 0.0017444395987788923, 'mean_word_length': 3.958918918918919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7632595', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1399, 'n_words': 287}