Add csv files and initial import script for customer and jo migration #52
This commit is contained in:
parent
9e2cb60212
commit
30494f9889
5 changed files with 1033226 additions and 0 deletions
323910
data/Contacts.csv
Normal file
323910
data/Contacts.csv
Normal file
File diff suppressed because it is too large
Load diff
375903
data/JO 2016.csv
Normal file
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
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
76622
data/JO 2018.csv
Normal file
File diff suppressed because one or more lines are too long
102
src/Command/ImportCustomerCommand.php
Normal file
102
src/Command/ImportCustomerCommand.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue