/** * Sets up the manufacturers using the YAML file. * @param $yaml string The path to the manufacturers YAML file */ public function setupManufacturers() { $count = 0; $skipped = 0; $data = Setup::loadYAML(self::MANUFACTURER_FILE); foreach ($data as $mfgname => $logos) { try { ManufacturerManager::getInstance()->getManufacturerByName($mfgname); $skipped++; } catch (\Exception $e) { $manufacturer = new Manufacturer(); $manufacturer->setName($mfgname); $this->entityManager->persist($manufacturer); foreach ($logos as $logo) { $mfglogo = new ManufacturerICLogo(); $mfglogo->setManufacturer($manufacturer); $mfglogo->replace(self::MANUFACTURER_PATH . "images/" . $logo); $mfglogo->setOriginalFilename($logo); $this->entityManager->persist($mfglogo); } $count++; } } $this->entityManager->flush(); $this->logMessage(sprintf("Imported %d Manufacturers, skipped %d because they already exist", $count, $skipped)); }
/** * Adds a new manufacturer by name * * @param string $name The manufacturer name */ public function addManufacturer($name) { $manufacturer = new Manufacturer(); $manufacturer->setName($name); PartKeepr::getEM()->persist($manufacturer); PartKeepr::getEM()->flush(); return $manufacturer; }