function action_save() { $old_id = $this->bean->id; // create new version unset($this->bean->id); parent::action_save(); // redirect to new version $this->return_id = $this->bean->id; // hide old version $this->bean->mark_deleted($old_id); }
public function testaction_save() { $SugarController = new SugarController(); $SugarController->setModule('Users'); $SugarController->loadBean(); //execute the method and check if it either works or throws an mysql exception. //Fail if it throws any other exception. try { $SugarController->action_save(); } catch (Exception $e) { $this->assertStringStartsWith('mysqli_query()', $e->getMessage()); } $this->assertTrue(true); }
function action_save() { if (empty($this->bean->id)) { parent::action_save(); } $this->removeCategories(); // NOTE: call from_html _before_ calling $json->decode... WTF! $json = getJSONobj(); // workaround for #276 $hiddenFieldContent = $_POST['categoryHiddenField']; if (!empty($hiddenFieldContent)) { $categoryHiddenField = $json->decode(from_html($hiddenFieldContent)); //$GLOBALS['log']->error("product catalog tree structure: ". var_export($categoryHiddenField,true)); // for each category store its subcategories in the subcategories attribute (saveCategories()) and store the ids of the root categories in the category_ids fields of the product catalog $this->bean->category_ids = implode(' ', $this->saveCategories($categoryHiddenField)); } else { $GLOBALS['log']->warn("field 'item' which is neccessary for creating category structure does not exist"); } parent::action_save(); }
function action_save() { $isDuplicate = empty($_REQUEST['record']) && empty($_REQUEST['return_id']); // check if there are any modifications $modified = hasBeenModified($this->bean, array()); if (!$isDuplicate && !$modified) { return; // skip save if this is not a duplicate and nothing been modified } //2.0 We determine to what catalog category belongs if (!empty($this->bean->relatedcategory_id)) { $category = new oqc_Category(); if ($category->retrieve($this->bean->relatedcategory_id)) { $this->bean->catalog_id = $category->catalog_id; } } // save id of user that created the old version global $timedate; $dateCreated = $timedate->to_db($this->bean->date_entered); $createdById = $this->bean->created_by; $old_id = $this->begin_new_version(); parent::action_save(); $this->end_new_version($old_id); $this->initializeUniqueIdentifier(); $this->save_packaged_products(); $this->saveAttachedDocuments(); $this->saveProductOptions(); $this->saveImageWithResize(); $this->updateRelatedProducts($old_id); //$GLOBALS['log']->error("Dates are: ". $this->bean->date_entered ); // the new contract should have the same creator and creation date as the previous version, fix for #486 if ($dateCreated) { $this->bean->date_entered = $dateCreated; } if ($createdById) { $this->bean->created_by = $createdById; } if (!isset($_POST['assigned_user_id'])) { $this->bean->assigned_user_id = $this->bean->created_by; } //2.1 set this only if it is not in $_POST parent::action_save(); }
function action_save() { $old_id = null; $isLinked = false; if (isset($_POST['isLinked'])) { $isLinked = $_POST['isLinked'] == 'true' ? true : false; } // create new version of Addition and update Contract idsofadditions field since we are creating new version of Addition if (!$isLinked && !empty($this->bean->contractid)) { if (!$this->bean->is_latest) { $latestVersion = $this->bean->getLatestRevision(); $old_id = $latestVersion->id; $this->bean->version = intval($latestVersion->version + 1); } else { $old_id = $this->bean->id; $this->bean->version = intval($this->bean->version + 1); } //$GLOBALS['log']->fatal('going branch 1'); unset($this->bean->id); unset($this->bean->{$this->bean->table_name . '_number'}); $this->bean->deleted = 0; $this->bean->nextrevisions = ''; $this->bean->is_latest = 1; //1.7.6 $this->bean->previousrevision = $old_id; SugarController::action_save(); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } $this->bean->oqc_delete_relationships($this->bean->id); // deleting documents and services- will be recreated during save //Recreate relationship to original contract $contract = 'oqc_contract'; $this->bean->load_relationship($contract); $this->bean->oqc_contract->add($this->bean->contractid); //Update idsofadditions linked of contract $linkedContract = new oqc_Contract(); if ($linkedContract->retrieve($this->bean->contractid)) { $linkedContract->idsofadditions = str_replace($old_id, $this->bean->id, $linkedContract->idsofadditions); $linkedContract->save(); } } elseif ($isLinked) { if ($this->bean->deleted == 1) { $this->bean->mark_undeleted($this->bean->id); } $this->bean->deleted = 0; $this->bean->is_latest = 1; //$GLOBALS['log']->fatal('going branch 3'); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } $this->bean->oqc_delete_relationships($this->bean->id); // deleting documents and services- will be recreated during save //Recreate relationship to original contract $contract = 'oqc_contract'; $this->bean->load_relationship($contract); $this->bean->oqc_contract->add($this->bean->contractid); // Add new addition to the list of idsofadditions $linkedContract = new oqc_Contract(); if ($linkedContract->retrieve($this->bean->contractid)) { $linkedContract->idsofadditions = $linkedContract->idsofadditions . " " . $this->bean->id; $linkedContract->save(); } } if (isset($_POST['servicesVAT'])) { $this->bean->vat = $_POST['servicesVAT']; } else { if (isset($_POST['servicesOnceVAT'])) { $this->bean->vat = $_POST['servicesOnceVAT']; } } $this->saveAttachedDocuments(); $this->saveTextblocks(); $this->saveServices(); if (!isset($_POST['assigned_user_id'])) { $this->bean->assigned_user_id = $this->bean->created_by; } //2.1 set this only if it is not in $_POST SugarController::action_save(); // redirect to new version $this->return_id = $this->bean->id; $this->return_module = $this->module; // If previous version exist, hide it and update nextrevision field if ($old_id != '') { $oldBean = new $this->bean->object_name(); if ($oldBean->retrieve($old_id)) { $oldBean->addNextRevisionId($this->bean->id); $oldBean->save(); $this->bean->oqc_mark_deleted($old_id); //1.7.6 } } }
function action_save() { $old_id = ''; if ($this->bean->is_latest) { $old_id = $this->bean->id; $this->bean->version = $this->bean->version + 1; } else { $latestRevision = $this->bean->getLatestRevision($this->bean->id); $old_id = $latestRevision->id; $this->bean->version = intval($latestRevision->version + 1); } if (empty($this->bean->contractid)) { unset($this->bean->id); unset($this->bean->{$this->bean->table_name . '_number'}); $this->bean->deleted = 0; $this->bean->nextrevisions = ''; $this->bean->is_latest = 1; //1.7.6 $this->bean->previousrevision = $old_id; //$this->bean->version = $this->bean->getHeadVersion() + 1; SugarController::action_save(); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } } else { unset($this->bean->id); unset($this->bean->{$this->bean->table_name . '_number'}); $this->bean->deleted = 0; $this->bean->nextrevisions = ''; $this->bean->is_latest = 1; //1.7.6 $this->bean->previousrevision = $old_id; $this->bean->version = $this->bean->getHeadVersion() + 1; $this->bean->contractid = ''; // remove link to contract since its no longer is valid SugarController::action_save(); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } } if (isset($_POST['servicesVAT'])) { $this->bean->vat = $_POST['servicesVAT']; } else { if (isset($_POST['servicesOnceVAT'])) { $this->bean->vat = $_POST['servicesOnceVAT']; } } $this->saveAttachedDocuments(); $this->saveTextblocks(); $this->saveServices(); if (!isset($_POST['assigned_user_id'])) { $this->bean->assigned_user_id = $this->bean->created_by; } //2.1 set this only if it is not in $_POST SugarController::action_save(); // redirect to new version $this->return_id = $this->bean->id; $this->return_module = $this->module; if ($old_id != '') { $oldBean = new $this->bean->object_name(); if ($oldBean->retrieve($old_id)) { $oldBean->addNextRevisionId($this->bean->id); $oldBean->save(); // hide previous version $this->bean->oqc_mark_deleted($old_id); } } }
function action_save() { global $timedate; $old_id = null; $isLinked = false; if (isset($_POST['isLinked'])) { $isLinked = $_POST['isLinked'] == 'true' ? true : false; } //$GLOBALS['log']->fatal('isLinked variable is '.$isLinked . ' POST is '. $_POST['isLinked'] ); // create a detached version without quote references if (!$isLinked && empty($this->bean->offeringid)) { if ($this->bean->is_latest) { $old_id = $this->bean->id; $this->bean->version = $this->bean->version + 1; } else { $latestRevision = $this->bean->getLatestRevision($this->bean->id); $old_id = $latestRevision->id; $this->bean->version = $latestRevision->version + 1; } //$GLOBALS['log']->fatal('going branch 1'); unset($this->bean->id); unset($this->bean->{$this->bean->table_name . '_number'}); $this->bean->deleted = 0; $this->bean->nextrevisions = ''; $this->bean->is_latest = 1; //1.7.6 $this->bean->idsofadditions = ''; //2.0RC2 remove additions since this is new version of Contract $this->bean->previousrevision = $old_id; parent::action_save(); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } } elseif (!empty($this->bean->offeringid) && !$isLinked) { //$GLOBALS['log']->fatal('going branch 2'); if ($this->bean->is_latest == 0 && $this->bean->deleted == 0) { return header("Location: index.php?action=DetailView&module={$this->bean->object_name}&record={$this->bean->id}"); // do nothing user is modifying old record; otherwise it is just created from Quote } //$GLOBALS['log']->fatal('going branch 2a'); if ($this->bean->deleted == 1) { $this->bean->mark_undeleted($this->bean->id); $old_id = $this->bean->previousrevision; } $this->bean->deleted = 0; $this->bean->is_latest = 1; //1.7.6 addition $this->bean->idsofadditions = ''; //2.0RC2 remove additions since this is new version of Contract $this->bean->oqc_cleanup_document_revision($this->bean->id); //delete document revision that is no longer valid after modification if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } $this->bean->oqc_delete_relationships($this->bean->id); // deleting documents and services- will be recreated during save } elseif ($isLinked) { if ($this->bean->deleted == 1) { $this->bean->mark_undeleted($this->bean->id); } $this->bean->deleted = 0; $this->bean->is_latest = 1; $this->bean->idsofadditions = ''; //2.0RC2 remove additions since this is new version of Contract $old_id = $this->bean->previousrevision; //$GLOBALS['log']->fatal('going branch 3'); //retrieve saved bean for oqc...number that is created during save $oqc_fld_number = $this->bean->table_name . '_number'; $savedBean = new $this->bean->object_name(); if ($savedBean->retrieve($this->bean->id)) { $this->bean->{$oqc_fld_number} = intval($savedBean->{$oqc_fld_number}); } // 1.7.6 Keep generated svnumber for all future references if (empty($this->bean->svnumber)) { $this->bean->fill_in_svnumber(); } $this->bean->oqc_delete_relationships($this->bean->id); // deleting documents and services- will be recreated during save //Add related Quote to subpanel if ($this->bean->object_name == 'oqc_Contract') { $quote = 'oqc_offering'; $this->bean->load_relationship($quote); $this->bean->{$quote}->add($this->bean->offeringid); } } if (isset($_POST['servicesVAT'])) { $this->bean->vat = $_POST['servicesVAT']; } else { if (isset($_POST['servicesOnceVAT'])) { $this->bean->vat = $_POST['servicesOnceVAT']; } } $this->saveAttachedDocuments(); $this->saveTextblocks(); $this->saveServices(); if (!isset($_POST['assigned_user_id'])) { $this->bean->assigned_user_id = $this->bean->created_by; } //2.1 set this only if it is not in $_POST parent::action_save(); // redirect to new version $this->return_id = $this->bean->id; $this->return_module = $this->module; // save a reference to this newly created bean in the nextRevision field of the old bean if ($old_id != null) { $oldBean = new $this->bean->object_name(); if ($oldBean->retrieve($old_id)) { $oldBean->addNextRevisionId($this->bean->id); $oldBean->save(); // hide previous version $this->bean->oqc_mark_deleted($old_id); } } }
public function action_save() { $item = BeanFactory::getBean('xInventories'); if ($this->bean->new_with_id == true) { // new bean want to update xinventory must be implemented in xInventoryRecord bean class; } else { if ($this->pre_operation != $this->bean->operation || $this->pre_quantity != $this->bean->quantity || $this->pre_xinventory_id != $this->bean->xinventory_id) { if ($this->pre_xinventory_id == $this->bean->xinventory_id) { if ($item->retrieve($this->bean->xinventory_id) != null) { if ($this->pre_operation == $this->bean->operation) { $diff = $this->bean->quantity - $this->pre_quantity; if ($this->bean->operation == 'in') { $item->quantity += $diff; } else { $item->quantity -= $diff; } } else { // operation changed if ($this->pre_operation == 'in') { $item->quantity -= $this->pre_quantity; $item->quantity -= $this->bean->quantity; } else { $item->quantity += $this->pre_quantity; $item->quantity += $this->bean->quantity; } } if ($item->quantity < 0) { $item->quantity = 0; } $item->save(); } } else { // xinventory id changed if ($item->retrieve($this->pre_xinventory_id) != null) { if ($this->pre_operation == 'in') { $item->quantity -= $this->pre_quantity; if ($item->quantity < 0) { $item->quantity = 0; } } else { $item->quantity += $this->pre_quantity; } $item->save(); } if ($item->retrieve($this->bean->xinventory_id) != null) { if ($this->bean->operation == 'in') { $item->quantity += $this->bean->quantity; } else { $item->quantity -= $this->bean->quantity; if ($item->quantity < 0) { $item->quantity = 0; } } $item->save(); } } } } parent::action_save(); }
function action_save() { // make duplicate create new costs and positions $isDuplicate = empty($_REQUEST['record']) && empty($_REQUEST['return_id']); // check if there are any modifications $modified = hasBeenModified($this->bean, array('finalcosts')); if (!$isDuplicate && !$modified) { return; // skip save if this is not a duplicate and nothing has nothing has been modified } if ($this->bean->enddate != $_REQUEST['enddate']) { $this->bean->already_notified = false; // notify user again because the enddate has changed. } // save id of user that created the old version global $timedate; $dateCreated = $timedate->to_db($this->bean->date_entered); $createdById = $this->bean->created_by; $old_id = $this->begin_new_version(); parent::action_save(); $this->end_new_version($old_id); // save related data. parent::action_save() had to be called once already (auditing). $this->saveCosts($isDuplicate); $this->savePositions($isDuplicate); $this->saveSVNumbers(); $this->saveAttachedDocuments(); //1.7.6 // the new contract should have the same creator and creation date as the previous version, fix for #486 if ($dateCreated) { $this->bean->date_entered = $dateCreated; } if ($createdById) { $this->bean->created_by = $createdById; } // workaround for #487: write id stored in created_by field into assigned_user_id field to make sure that searches similiar to 'only my items' work properly $this->bean->assigned_user_id = $this->bean->created_by; parent::action_save(); $accountRelationName = 'accounts'; $contactsRelationName = 'contacts'; // make sure that the relations can be loaded if ($this->bean->load_relationship($accountRelationName) && $this->bean->load_relationship($contactsRelationName)) { if ($this->relationshipHasBeenChanged(new Account(), $accountRelationName, array('account_id'))) { // delete relationsships to accounts and contacts $this->removeAllFromRelationship(new Account(), $accountRelationName); // add the relationsships again. this avoids duplicates and outdated data $this->bean->accounts->add($this->bean->account_id); } if ($this->relationshipHasBeenChanged(new Contact(), $contactsRelationName, array('clientcontact_id', 'technicalcontact_id'))) { // delete relationsships to accounts and contacts $this->removeAllFromRelationship(new Contact(), $contactsRelationName); // add the relationsships again. this avoids duplicates and outdated data $this->bean->contacts->add($this->bean->clientcontact_id); $this->bean->contacts->add($this->bean->technicalcontact_id); // TODO add relationship to employee (contact_id) } } }