/** * 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->aEleccion !== null) { if ($this->aEleccion->isModified() || $this->aEleccion->getCulture() && $this->aEleccion->getCurrentEleccionI18n()->isModified() || $this->aEleccion->isNew()) { $affectedRows += $this->aEleccion->save($con); } $this->setEleccion($this->aEleccion); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = EleccionI18nPeer::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->setNew(false); } else { $affectedRows += EleccionI18nPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * 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->aEleccion !== null) { if ($this->aEleccion->isModified() || $this->aEleccion->isNew()) { $affectedRows += $this->aEleccion->save($con); } $this->setEleccion($this->aEleccion); } if ($this->isNew()) { $this->modifiedColumns[] = ConvocatoriaPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ConvocatoriaPeer::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 += ConvocatoriaPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collConvocatoriaI18ns !== null) { foreach ($this->collConvocatoriaI18ns as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collEnlaces !== null) { foreach ($this->collEnlaces as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collListas !== null) { foreach ($this->collListas as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collListaCalles !== null) { foreach ($this->collListaCalles as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $c = new Criteria(); $c->add(InstitucionI18nPeer::NOMBRE, 'Ayuntamiento%', Criteria::LIKE); $c->add(InstitucionI18nPeer::CULTURE, 'es'); $pager = new sfPropelPager('InstitucionI18n', 100); $pager->setCriteria($c); $pageNum = 0; do { $pageNum++; echo "\nBlock no. {$pageNum} \n"; $pager->setPage($pageNum); $pager->init(); $instituciones = $pager->getResults(); foreach ($instituciones as $institucion) { $geo = GeoPeer::retrieveByPK($institucion->getInstitucion()->getGeoId()); if ($geo) { echo "."; $nombreCorto = $geo->getNombre(); //$nombreCorto = $institucion->getInstitucion()->getGeo()->getNombre(); $vanityUrl = SfVoUtil::encodeVanity($nombreCorto); $c2 = new Criteria(); $c2->add(EleccionPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); //$c2->add(EleccionPeer::ID, $id, Criteria::NOT_EQUAL); $eleccionesLikeMe = EleccionPeer::doSelect($c2); $counter = 0; foreach ($eleccionesLikeMe as $eleccionLikeMe) { $counter++; } $vanity = "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"); $eleccion = new Eleccion(); $eleccion->setVanity($vanity); $eleccion->save(); $ei = new EleccionInstitucion(); $ei->setEleccion($eleccion); $ei->setInstitucion($institucion->getInstitucion()); $ei->save(); $eleccion_i18n = new EleccionI18n(); $eleccion_i18n->setCulture('es'); $eleccion_i18n->setNombreCorto($nombreCorto); $eleccion_i18n->setNombre("Elecciones al Ayuntamiento de {$nombreCorto}"); $eleccion_i18n->setEleccion($eleccion); $eleccion_i18n->save(); $eleccion_i18n = new EleccionI18n(); $eleccion_i18n->setCulture('ca'); $eleccion_i18n->setNombreCorto($nombreCorto); $eleccion_i18n->setNombre("Eleccions al Ajuntament de {$nombreCorto}"); $eleccion_i18n->setEleccion($eleccion); $eleccion_i18n->save(); $convocatoria = new Convocatoria(); $convocatoria->setEleccion($eleccion); $convocatoria->setNombre('2011'); $convocatoria->setFecha('2011/05/22'); $convocatoria->save(); $convocatoria_i18n = new ConvocatoriaI18n(); $convocatoria_i18n->setConvocatoria($convocatoria); $convocatoria_i18n->setCulture('es'); $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle."); $convocatoria_i18n->save(); $convocatoria_i18n = new ConvocatoriaI18n(); $convocatoria_i18n->setConvocatoria($convocatoria); $convocatoria_i18n->setCulture('ca'); $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle."); $convocatoria_i18n->save(); $circu = new Circunscripcion(); $circu->setGeo($geo); $criteria = new Criteria(); $criteria->add(PoliticoInstitucionPeer::INSTITUCION_ID, $institucion->getId()); $count = PoliticoInstitucionPeer::doCount($criteria); $circu->setEscanyos($count); $circu->save(); } } } while (!$pager->isLastPage()); }