1+ <?php
2+ /**
3+ *
4+ * Script for migrate statistics data from version < 1.6.x to version > 2.0.0
5+ *
6+ * You need firstly export the tables identityProviders and serviceProviders into two separate CSV files.
7+ *
8+ * The result file is in text format as SQL inserts.
9+ *
10+ * How to run this script:
11+ * php -f migrate_2.0.php
12+ *
13+ * @author: Pavel Vyskocil <[email protected] > 14+ */
15+
16+ // Absolute path to CSV file with data about identityProviders
17+ $ identityProvidersFileName = '' ;
18+
19+ // Absolute path to CSV file with data about serviceProviders
20+ $ serviceProvidersFileName = '' ;
21+
22+ // Absolute path where result file will be stored
23+ $ resultFileName = '' ;
24+
25+ if (empty ($ identityProvidersFileName ) || empty ($ serviceProvidersFileName ) || empty ($ resultFileName )) {
26+ exit ("One of required attributes is empty. " . PHP_EOL );
27+ }
28+
29+ $ tableName = 'statistics ' ;
30+
31+ $ result = '' ;
32+ $ line = null ;
33+
34+ // Identity providers part
35+ $ file = fopen ($ identityProvidersFileName ,"r " );
36+
37+ while (!feof ($ file ))
38+ {
39+ $ line =(fgetcsv ($ file ));
40+ if ($ line != null ) {
41+ $ lineInsert = 'INSERT INTO ' . $ tableName . '(year, month, day, sourceIdp, service, count) VALUES( ' . $ line [0 ] . ', ' . $ line [1 ] . ', ' . $ line [2 ] . ', " ' . $ line [3 ] . '","" , ' . $ line [4 ] . '); ' . PHP_EOL ;
42+ $ result .= $ lineInsert ;
43+ }
44+ }
45+
46+ fclose ($ file );
47+
48+ // Service providers part
49+ $ file = fopen ($ serviceProvidersFileName ,"r " );
50+
51+ while (!feof ($ file ))
52+ {
53+ $ line =(fgetcsv ($ file ));
54+ if ($ line != null ) {
55+ $ lineInsert = 'INSERT INTO ' . $ tableName . '(year, month, day, sourceIdp, service, count) VALUES( ' . $ line [0 ] . ', ' . $ line [1 ] . ', ' . $ line [2 ] . ', "", " ' . $ line [3 ] . '", ' . $ line [4 ] . '); ' . PHP_EOL ;
56+ $ result .= $ lineInsert ;
57+ }
58+ }
59+
60+ fclose ($ file );
61+
62+ // save to result file
63+ file_put_contents ($ resultFileName , $ result );
0 commit comments