/** * @param $API_JSON * @param $offset */ function processApiData($API_JSON, $offset) { $APIItems = APIItemV2::getMultipleItemsByJSON($API_JSON); try { $itemCount = $offset; foreach ($APIItems as $APIItem) { $itemCount++; if ($APIItem == null) { print "Skipped item {$itemCount} on page {$offset}.\n"; continue; } echo "{$itemCount}: {$APIItem->getName()} (ID: {$APIItem->getItemId()})\n"; $itemData = array('TypeId' => getOrCreateTypeID($APIItem->getMarketType()), 'DataId' => $APIItem->getItemId(), 'Name' => $APIItem->getName(), 'RestrictionLevel' => $APIItem->getLevel(), 'Rarity' => getRarityID($APIItem->getRarity()), 'VendorSellPrice' => $APIItem->getVendorValue(), 'Img' => $APIItem->getImageURL(), 'RarityWord' => $APIItem->getRarity(), 'UnsellableFlag' => $APIItem->isUnsellable()); $item = ItemQuery::create()->findPK($APIItem->getItemId()); if ($item === null) { $item = new Item(); } $item->fromArray($itemData); $itemType = ItemTypeQuery::create()->findPk($itemData['TypeId']); if ($itemType !== null) { if ($APIItem->getSubType() !== null) { $itemSubType = ItemSubTypeQuery::create()->findOneByTitle($APIItem->getDBSubType()); if ($itemSubType === null) { //All of the below types are known to not exist in the market data with an ID (by this name). //Rune/Sigil/Utility/Gem/Booze/Halloween/LargeBundle/RentableContractNpc/ContractNPC/UnlimitedConsumable //TwoHandedToy/AppearanceChange/Immediate/Unknown $itemSubTypes = ItemSubTypeQuery::create()->filterByMainTypeId($itemData['TypeId'])->withColumn('MAX(id)', 'MAXid')->find(); $SubTypeID = $itemSubTypes[0]->getMAXid() + 1; $itemSubType = new ItemSubType(); $itemSubType->fromArray(array('Id' => $SubTypeID, 'MainTypeId' => $itemData['TypeId'], 'Title' => $APIItem->getDBSubType())); $itemSubType->save(); $itemType->addSubType($itemSubType); $item->setItemSubType($itemSubType); } $itemType->addSubType($itemSubType); $item->setItemSubType($itemSubType); } $item->setItemType($itemType); } $item->save(); } } catch (Exception $e) { echo "failed [[ {$e->getMessage()} ]] .. \n"; } }
/** * 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->aItemType !== null) { if ($this->aItemType->isModified() || $this->aItemType->isNew()) { $affectedRows += $this->aItemType->save($con); } $this->setItemType($this->aItemType); } if ($this->aItemSubType !== null) { if ($this->aItemSubType->isModified() || $this->aItemSubType->isNew()) { $affectedRows += $this->aItemSubType->save($con); } $this->setItemSubType($this->aItemSubType); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->recipesScheduledForDeletion !== null) { if (!$this->recipesScheduledForDeletion->isEmpty()) { $pks = array(); $pk = $this->getPrimaryKey(); foreach ($this->recipesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { $pks[] = array($remotePk, $pk); } IngredientQuery::create()->filterByPrimaryKeys($pks)->delete($con); $this->recipesScheduledForDeletion = null; } foreach ($this->getRecipes() as $recipe) { if ($recipe->isModified()) { $recipe->save($con); } } } if ($this->usersScheduledForDeletion !== null) { if (!$this->usersScheduledForDeletion->isEmpty()) { $pks = array(); $pk = $this->getPrimaryKey(); foreach ($this->usersScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { $pks[] = array($remotePk, $pk); } OnWatchlistQuery::create()->filterByPrimaryKeys($pks)->delete($con); $this->usersScheduledForDeletion = null; } foreach ($this->getUsers() as $user) { if ($user->isModified()) { $user->save($con); } } } if ($this->resultOfRecipesScheduledForDeletion !== null) { if (!$this->resultOfRecipesScheduledForDeletion->isEmpty()) { foreach ($this->resultOfRecipesScheduledForDeletion as $resultOfRecipe) { // need to save related object because we set the relation to null $resultOfRecipe->save($con); } $this->resultOfRecipesScheduledForDeletion = null; } } if ($this->collResultOfRecipes !== null) { foreach ($this->collResultOfRecipes as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->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); } } } if ($this->sellListingsScheduledForDeletion !== null) { if (!$this->sellListingsScheduledForDeletion->isEmpty()) { SellListingQuery::create()->filterByPrimaryKeys($this->sellListingsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->sellListingsScheduledForDeletion = null; } } if ($this->collSellListings !== null) { foreach ($this->collSellListings as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->buyListingsScheduledForDeletion !== null) { if (!$this->buyListingsScheduledForDeletion->isEmpty()) { BuyListingQuery::create()->filterByPrimaryKeys($this->buyListingsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->buyListingsScheduledForDeletion = null; } } if ($this->collBuyListings !== null) { foreach ($this->collBuyListings as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->onWatchlistsScheduledForDeletion !== null) { if (!$this->onWatchlistsScheduledForDeletion->isEmpty()) { WatchlistQuery::create()->filterByPrimaryKeys($this->onWatchlistsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->onWatchlistsScheduledForDeletion = null; } } if ($this->collOnWatchlists !== null) { foreach ($this->collOnWatchlists as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }