Example #1
0
 /**
  * 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->aItem !== null) {
             if ($this->aItem->isModified() || $this->aItem->isNew()) {
                 $affectedRows += $this->aItem->save($con);
             }
             $this->setItem($this->aItem);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #2
0
 /**
  * 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;
 }
/**
 * @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";
    }
}
 protected function updateTrending(Item $item)
 {
     $onehourago = new DateTime();
     $onehourago->sub(new \DateInterval('PT1H'));
     $q = SellListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC);
     $oneHourAgoSellListing = $q->findOne();
     if (!$oneHourAgoSellListing || $oneHourAgoSellListing->getUnitPrice() <= 0 || $item->getMinSaleUnitPrice() <= 0) {
         $item->setSalePriceChangeLastHour(0);
     } else {
         $item->setSalePriceChangeLastHour(($item->getMinSaleUnitPrice() - $oneHourAgoSellListing->getUnitPrice()) / $oneHourAgoSellListing->getUnitPrice() * 100);
     }
     $q = BuyListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC);
     $oneHourAgoBuyListing = $q->findOne();
     if (!$oneHourAgoBuyListing || $oneHourAgoBuyListing->getUnitPrice() <= 0 || $item->getMaxOfferUnitPrice() <= 0) {
         $item->setOfferPriceChangeLastHour(0);
     } else {
         $item->setOfferPriceChangeLastHour(($item->getMaxOfferUnitPrice() - $oneHourAgoBuyListing->getUnitPrice()) / $oneHourAgoBuyListing->getUnitPrice() * 100);
     }
     $item->save();
 }