/**
  * @param  $lhs SugarBean left side bean to add to the relationship.
  * @param  $rhs SugarBean right side bean to add to the relationship.
  * @param  $additionalFields key=>value pairs of fields to save on the relationship
  * @return boolean true if successful
  */
 public function add($lhs, $rhs, $additionalFields = array())
 {
     $lhsLinkName = $this->lhsLink;
     $rhsLinkName = $this->rhsLink;
     //Since this is bean based, we know updating the RHS's field will overwrite any old value,
     //But we need to use delete to make sure custom logic is called correctly
     if ($rhs->load_relationship($rhsLinkName)) {
         $oldLink = $rhs->{$rhsLinkName};
         $prevRelated = $oldLink->getBeans(null);
         foreach ($prevRelated as $oldLHS) {
             $this->remove($oldLHS, $rhs, false);
         }
     }
     //Make sure we load the current relationship state to the LHS link
     if (isset($lhs->{$lhsLinkName}) && is_a($lhs->{$lhsLinkName}, "Link2") || $lhs->load_relationship($lhsLinkName)) {
         $lhs->{$lhsLinkName}->load();
     }
     $this->updateFields($lhs, $rhs, $additionalFields);
     if (empty($_SESSION['disable_workflow']) || $_SESSION['disable_workflow'] != "Yes") {
         //Need to call save to update the bean as the relationship is saved on the main table
         //We don't want to create a save loop though, so make sure we aren't already in the middle of saving this bean
         SugarRelationship::addToResaveList($rhs);
         $this->updateLinks($lhs, $lhsLinkName, $rhs, $rhsLinkName);
         $this->callAfterAdd($lhs, $rhs);
         $this->callAfterAdd($rhs, $lhs);
     }
 }
 /**
  * @param  $lhs SugarBean left side bean to add to the relationship.
  * @param  $rhs SugarBean right side bean to add to the relationship.
  * @param  $additionalFields key=>value pairs of fields to save on the relationship
  *
  * @return boolean true if successful
  */
 public function add($lhs, $rhs, $additionalFields = array())
 {
     // test to see if the relationship exist if the relationship between the two beans
     // exist then we just fail out with false as we don't want to re-trigger this
     // the save and such as it causes problems with the related() in sugarlogic
     if ($this->relationship_exists($lhs, $rhs) && $lhs->inOperation('saving_related')) {
         return false;
     }
     $lhsLinkName = $this->lhsLink;
     $rhsLinkName = $this->rhsLink;
     //Since this is bean based, we know updating the RHS's field will overwrite any old value,
     //But we need to use delete to make sure custom logic is called correctly
     if ($rhs->load_relationship($rhsLinkName)) {
         $oldLink = $rhs->{$rhsLinkName};
         $prevRelated = $oldLink->getBeans(null);
         foreach ($prevRelated as $oldLHS) {
             if ($oldLHS->id != $lhs->id) {
                 $this->remove($oldLHS, $rhs, false);
             }
         }
     }
     //Make sure we load the current relationship state to the LHS link
     if (isset($lhs->{$lhsLinkName}) && is_a($lhs->{$lhsLinkName}, "Link2") || $lhs->load_relationship($lhsLinkName)) {
         $lhs->{$lhsLinkName}->load();
     }
     if (empty($_SESSION['disable_workflow']) || $_SESSION['disable_workflow'] != "Yes") {
         $this->callBeforeAdd($lhs, $rhs, $lhsLinkName);
         $this->callBeforeAdd($rhs, $lhs, $rhsLinkName);
     }
     $this->updateFields($lhs, $rhs, $additionalFields);
     if (empty($_SESSION['disable_workflow']) || $_SESSION['disable_workflow'] != "Yes") {
         //Need to call save to update the bean as the relationship is saved on the main table
         //We don't want to create a save loop though, so make sure we aren't already in the middle of saving this bean
         SugarRelationship::addToResaveList($rhs);
         $this->updateLinks($lhs, $lhsLinkName, $rhs, $rhsLinkName);
         $this->callAfterAdd($lhs, $rhs, $lhsLinkName);
         $this->callAfterAdd($rhs, $lhs, $rhsLinkName);
     }
     //One2MBean relationships require that the RHS bean be saved or else the relationship will not be saved.
     //If we aren't already in a relationship save, intitiate a save now.
     if (!$lhs->inOperation('saving_related')) {
         SugarRelationship::resaveRelatedBeans(false);
     }
     return true;
 }
