protected function importCustomers(\PDO $dbh, EntityManager $em) { $count = 0; $sth = $dbh->prepare('SELECT * FROM customer'); $sth->execute(); foreach ($sth->fetchAll(\PDO::FETCH_ASSOC) as $row) { if (empty($row['name'])) { // Do not import records with empty name. continue; } $customer = new Customer(); $customer->setName($row['name']); if ($row['identification'] && $row['identification'] !== 'Client Legal Id') { $customer->setIdentification($row['identification']); } $email = $row['email']; // In previous version email was optional. if (!$email) { $email = strtolower(str_replace(' ', '-', $name)) . '@upgradefrom04.fixme'; } $customer->setEmail($email); $customer->setContactPerson($row['contact_person']); $customer->setInvoicingAddress($row['invoicing_address']); $customer->setShippingAddress($row['shipping_address']); $em->persist($customer); $count++; } return $count; }