/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aIndicatorsSc !== null) { if ($this->aIndicatorsSc->isModified() || $this->aIndicatorsSc->isNew()) { $affectedRows += $this->aIndicatorsSc->save($con); } $this->setIndicatorsSc($this->aIndicatorsSc); } if ($this->aUserSc !== null) { if ($this->aUserSc->isModified() || $this->aUserSc->isNew()) { $affectedRows += $this->aUserSc->save($con); } $this->setUserSc($this->aUserSc); } if ($this->aGroupDataIndicadores !== null) { if ($this->aGroupDataIndicadores->isModified() || $this->aGroupDataIndicadores->isNew()) { $affectedRows += $this->aGroupDataIndicadores->save($con); } $this->setGroupDataIndicadores($this->aGroupDataIndicadores); } if ($this->isNew()) { $this->modifiedColumns[] = DataIndicadoresPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = DataIndicadoresPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += DataIndicadoresPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collAuditDataIndicadoress !== null) { foreach ($this->collAuditDataIndicadoress as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function executeCreate_mirror_tree(sfWebRequest $request) { $tree_id = $request->getParameter('idTree'); $user = $this->getUser()->getAttribute(sfConfig::get('app_session_current_user'), null); if ($user != null) { $tree_current = TreeScPeer::retrieveByPK($tree_id); if (is_object($tree_current)) { try { $conn = Propel::getConnection(); $conn->beginTransaction(); $tree_bean = new TreeSc(); $tree_bean->setName($tree_current->getName()); $tree_bean->setUserId($tree_current->getUserId()); $tree_bean->setConfigureFlag($tree_current->getConfigureFlag()); $tree_bean->setConfigureDesign($tree_current->getConfigureDesign()); $tree_bean->setCreateAt(time()); $tree_bean->setUpdateAt(time()); $tree_bean->setFlag($tree_current->getFlag()); $tree_bean->setProduccion('not'); $tree_bean->setGrupoTrabajoId($tree_current->getGrupoTrabajoId()); $tree_bean->setPeriodoId($tree_current->getPeriodoId()); $tree_bean->save(); $tree_user_bean = new TreeUser(); $tree_user_bean->setUserId($tree_bean->getUserId()); $tree_user_bean->setTreeId($tree_bean->getId()); $tree_user_bean->save(); $criterio = new Criteria(); $criterio->add(IndicatorsScPeer::TREE_ID, $tree_current->getId()); $criterio->add(IndicatorsScPeer::FLAG, '%habilitado%', Criteria::LIKE); $criterio->addAscendingOrderByColumn(IndicatorsScPeer::ID); $list_indicadores = IndicatorsScPeer::doSelect($criterio); $list_relation = null; foreach ($list_indicadores as $row) { $indicator_bean = new IndicatorsSc(); $indicator_bean->setTitulo($row->getTitulo()); $indicator_bean->setDescripcion($row->getDescripcion()); $indicator_bean->setValorMinimo($row->getValorMinimo()); $indicator_bean->setValorDeseado($row->getValorDeseado()); $indicator_bean->setValorOptimo($row->getValorOptimo()); $indicator_bean->setResponsableId($row->getResponsableId()); $indicator_bean->setTreeId($tree_bean->getId()); $indicator_bean->setEmailResponsable($row->getEmailResponsable()); $indicator_bean->setUltimoNodo($row->getUltimoNodo()); $indicator_bean->setDetNetworkAttributeId($row->getDetNetworkAttributeId()); $indicator_bean->setUsernameInNetwork($row->getUsernameInNetwork()); $indicator_bean->setGaFecIni($row->getGaFecIni()); $indicator_bean->setGaFecFin($row->getGaFecFin()); if ($row->getPreviousId() == 0) { $indicator_bean->setPreviousId(0); } else { $id_relation = $this->return_relation_id($list_relation, $row->getPreviousId()); $indicator_bean->setPreviousId($id_relation); } if ($row->getParents() != "") { $parents = $this->return_parent_relation($list_relation, $row->getParents()); $indicator_bean->setParents($parents); } $indicator_bean->setFlag($row->getFlag()); $indicator_bean->setConectoresConfigure($row->getConectoresConfigure()); $indicator_bean->save(); $relation = array('array' => '' . $row->getId() . '-' . $indicator_bean->getId() . ''); $list_relation[] = $relation; } // $conn->rollBack(); $tree_current->setFlag(2); $tree_current->save(); $conn->commit(); $conn = Propel::close(); $this->list_relation = $list_relation; $this->redirect('@edit_strategy?id_tree=' . $tree_bean->getId()); } catch (Exception $e) { $conn->rollBack(); $this->message = $e->getMessage(); $conn = Propel::close(); return sfView::ERROR; } } else { $this->message = 'tree not definitive'; $conn = Propel::close(); return sfView::ERROR; } } else { $this->message = 'session expired'; $conn = Propel::close(); return sfView::ERROR; } }