From 4eb178a51f91dec315ce3de7089bffd6bcbf8d22 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 30 Jul 2010 17:58:44 -0300 Subject: Fixes around getEntity --- lib/sfIsisImporter.class.php | 28 +++++++++++++++++++++++++--- lib/sfIsisImporterManager.class.php | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/sfIsisImporter.class.php b/lib/sfIsisImporter.class.php index 4fd6353..45046db 100644 --- a/lib/sfIsisImporter.class.php +++ b/lib/sfIsisImporter.class.php @@ -243,17 +243,39 @@ class sfIsisImporter extends IsisConnector } } + /** + * Get an existing entity. + * + * @param string $entity Entity name + * @param string $value Value to search for + * @param string $by Field to search $value + * @return mixed Entity data or false + */ + public function getEntity($entity, $value, $by = 'name') + { + $findby = 'findOneBy'. ucfirst($by); + $data = Doctrine_Core::getTable($entity)->{$findby}($value); + + if (!$data) + { + return $data; + } + + return false; + } + /** * Add a new entity into the database if needed, returning * the corresponding object. * - * @param string $name Genre name - * @return Genre Genre data + * @param string $entity Entity name + * @param string $name Name value + * @return object Entity data */ public function addEntity($entity, $name) { $name = $this->entityName($name); - $data = Doctrine_Core::getTable($entity)->findOneByName($name); + $data = $this->getEntity($entity, $name); if (!$data) { diff --git a/lib/sfIsisImporterManager.class.php b/lib/sfIsisImporterManager.class.php index 756de8c..24b483e 100644 --- a/lib/sfIsisImporterManager.class.php +++ b/lib/sfIsisImporterManager.class.php @@ -100,6 +100,7 @@ class sfIsisImporterManager extends IsisConnector } } + ksort($databases); return $databases; } -- cgit v1.2.3