/** * Creates a new distributor with the given name. * @param string $name The name of the distributor * @return Distributor The new distributor object */ public function addDistributor($name) { $distributor = new Distributor(); $distributor->setName($name); PartKeepr::getEM()->persist($distributor); PartKeepr::getEM()->flush(); return $distributor; }
/** * Migrates the existing distributors */ public function run() { $count = 0; $skipped = 0; $r = mysql_query("SELECT * FROM suppliers"); while ($supplier = mysql_fetch_assoc($r)) { $name = PartDBMigration::convertText($supplier["name"]); try { $distributor = DistributorManager::getInstance()->getDistributorByName($name); $skipped++; } catch (\Exception $e) { $distributor = new Distributor(); $distributor->setName($name); $this->entityManager->persist($distributor); $count++; } } $this->entityManager->flush(); $this->logMessage(sprintf("Migrated %d distributors, skipped %d because they already exist", $count, $skipped)); }