/** * 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->aDiscipline !== null) { if ($this->aDiscipline->isModified() || $this->aDiscipline->isNew()) { $affectedRows += $this->aDiscipline->save($con); } $this->setDiscipline($this->aDiscipline); } if ($this->aResultItem !== null) { if ($this->aResultItem->isModified() || $this->aResultItem->isNew()) { $affectedRows += $this->aResultItem->save($con); } $this->setResultItem($this->aResultItem); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->itemsScheduledForDeletion !== null) { if (!$this->itemsScheduledForDeletion->isEmpty()) { $pks = array(); $pk = $this->getPrimaryKey(); foreach ($this->itemsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { $pks[] = array($pk, $remotePk); } IngredientQuery::create()->filterByPrimaryKeys($pks)->delete($con); $this->itemsScheduledForDeletion = null; } foreach ($this->getItems() as $item) { if ($item->isModified()) { $item->save($con); } } } if ($this->ingredientsScheduledForDeletion !== null) { if (!$this->ingredientsScheduledForDeletion->isEmpty()) { RecipeIngredientQuery::create()->filterByPrimaryKeys($this->ingredientsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->ingredientsScheduledForDeletion = null; } } if ($this->collIngredients !== null) { foreach ($this->collIngredients as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
} require dirname(__FILE__) . '/../autoload.php'; Propel::disableInstancePooling(); if (!isset($argv[1]) || !($mapfilename = $argv[1])) { die('map file required.'); } if (!file_exists($mapfilename)) { die('map file does not exist.'); } if (DisciplineQuery::create()->count() == 0) { $disciplines = array(1 => 'Huntsman', 2 => 'Artificer', 3 => 'Weaponsmith', 4 => 'Armorsmith', 5 => 'Leatherworker', 6 => 'Tailor', 7 => 'Jeweler', 8 => 'Cook'); foreach ($disciplines as $id => $name) { $d = new Discipline(); $d->setId($id); $d->setName($name); $d->save(); } } $data = json_decode(file_get_contents($mapfilename), true); $cnt = count($data) - 1; $failed = array(); $max = null; foreach ($data as $i => $row) { try { echo "[{$i} / {$cnt}]: {$row['Name']}\n"; $q = RecipeQuery::create()->findByDataId($row['DataID']); if ($q->count() == 0) { $r = new Recipe(); } else { $r = $q[0]; }