1
|
# When annales was migrated, informations about the cas usernames where lost
|
2
|
# resulting in the impossibility to log with cas. This script patch the database
|
3
|
# by copying uid and names from the users table to uid and cas_name in the cas_user table
|
4
|
|
5
|
use strict;
|
6
|
use warnings;
|
7
|
use DBI;
|
8
|
|
9
|
my $bd = 'annales';
|
10
|
my $serveur = 'localhost'; # Il est possible de mettre une adresse IP
|
11
|
my $identifiant = 'root'; # identifiant
|
12
|
my $motdepasse = 'tata';
|
13
|
my $port = '';
|
14
|
|
15
|
|
16
|
##### Create DB connection
|
17
|
my $dbh = DBI->connect( "DBI:mysql:database=$bd;host=$serveur;port=$port", $identifiant, $motdepasse, { RaiseError => 1, } ) or die "Connection impossible à la base de données $bd !\n $! \n $@\n$DBI::errstr";
|
18
|
|
19
|
my $sql_select =<<"SQL";
|
20
|
SELECT uid, name FROM users
|
21
|
SQL
|
22
|
|
23
|
my $sql_insert =<<"SQL";
|
24
|
INSERT INTO cas_user (aid, uid, cas_name)
|
25
|
VALUES (?, ?, ?)
|
26
|
SQL
|
27
|
|
28
|
my $req_select = $dbh->prepare($sql_select);
|
29
|
my $req_insert = $dbh->prepare($sql_insert);
|
30
|
|
31
|
$req_select->execute;
|
32
|
|
33
|
my $aid = 1;
|
34
|
|
35
|
while (my ($uid, $name) = $req_select->fetchrow_array)
|
36
|
{
|
37
|
$req_insert->execute($aid, $uid, $name);
|
38
|
$aid++;
|
39
|
}
|
40
|
|
41
|
$req_insert->finish;
|
42
|
$req_select->finish;
|
43
|
|
44
|
$dbh->disconnect;
|