|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* allows the creation of distributors from a CSV |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class ImportDistributorsTask extends ImportStockistsTask |
|
9
|
|
|
{ |
|
10
|
|
|
protected $title = "Import all the Distributors"; |
|
11
|
|
|
|
|
12
|
|
|
protected $description = "Does not delete any record, it only updates and adds."; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* excluding base folder |
|
16
|
|
|
* |
|
17
|
|
|
* e.g. assets/files/mycsv.csv |
|
18
|
|
|
* @var String |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $fileLocation = "assets/Uploads/distributors.csv"; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
public function run($request) |
|
26
|
|
|
{ |
|
27
|
|
|
increase_time_limit_to(3600); |
|
28
|
|
|
set_time_limit(3600); |
|
29
|
|
|
increase_memory_limit_to('1024M'); |
|
30
|
|
|
$this->readFile(); |
|
31
|
|
|
$this->createDistributors(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* |
|
36
|
|
|
* here we actuall |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function createDistributors() |
|
39
|
|
|
{ |
|
40
|
|
|
flush(); |
|
41
|
|
|
ob_end_flush(); |
|
42
|
|
|
DB::alteration_message("================================================ CREATING distributors ================================================"); |
|
43
|
|
|
ob_start(); |
|
44
|
|
|
$distributorsCompleted = array(); |
|
|
|
|
|
|
45
|
|
|
$rowCount = 0; |
|
46
|
|
|
foreach ($this->csv as $row) { |
|
47
|
|
|
$rowCount++; |
|
48
|
|
|
//distributor page |
|
49
|
|
|
$name = trim($row["NAME"]); |
|
50
|
|
|
$distributor = Distributor::get()->filter(array("Name" => $name))->first(); |
|
51
|
|
|
if (!$distributor) { |
|
52
|
|
|
$distributor = new Distributor(); |
|
53
|
|
|
$distributor->Address1 = $row["ENTEREDADDRESS"]; |
|
|
|
|
|
|
54
|
|
|
flush(); |
|
55
|
|
|
ob_end_flush(); |
|
56
|
|
|
DB::alteration_message(" --- Creating distributor: ".$row["NAME"], "created"); |
|
57
|
|
|
ob_start(); |
|
58
|
|
|
} else { |
|
59
|
|
|
flush(); |
|
60
|
|
|
ob_end_flush(); |
|
61
|
|
|
DB::alteration_message(" --- Updating distributor: ".$row["NAME"], "changed"); |
|
62
|
|
|
ob_start(); |
|
63
|
|
|
} |
|
64
|
|
|
$distributor->Name = $name; |
|
65
|
|
|
$distributor->IsDefault = false; |
|
66
|
|
|
$distributor->Email = $row["EMAIL"]; |
|
67
|
|
|
$distributor->Phone = $row["PHONE"]; |
|
68
|
|
|
$distributor->DisplayEmail = $row["EMAIL"]; |
|
69
|
|
|
$distributor->WebAddress = $row["WEB"]; |
|
70
|
|
|
$distributor->write(); |
|
71
|
|
|
} |
|
72
|
|
|
flush(); |
|
73
|
|
|
ob_end_flush(); |
|
74
|
|
|
DB::alteration_message("====================== END =========================="); |
|
75
|
|
|
ob_start(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.