protected function getImport($id) { $import = ImportQuery::create()->findPk($id); if (null === $import) { throw new \ErrorException($this->getTranslator()->trans("There is no id \"%id\" in the imports", ["%id" => $id])); } return $import; }
protected function parseImports(SimpleXMLElement $xml) { if (false === ($imports = $xml->xpath('//config:imports/config:import'))) { return; } $con = Propel::getWriteConnection(ImportTableMap::DATABASE_NAME); $con->beginTransaction(); try { /** @var SimpleXMLElement $import */ foreach ($imports as $import) { $id = (string) $import->getAttributeAsPhp("id"); $class = (string) $import->getAttributeAsPhp("class"); $categoryRef = (string) $import->getAttributeAsPhp("category_id"); if (!class_exists($class)) { throw new \ErrorException("The class \"{$class}\" doesn't exist"); } $category = ImportCategoryQuery::create()->findOneByRef($categoryRef); if (null === $category) { throw new \ErrorException("The import category \"{$categoryRef}\" doesn't exist"); } $importModel = ImportQuery::create()->findOneByRef($id); if (null === $importModel) { $importModel = new Import(); $importModel->setRef($id); } $importModel->setImportCategory($category)->setHandleClass($class)->save($con); /** @var SimpleXMLElement $descriptive */ foreach ($import->children() as $descriptive) { $locale = $descriptive->getAttributeAsPhp("locale"); $title = null; $description = null; /** @var SimpleXMLElement $row */ foreach ($descriptive->children() as $row) { switch ($row->getName()) { case "title": $title = (string) $row; break; case "description": $description = (string) $row; break; } } $importModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con); } } $con->commit(); } catch (\Exception $e) { $con->rollBack(); Tlog::getInstance()->error($e->getMessage()); } }
/** * Get the associated ChildImport object * * @param ConnectionInterface $con Optional Connection object. * @return ChildImport The associated ChildImport object. * @throws PropelException */ public function getImport(ConnectionInterface $con = null) { if ($this->aImport === null && $this->id !== null) { $this->aImport = ChildImportQuery::create()->findPk($this->id, $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->aImport->addImportI18ns($this); */ } return $this->aImport; }
protected function getQueryModel() { return ImportQuery::create(); }
/** * Returns the number of related Import objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related Import objects. * @throws PropelException */ public function countImports(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collImportsPartial && !$this->isNew(); if (null === $this->collImports || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collImports) { return 0; } if ($partial && !$criteria) { return count($this->getImports()); } $query = ChildImportQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByImportCategory($this)->count($con); } return count($this->collImports); }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see Import::setDeleted() * @see Import::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildImportQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Performs an INSERT on the database, given a Import or Criteria object. * * @param mixed $criteria Criteria or Import 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(ImportTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Import object } if ($criteria->containsKey(ImportTableMap::ID) && $criteria->keyContainsValue(ImportTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportTableMap::ID . ')'); } // Set the correct dbName $query = ImportQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }