Resolve "Migrate contact and job order scripts" #861

Merged
jankstudio merged 4 commits from 52-migrate-contact-and-job-order-scripts into master 2018-03-21 19:24:51 +00:00
5 changed files with 1033226 additions and 0 deletions
Showing only changes of commit 30494f9889 - Show all commits

323910
data/Contacts.csv Normal file

File diff suppressed because it is too large Load diff

375903
data/JO 2016.csv Normal file

File diff suppressed because one or more lines are too long

256689
data/JO 2017.csv Normal file

File diff suppressed because one or more lines are too long

76622
data/JO 2018.csv Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,102 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use DateTime;
use App\Entity\Customer;
class ImportCustomerCommand extends Command
{
protected $em;
public function __construct(ObjectManager $em)
{
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this->setName('customer:import')
->setDescription('Import a CSV file with customers.')
->setHelp('Creates customers based on imported CSV.')
->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$csv_file = $input->getArgument('file');
/*
CSV column order:
0 - internal id
1 - name
2 - duplicate (yes or blank)
3 - date created
4 - date last modified
5 - phone
6 - company (plate number)
7 - email
8 - login access
9 - fax
10 - billing address 1 (blank)
11 - billing address 2 (blank)
12 - billing city (blank)
13 - billing state / province (blank)
14 - billing zip (blank)
15 - billing country (blank)
16 - job title (blank)
17 - category (blank)
18 - office phone
19 - mobile phone
20 - home phone
21 - date created
22 - date last modified
23 - first name
24 - last name
25 - login access
26 - role
*/
// attempt to open file
try
{
$fh = fopen($csv_file, "r");
}
catch (Exception $e)
{
throw new Exception('The file "' . $csv_file . '" could be read.');
}
// get entity manager
$em = $this->em;
$row_num = 1;
while (($fields = fgetcsv($fh)) !== false)
{
$output->writeln("Parsing row " . $row_num . "...");
// ignore first row
if ($row_num == 1)
{
$row_num++;
continue;
}
$id = trim($fields[0]);
$fname = trim($fields[23]);
$lname = trim($fields[24]);
$output->writeln($id . ' - ' . $fname . ' ' . $lname);
}
}
}