Exemple #3
0
 /**
  * Marks the relationship delted for this given record pair.
  *
  * @param string $id         id of the Parent/Focus SugarBean
  * @param string $related_id id or SugarBean to unrelate. Pass a SugarBean if you have it.
  *
  * @return boolean          true if delete was successful or false if it was not
  */
 function delete($id, $related_id = '')
 {
     if (empty($this->focus->id)) {
         $this->focus = BeanFactory::getBean($this->focus->module_name, $id);
     }
     if (!empty($related_id)) {
         if (!$related_id instanceof SugarBean) {
             $related_id = $this->getRelatedBean($related_id);
         }
         if ($this->getSide() == REL_LHS) {
             return $this->relationship->remove($this->focus, $related_id);
         } else {
             return $this->relationship->remove($related_id, $this->focus);
         }
     } else {
         return $this->relationship->removeAll($this);
     }
 }
 /**
  * 
  * @static
  * @return void
  */
 public static function resaveRelatedBeans()
 {
     $GLOBALS['resavingRelatedBeans'] = true;
     //Resave any bean not currently in the middle of a save operation
     foreach (self::$beansToResave as $module => $beans) {
         foreach ($beans as $bean) {
             if (empty($bean->deleted) && empty($bean->in_save)) {
                 $bean->save();
             }
         }
     }
     $GLOBALS['resavingRelatedBeans'] = false;
     //Reset the list of beans that will need to be resaved
     self::$beansToResave = array();
 }
Exemple #5
0
 /**
  * This function should be overridden in each module.  It marks an item as deleted.
  *
  * If it is not overridden, then marking this type of item is not allowed
  */
 function mark_deleted($id)
 {
     global $current_user;
     $date_modified = $GLOBALS['timedate']->nowDb();
     if (isset($_SESSION['show_deleted'])) {
         $this->mark_undeleted($id);
     } else {
         // call the custom business logic
         $custom_logic_arguments['id'] = $id;
         $this->call_custom_logic("before_delete", $custom_logic_arguments);
         $this->deleted = 1;
         $this->mark_relationships_deleted($id);
         if (isset($this->field_defs['modified_user_id'])) {
             if (!empty($current_user)) {
                 $this->modified_user_id = $current_user->id;
             } else {
                 $this->modified_user_id = 1;
             }
             $query = "UPDATE {$this->table_name} set deleted=1 , date_modified = '{$date_modified}', modified_user_id = '{$this->modified_user_id}' where id='{$id}'";
         } else {
             $query = "UPDATE {$this->table_name} set deleted=1 , date_modified = '{$date_modified}' where id='{$id}'";
         }
         $this->db->query($query, true, "Error marking record deleted: ");
         SugarRelationship::resaveRelatedBeans();
         // Take the item off the recently viewed lists
         $tracker = new Tracker();
         $tracker->makeInvisibleForAll($id);
         $this->deleteFiles();
         // call the custom business logic
         $this->call_custom_logic("after_delete", $custom_logic_arguments);
     }
 }
 /**
  *
  * @static
  * @return void
  */
 public static function resaveRelatedBeans()
 {
     $GLOBALS['resavingRelatedBeans'] = true;
     //Resave any bean not currently in the middle of a save operation
     foreach (self::$beansToResave as $module => $beans) {
         foreach ($beans as $bean) {
             if (empty($bean->deleted) && empty($bean->in_save)) {
                 $bean->save();
             } else {
                 // Bug 55942 save the in-save id which will be used to send workflow alert later
                 if (isset($bean->id) && !empty($_SESSION['WORKFLOW_ALERTS'])) {
                     $_SESSION['WORKFLOW_ALERTS']['id'] = $bean->id;
                 }
             }
         }
     }
     $GLOBALS['resavingRelatedBeans'] = false;
     //Reset the list of beans that will need to be resaved
     self::$beansToResave = array();
 }
