protected function getCategory($id) { $category = ExportCategoryQuery::create()->findPk($id); if (null === $category) { throw new \ErrorException($this->getTranslator()->trans("There is no id \"%id\" in the export categories", ["%id" => $id])); } return $category; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ExportCategory::setDeleted() * @see ExportCategory::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(ExportCategoryTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildExportCategoryQuery::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; } }
protected function parseExports(SimpleXMLElement $xml) { if (false === ($exports = $xml->xpath('//config:exports/config:export'))) { return; } $con = Propel::getWriteConnection(ExportTableMap::DATABASE_NAME); $con->beginTransaction(); try { /** @var SimpleXMLElement $export */ foreach ($exports as $export) { $id = (string) $export->getAttributeAsPhp("id"); $class = (string) $export->getAttributeAsPhp("class"); $categoryRef = (string) $export->getAttributeAsPhp("category_id"); if (!class_exists($class)) { throw new \ErrorException("The class \"{$class}\" doesn't exist"); } $category = ExportCategoryQuery::create()->findOneByRef($categoryRef); if (null === $category) { throw new \ErrorException("The export category \"{$categoryRef}\" doesn't exist"); } $exportModel = ExportQuery::create()->findOneByRef($id); if (null === $exportModel) { $exportModel = new Export(); $exportModel->setRef($id); } $exportModel->setExportCategory($category)->setHandleClass($class)->save($con); /** @var SimpleXMLElement $descriptive */ foreach ($export->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; } } $exportModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con); } } $con->commit(); } catch (\Exception $e) { $con->rollBack(); Tlog::getInstance()->error($e->getMessage()); } }
/** * Get the associated ChildExportCategory object * * @param ConnectionInterface $con Optional Connection object. * @return ChildExportCategory The associated ChildExportCategory object. * @throws PropelException */ public function getExportCategory(ConnectionInterface $con = null) { if ($this->aExportCategory === null && $this->export_category_id !== null) { $this->aExportCategory = ChildExportCategoryQuery::create()->findPk($this->export_category_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->aExportCategory->addExports($this); */ } return $this->aExportCategory; }
protected function getQueryModel() { return ExportCategoryQuery::create(); }
/** * Performs an INSERT on the database, given a ExportCategory or Criteria object. * * @param mixed $criteria Criteria or ExportCategory 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(ExportCategoryTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ExportCategory object } if ($criteria->containsKey(ExportCategoryTableMap::ID) && $criteria->keyContainsValue(ExportCategoryTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ExportCategoryTableMap::ID . ')'); } // Set the correct dbName $query = ExportCategoryQuery::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; }