/**
  * @param ForecastWorksheet $bean
  * @param string $event
  * @param array $args
  * @return bool
  */
 public static function checkRelatedName($bean, $event, $args)
 {
     if ($event == 'before_save') {
         if (empty($bean->account_id) && !empty($bean->account_name)) {
             $bean->account_name = '';
         }
         if (empty($bean->opportunity_id) && !empty($bean->opportunity_name)) {
             $bean->opportunity_name = '';
         }
         // if we are in a delete operation, don't update the date modified
         if (isset($bean->fetched_row['date_modified']) && (SugarBean::inOperation('delete') || SugarBean::inOperation('saving_related'))) {
             $bean->date_modified = $bean->fetched_row['date_modified'];
         }
     }
     return true;
 }
Пример #2
0
 /**
  * Handler for create and update actions on a bean.
  *
  * @param SugarBean $bean
  * @param array     $args
  * @param Activity  $act
  * @return bool     eventProcessed
  */
 protected function createOrUpdate(SugarBean $bean, array $args, Activity $act)
 {
     if ($bean->deleted || $bean->inOperation('saving_related')) {
         return false;
     }
     // Add Appropriate Subscriptions for this Bean
     $this->addRecordSubscriptions($args, $bean);
     $data = array('object' => self::getBeanAttributes($bean));
     if ($args['isUpdate']) {
         $act->activity_type = 'update';
         $data['changes'] = $args['dataChanges'];
         $this->prepareChanges($bean, $data);
         //if no field changes to report, do not create the activity
         if (empty($data['changes'])) {
             return false;
         }
     } else {
         $act->activity_type = 'create';
     }
     $act->parent_id = $bean->id;
     $act->parent_type = $bean->module_name;
     $act->data = $data;
     $act->save();
     $act->processRecord($bean);
     return true;
 }
Пример #3
0
 protected function getLinkField($fieldName)
 {
     if ((empty($this->context->{$fieldName}) || !is_a($this->context->{$fieldName}, "Link2")) && !$this->context->load_relationship($fieldName)) {
         throw new Exception("Unable to load relationship {$fieldName}");
     }
     if (empty($this->context->{$fieldName})) {
         throw new Exception("Relationship {$fieldName} was not set");
     }
     if (SugarBean::inOperation('delete')) {
         // if we are in a delete operation, always re-fetch the relationships beans
         // as one of the could have changed and we want the freshest set from the db
         $this->context->{$fieldName}->beans = null;
         $this->context->{$fieldName}->resetLoaded();
     } elseif (isset($this->context->{$fieldName}->beans)) {
         return $this->context->{$fieldName}->beans;
     }
     $beans = $this->context->{$fieldName}->getBeans();
     return $beans;
 }