Ejemplo n.º 1
0
 /**
  * Save changes that have been made to a relationship.
  *
  * @param $is_update true if this save is an update.
  */
 function save_relationship_changes($is_update, $exclude = array())
 {
     parent::save_relationship_changes($is_update, $exclude);
     $new_rel_id = false;
     $new_rel_link = false;
     //this allows us to dynamically relate modules without adding it to the relationship_fields array
     if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id) {
         $new_rel_id = $_REQUEST['relate_id'];
         $new_rel_relname = $_REQUEST['relate_to'];
         if (!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) {
             $new_rel_id = $this->new_rel_id;
             $new_rel_relname = $this->new_rel_relname;
         }
         $new_rel_link = $new_rel_relname;
         //Try to find the link in this bean based on the relationship
         foreach ($this->field_defs as $key => $def) {
             if (isset($def['type']) && $def['type'] == 'link' && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) {
                 $new_rel_link = $key;
             }
         }
         if ($new_rel_link == 'contacts') {
             $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id));
             if ($accountId !== false) {
                 if ($this->load_relationship('accounts')) {
                     $this->accounts->add($accountId);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Test tries to emulate changing of related field and assert correct result
  *
  * @group 44930
  * @return void
  */
 public function testChangingOfRelation()
 {
     $_REQUEST['relate_id'] = '2';
     $_REQUEST['relate_to'] = 'test';
     $bean = new SugarBean();
     $bean->id = '1';
     $bean->test_id = '3';
     $bean->field_defs = array('test' => array('type' => 'link', 'relationship' => 'test', 'link_file' => 'data/SugarBean.php', 'link_class' => 'Link44930'));
     $bean->relationship_fields = array('test_id' => 'test');
     $bean->save_relationship_changes(true);
     $this->assertEquals($bean->test_id, $bean->test->lastCall, 'Last relation should point to test_id instead of relate_id');
 }
Ejemplo n.º 3
0
 function save_relationship_changes($is_update)
 {
     parent::save_relationship_changes($is_update);
     if ($this->lead_id != "") {
         $this->set_prospect_relationship($this->id, $this->lead_id, "lead");
     }
     if ($this->contact_id != "") {
         $this->set_prospect_relationship($this->id, $this->contact_id, "contact");
     }
     if ($this->prospect_id != "") {
         $this->set_prospect_relationship($this->id, $this->contact_id, "prospect");
     }
 }
Ejemplo n.º 4
0
	function save_relationship_changes($is_update) {
		$exclude = array();
		if(empty($this->in_workflow))
        {
            if(empty($this->in_import))
            {
                //if the global soap_server_object variable is not empty (as in from a soap/OPI call), then process the assigned_user_id relationship, otherwise
                //add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship
                if(!empty($GLOBALS['soap_server_object']))
                {
           		    $exclude = array('lead_id', 'contact_id', 'user_id');
           	    }
                else
                {
	                $exclude = array('lead_id', 'contact_id', 'user_id', 'assigned_user_id');
           	    }
            }
            else
            {
                $exclude = array('user_id');
            }


        }
		parent::save_relationship_changes($is_update, $exclude);
	}
Ejemplo n.º 5
0
 function save_relationship_changes($is_update)
 {
     parent::save_relationship_changes($is_update);
     if (!empty($this->contact_id)) {
         $this->set_case_contact_relationship($this->contact_id);
     }
 }
Ejemplo n.º 6
0
 function save_relationship_changes($is_update)
 {
     //if account_id was replaced unlink the previous account_id.
     //this rel_fields_before_value is populated by sugarbean during the retrieve call.
     if (!empty($this->account_id) and !empty($this->rel_fields_before_value['account_id']) and trim($this->account_id) != trim($this->rel_fields_before_value['account_id'])) {
         //unlink the old record.
         $this->load_relationship('accounts');
         $this->accounts->delete($this->id, $this->rel_fields_before_value['account_id']);
     }
     // Bug 38529 & 40938 - exclude currency_id
     parent::save_relationship_changes($is_update, ['currency_id']);
     if (!empty($this->contact_id)) {
         $this->set_opportunity_contact_relationship($this->contact_id);
     }
 }
Ejemplo n.º 7
0
	function save_relationship_changes($is_update, $exclude = array())
    {
    	parent::save_relationship_changes($is_update, $exclude);
		if($this->lead_id != "")
	   		$this->set_prospect_relationship($this->id, $this->lead_id, "lead");
    	if($this->contact_id != "")
    		$this->set_prospect_relationship($this->id, $this->contact_id, "contact");
    	if($this->prospect_id != "")
    		$this->set_prospect_relationship($this->id, $this->contact_id, "prospect");
    }
Ejemplo n.º 8
0
 function save_relationship_changes($is_update)
 {
     $exclude = array();
     if (empty($this->in_workflow)) {
         $exclude = array('lead_id', 'contact_id', 'user_id');
     }
     parent::save_relationship_changes($is_update, $exclude);
 }
Ejemplo n.º 9
0
 public function save_relationship_changes($is_update)
 {
     //if account_id was replaced unlink the previous account_id.
     //this rel_fields_before_value is populated by sugarbean during the retrieve call.
     if (!empty($this->account_id) and !empty($this->rel_fields_before_value['account_id']) and trim($this->account_id) != trim($this->rel_fields_before_value['account_id'])) {
         //unlink the old record.
         $this->load_relationship('accounts');
         $this->accounts->delete($this->id, $this->rel_fields_before_value['account_id']);
         //propagate change down to related beans
         $relationshipsToBeTouched = array('products', 'revenuelineitems');
         foreach ($relationshipsToBeTouched as $relationship) {
             $this->load_relationship($relationship);
             foreach ($this->{$relationship}->getBeans() as $bean) {
                 $bean->account_id = $this->account_id;
                 $bean->save();
             }
         }
     }
     // Bug 38529 & 40938 - exclude currency_id
     parent::save_relationship_changes($is_update, array('currency_id'));
     if (!empty($this->contact_id)) {
         $this->set_opportunity_contact_relationship($this->contact_id);
     }
 }
Ejemplo n.º 10
0
 function save_relationship_changes($is_update)
 {
     parent::save_relationship_changes($is_update, array('lead_id', 'contact_id', 'user_id'));
 }
Ejemplo n.º 11
0
 function save_relationship_changes($is_update)
 {
     //if account_id was replaced unlink the previous account_id.
     //this rel_fields_before_value is populated by sugarbean during the retrieve call.
     if (!empty($this->account_id) and !empty($this->rel_fields_before_value['account_id']) and trim($this->account_id) != trim($this->rel_fields_before_value['account_id'])) {
         //unlink the old record.
         $this->load_relationship('accounts');
         $this->accounts->delete($this->id, $this->rel_fields_before_value['account_id']);
     }
     parent::save_relationship_changes($is_update);
 }