protected function getQueryModel() { return ImportCategoryQuery::create(); }
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()); } }
protected function getCategory($id) { $category = ImportCategoryQuery::create()->findPk($id); if (null === $category) { throw new \ErrorException($this->getTranslator()->trans("There is no id \"%id\" in the import categories", ["%id" => $id])); } return $category; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ImportCategory::setDeleted() * @see ImportCategory::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(ImportCategoryTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildImportCategoryQuery::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; } }
/** * Get the associated ChildImportCategory object * * @param ConnectionInterface $con Optional Connection object. * @return ChildImportCategory The associated ChildImportCategory object. * @throws PropelException */ public function getImportCategory(ConnectionInterface $con = null) { if ($this->aImportCategory === null && $this->import_category_id !== null) { $this->aImportCategory = ChildImportCategoryQuery::create()->findPk($this->import_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->aImportCategory->addImports($this); */ } return $this->aImportCategory; }
/** * Performs an INSERT on the database, given a ImportCategory or Criteria object. * * @param mixed $criteria Criteria or ImportCategory 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(ImportCategoryTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ImportCategory object } if ($criteria->containsKey(ImportCategoryTableMap::ID) && $criteria->keyContainsValue(ImportCategoryTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportCategoryTableMap::ID . ')'); } // Set the correct dbName $query = ImportCategoryQuery::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; }