-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
72 lines (65 loc) · 1.4 KB
/
upload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
DROP TABLE IF EXISTS `areas`;
CREATE TABLE `areas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci;
DROP TABLE IF EXISTS `risks`;
CREATE TABLE `risks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) NOT NULL DEFAULT '0',
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci;
*/
include('includes/application.php');
Application::run('config', 'database');
$file = isset($argv[1]) ? $argv[1] : null;
if (!$file || !file_exists($file))
{
echo "File not exists: $file\n";
exit;
}
$f = fopen($file, 'r');
if (!$f)
{
echo "Cannot open file: $file\n";
exit;
}
$current = 0;
while (($row = fgetcsv($f, 200, ';')) !== false)
{
if ('id' === $row[0])
{
$current++;
continue;
}
switch ($current)
{
case 1:
$Area = new \Model\Area();
$Area->id = trim($row[0]);
$Area->name = trim($row[2]);
if ($Area->id && $Area->name)
{
$Area->saveNew();
echo "Area: {$Area->id}, {$Area->name}\n";
}
break;
case 2:
$Risk = new \Model\Risk();
$Risk->id = trim($row[0]);
$Risk->parent_id = trim($row[1]);
$Risk->name = trim($row[2]);
if ($Risk->id && $Risk->name)
{
$Risk->saveNew();
echo "Risk: {$Risk->id}, {$Risk->name}\n";
}
break;
}
}
echo "Done\n";