/** * Performs an INSERT on the database, given a EveApi or Criteria object. * * @param mixed $criteria Criteria or EveApi object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(EveApiTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from EveApi object } if ($criteria->containsKey(EveApiTableMap::COL_ID) && $criteria->keyContainsValue(EveApiTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . EveApiTableMap::COL_ID . ')'); } // Set the correct dbName $query = EveApiQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildEveApiQuery::create(); $criteria->add(EveApiTableMap::COL_ID, $this->id); return $criteria; }
/** * Returns a new ChildEveApiQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildEveApiQuery */ public static function create($modelAlias = null, Criteria $criteria = null) { if ($criteria instanceof ChildEveApiQuery) { return $criteria; } $query = new ChildEveApiQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Get the associated ChildEveApi object * * @param ConnectionInterface $con Optional Connection object. * @return ChildEveApi The associated ChildEveApi object. * @throws PropelException */ public function getEveApi(ConnectionInterface $con = null) { if ($this->aEveApi === null && $this->eveapiid !== null) { $this->aEveApi = ChildEveApiQuery::create()->findPk($this->eveapiid, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aEveApi->addEveCharacters($this); */ } return $this->aEveApi; }
public function processApiKeys() { while (true) { $eveApis = ECP\EveApiQuery::create()->filterByStatus('not processed yet')->_or()->condition('c1', 'EveApi.lastComputed < ?', time() - 24 * 60 * 60)->condition('c2', 'EveApi.status = ?', 'success')->where(array('c1', 'c2'), 'and')->find(); $eveApis->populateRelation('EveCharacter'); foreach ($eveApis as $eveApi) { $characters = array(); $eveApi->setStatus(''); try { $characters = $this->getCharacters($eveApi); $eveApi->setStatus('success'); } catch (\Pheal\Exceptions\PhealException $e) { $eveApi->setStatus('An exception occured. ' . get_real_class($e) . ': ' . $e->getMessage()); } $eveApi->setLastComputed(time()); $connection = $this->getPropelConnection(); try { $connection->beginTransaction(); foreach ($characters as $character) { $eveCharacter = $this->getSubentity2($eveApi, 'EveCharacter', $character, 'characterID', 'CharId'); $eveCharacter->setCharName($character->name); $eveCharacter->setCharId($character->characterID); $eveCharacter->setCorpName($this->tryGetProperty($character, 'corporationName')); $eveCharacter->setCorpId($this->tryGetProperty($character, 'corporationID')); $eveCharacter->setAllyName($this->tryGetProperty($character, 'allianceName')); $eveCharacter->setAllyId($this->tryGetProperty($character, 'allianceID')); $this->prepareSubentitySave3($connection, $eveApi, 'EveCharacter', $eveCharacter); } $this->cleanupOldEnties($eveApi, 'EveCharacter', $characters, 'characterID', 'CharId'); $eveApi->save($connection); $connection->commit(); } catch (Exception $e) { $connection->rollBack(); throw $e; } } sleep(30); } }
/** * Returns the number of related EveApi objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related EveApi objects. * @throws PropelException */ public function countEveApis(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collEveApisPartial && !$this->isNew(); if (null === $this->collEveApis || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collEveApis) { return 0; } if ($partial && !$criteria) { return count($this->getEveApis()); } $query = ChildEveApiQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByUser($this)->count($con); } return count($this->collEveApis); }