Exemple #7
0
 /**
  * This function should be overridden in each module.  It marks an item as deleted.
  *
  * If it is not overridden, then marking this type of item is not allowed
  */
 public function mark_deleted($id)
 {
     global $current_user;
     $date_modified = $GLOBALS['timedate']->nowDb();
     if (isset($_SESSION['show_deleted'])) {
         $this->mark_undeleted($id);
     } else {
         // Ensure that Activity Messages do not occur in the context of a Delete action (e.g. unlink)
         // and do so for all nested calls within the Top Level Delete Context
         $opflag = static::enterOperation('delete');
         $aflag = Activity::isEnabled();
         Activity::disable();
         // call the custom business logic
         $custom_logic_arguments['id'] = $id;
         $this->call_custom_logic("before_delete", $custom_logic_arguments);
         $this->deleted = 1;
         $this->mark_relationships_deleted($id);
         if (isset($this->field_defs['modified_user_id'])) {
             if (!empty($current_user)) {
                 $this->modified_user_id = $current_user->id;
             } else {
                 $this->modified_user_id = 1;
             }
             $query = "UPDATE {$this->table_name} set deleted=1, date_modified = '{$date_modified}',\n                            modified_user_id = '{$this->modified_user_id}' where id='{$id}'";
             if ($this->isFavoritesEnabled()) {
                 SugarFavorites::markRecordDeletedInFavorites($id, $date_modified, $this->modified_user_id);
             }
         } else {
             $query = "UPDATE {$this->table_name} set deleted=1 , date_modified = '{$date_modified}' where id='{$id}'";
             if ($this->isFavoritesEnabled()) {
                 SugarFavorites::markRecordDeletedInFavorites($id, $date_modified);
             }
         }
         $this->db->query($query, true, "Error marking record deleted: ");
         // Take the item off the recently viewed lists
         $tracker = BeanFactory::getBean('Trackers');
         $tracker->makeInvisibleForAll($id);
         require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
         $searchEngine = SugarSearchEngineFactory::getInstance();
         $searchEngine->delete($this);
         SugarRelationship::resaveRelatedBeans();
         // call the custom business logic
         $this->call_custom_logic("after_delete", $custom_logic_arguments);
         if (static::leaveOperation('delete', $opflag) && $aflag) {
             Activity::enable();
         }
     }
 }
 /**
  * Relates existing records to related bean.
  *
  * @param ServiceBase $api The API class of the request.
  * @param array $args The arguments array passed in from the API.
  * @return array Array of formatted fields.
  * @throws SugarApiExceptionNotFound If bean can't be retrieved.
  */
 public function createRelatedLinksFromRecordList($api, $args)
 {
     Activity::disable();
     $result = array('related_records' => array('success' => array(), 'error' => array()));
     $this->requireArgs($args, array('module', 'record', 'remote_id', 'link_name'));
     $primaryBean = $this->loadBean($api, $args);
     list($linkName) = $this->checkRelatedSecurity($api, $args, $primaryBean, 'view', 'view');
     $recordList = RecordListFactory::getRecordList($args['remote_id']);
     $relatedBeans = $primaryBean->{$linkName}->add($recordList['records']);
     if ($relatedBeans === true) {
         $result['related_records']['success'] = $recordList['records'];
     } elseif (is_array($relatedBeans)) {
         $result['related_records']['success'] = array_diff($recordList['records'], $relatedBeans);
         $result['related_records']['error'] = $relatedBeans;
     }
     SugarRelationship::resaveRelatedBeans();
     Activity::enable();
     $result['record'] = $this->formatBean($api, $args, $primaryBean);
     return $result;
 }
    $query .= " and email_marketing_prospect_lists.prospect_list_id='{$linked_id}'";
    $result = $focus->db->query($query);
    while (($row = $focus->db->fetchByAssoc($result)) != null) {
        $del_query = " update email_marketing_prospect_lists set email_marketing_prospect_lists.deleted=1, email_marketing_prospect_lists.date_modified=" . $focus->db->convert("'" . TimeDate::getInstance()->nowDb() . "'", 'datetime');
        $del_query .= " WHERE  email_marketing_prospect_lists.id='{$row['id']}'";
        $focus->db->query($del_query);
    }
    $focus->db->query($query);
}
if ($focus->object_name == "Meeting") {
    $focus->retrieve($record);
    $user = BeanFactory::getBean('Users', $linked_id);
    if (!empty($user->id)) {
        //make sure that record exists. we may have a contact on our hands.
        if ($focus->update_vcal) {
            vCal::cache_sugar_vcal($user);
        }
    }
}
if ($focus->object_name == "User" && $linked_field == 'eapm') {
    BeanFactory::deleteBean('EAPM', $linked_id);
}
SugarRelationship::resaveRelatedBeans();
if (!empty($_REQUEST['return_url'])) {
    $_REQUEST['return_url'] = urldecode($_REQUEST['return_url']);
}
$GLOBALS['log']->debug("deleted relationship: bean: {$focus->object_name}, linked_field: {$linked_field}, linked_id:{$linked_id}");
if (empty($_REQUEST['refresh_page'])) {
    handleRedirect();
}
exit;
 /**
  * {@inheritdoc}
  */
 protected function addRow(array $row)
 {
     //Need to manage the primary flag if we are going to be updating/inserting data.
     if (!empty($this->def['primary_flag_column']) && $row[$this->def['primary_flag_column']]) {
         $rhsKey = $this->def['join_key_rhs'];
         $lhsKey = $this->def['join_key_lhs'];
         $db = DBManagerFactory::getInstance();
         // The primary flag is true, that means we need to block
         // out the old primary flag
         $query = "UPDATE {$this->getRelationshipTable()} SET " . "{$this->def['primary_flag_column']} = 0 WHERE ";
         if ($this->def['primary_flag_side'] == 'rhs') {
             $query .= "{$rhsKey} = '" . $db->quote($row[$rhsKey]) . "'";
         } else {
             $query .= "{$lhsKey} = '" . $db->quote($row[$lhsKey]) . "'";
         }
         $db->query($query);
     }
     return parent::addRow($row);
 }