-
Notifications
You must be signed in to change notification settings - Fork 1
/
nxCreateCategories.php
61 lines (48 loc) · 1.5 KB
/
nxCreateCategories.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
<?php
include_once "nxFramework.php";
include_once "nxCredentialsPC.php";
// -----------------------------------------
// Configuration
// -----------------------------------------
$inputCSVFileName="categories.csv";
$CSVSeparator=";";
// -------------------------------------------
// Functions reading categories from CSV files
// -------------------------------------------
function readCategoriesFromCSV($file,$CSVsep)
{
// Read input file
$inputFile=$file;
$rawCategories=file($inputFile);
$categories=array();
// Read line by line and create the array
for($i=0;$i<count($rawCategories);$i++)
{
// cleanup the line from any special character or CR/LF
$trimLine=trim($rawCategories[$i]," \t\n\r\0\x0B");
$tmp=explode($CSVsep,$trimLine);
$tmp=array_filter($tmp);
$j=0;
while($j<count($tmp))
{
$j++;
if(@$tmp[$j]!=NULL)
{
if($j==count($tmp)-1) @$categories[$tmp[0]].=$tmp[$j];
else @$categories[$tmp[0]].=$tmp[$j].",";
}
}
}
return $categories;
}
// =========================================
// Main Entry Point
// =========================================
// Read Categories from file
print("Reading categories from ".nxColorOutput($inputCSVFileName)."\n");
$categories=readCategoriesFromCSV($inputCSVFileName,$CSVSeparator);
print("Found ".nxColorOutput(count($categories))." category names\n");
// Create category
print("Creating categories in Prism Central.\n");
nxpcCreateCategory($clusterConnect,$categories);
?>