public function getOrCreateStorageLocation($storageLocation)
 {
     if (is_int($storageLocation)) {
         try {
             return $this->getStorageLocation($storageLocation);
         } catch (StorageLocationNotFoundException $e) {
         }
     }
     $sl = new StorageLocation();
     $sl->setName($storageLocation);
     PartKeepr::getEM()->persist($sl);
     return $sl;
 }
 /**
  * Creates multiple storage locations at once. 
  * 
  * Requires that the parameter "storageLocations" is set to an array with the names of the storage locations.
  * Returns all error messages as "data" index in the result array.
  */
 public function massCreate()
 {
     $this->requireParameter("storageLocations");
     $aMessages = array();
     foreach ($this->getParameter("storageLocations") as $storageLocation) {
         try {
             $obj = StorageLocationManager::getInstance()->getStorageLocationByName($storageLocation);
             $aMessages[] = sprintf(PartKeepr::i18n("Storage Location %s already exists"), $storageLocation);
         } catch (\Exception $e) {
             $obj = new StorageLocation();
             $obj->setName($storageLocation);
             PartKeepr::getEM()->persist($obj);
         }
     }
     PartKeepr::getEM()->flush();
     return array("data" => $aMessages);
 }
 /**
  * Migrates the storage locations
  */
 public function run()
 {
     $count = 0;
     $skipped = 0;
     $r = mysql_query("SELECT * FROM storeloc");
     while ($store = mysql_fetch_assoc($r)) {
         $name = PartDBMigration::convertText($store["name"]);
         try {
             $storageLocation = StorageLocationManager::getInstance()->getStorageLocationByName($name);
             $skipped++;
         } catch (\Exception $e) {
             $oStorageLocation = new StorageLocation();
             $oStorageLocation->setName($name);
             $this->entityManager->persist($oStorageLocation);
             $count++;
         }
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Migrated %d storage locations, skipped %d because they already exist", $count, $skipped));
 }