Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 48d3dd4

Browse files
committed
Added script for migrate data to new version of database structure
1 parent fa9d103 commit 48d3dd4

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55
[Added]
66
- Added details with statistics for individually SPs and IdPs
7+
- Added script for migrate data to new version of database structure
78

89
## [v1.5.0]
910
[Added]

scripts/migrate_2.0.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)