Subversion Repositories computer_asset_manager_v1

Rev

Rev 80 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 81
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
   /*
3
   /*
4
    * This script populates the device_attrib table in CAMP v1 from a tab delimited text file.
4
    * This script populates the device_attrib table in CAMP v1 from a tab delimited text file. Filename may be passed as the
-
 
5
    * only parameter on the cli, or the system can be used as a filter, ie read from STDIN
5
    * 
6
    * 
6
    * File should have a minimum of four columns and the first line should be headers as follows (case sensitive):
7
    * File should have a minimum of four columns and the first line should be headers as follows (case sensitive):
7
    * device    - should have case sensitive full name of something in the device table
8
    * device    - should have case sensitive full name of something in the device table
8
    * attribute - should have case sensitive full name of something in the attrib table
9
    * attribute - should have case sensitive full name of something in the attrib table
9
    * value     - What should be placed in the value column of device_attrib
10
    * value     - What should be placed in the value column of device_attrib
10
    * All other columns are ignored.
11
    * All other columns are ignored.
11
    *
12
    *
12
    * If an attribute name is not found, it is added to the attrib table. If device is not found, no entry is made.
13
    * If an attribute name is not found, it is added to the attrib table. If device is not found, no entry is made.
13
    *
14
    *
14
    * Script designed to run from cli.
15
    * Script designed to run from cli.
15
    * 1. Put full path/filename in the $filename variable below
-
 
16
    * 2. From cli, run 'php ./bulkLoadAttribs.php > out.sql
16
    * 1. From cli, run 'php ./bulkLoadAttribs.php tabdelimfile.csv > out.sql
17
    * 3. (optional) open out.sql in text editor to review
17
    * 2. (optional) open out.sql in text editor to review
18
    * 4. From cli, run 'mysql -u root -p camp < out.sql'
18
    * 3. From cli, run 'mysql -u root -p camp < out.sql'
19
    *
19
    *
20
    * If you're positive about the data you are importing, you can combine steps 2-4 as
20
    * If you're positive about the data you are importing, you can combine steps 2-4 as
21
    * php ./bulkLoadAttribs.php | mysql -u root -p camp
21
    * php ./bulkLoadAttribs.php tabdelimfile.csv | mysql -u root -p camp
22
    *
22
    *
23
    * Information should be loaded in database.
23
    * Information should be loaded in database.
24
    */
24
    */
25
 
25
 
26
 
26
 
Line 51... Line 51...
51
   function escapeforDB( $value ) {
51
   function escapeforDB( $value ) {
52
      return "'" . mysql_escape_string( $value ) . "'";
52
      return "'" . mysql_escape_string( $value ) . "'";
53
   }
53
   }
54
 
54
 
55
   // Name of file to import
55
   // Name of file to import
56
   $filename = '/home/rodolico/www/web/computer_asset_manager_v1/device_attributes.csv';
56
   $filename = 'php://stdin';
-
 
57
   if ( isset( $argv[1] ) ) {
-
 
58
      $filename = $argv[1];
-
 
59
   }
-
 
60
   
57
   // get data from import file and load it into $data. Read loadCSV
61
   // get data from import file and load it into $data. Read loadCSV
58
   $data = loadCSV( $filename );
62
   $data = loadCSV( $filename );
59
 
63
 
60
   // we'll put our SQL into an array, then dump it.
64
   // we'll put our SQL into an array, then dump it.
61
   $sql = array();
65
   $sql = array();