1 |
569211e8
|
Julien Enselme
|
# In the expat website, when we try to migarte it, the images not found
|
2 |
|
|
# and the only solution we found is to use this script to patch its database
|
3 |
|
|
# and so repair the links
|
4 |
|
|
|
5 |
|
|
use strict;
|
6 |
|
|
use warnings;
|
7 |
|
|
use DBI;
|
8 |
|
|
|
9 |
|
|
my $db = 'expat';
|
10 |
|
|
my $server = 'localhost';
|
11 |
|
|
my $user = 'root';
|
12 |
|
|
my $password = 'tata';
|
13 |
|
|
my $port = '';
|
14 |
|
|
|
15 |
|
|
#### Create DB connection
|
16 |
|
|
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$server;port=$port", $user, $password, { RaiseError => 1, }) or die "Cannont connect to database $db";
|
17 |
|
|
|
18 |
|
|
# Update user's pictures
|
19 |
|
|
|
20 |
|
|
my $sql_select =<<"SQL";
|
21 |
|
|
SELECT uid, picture FROM expat_users
|
22 |
|
|
SQL
|
23 |
|
|
|
24 |
|
|
my $sql_update =<<"SQL";
|
25 |
|
|
UPDATE expat_users SET picture = ? WHERE uid = ?
|
26 |
|
|
SQL
|
27 |
|
|
|
28 |
|
|
my $req_select = $dbh->prepare($sql_select);
|
29 |
|
|
my $req_update = $dbh->prepare($sql_update);
|
30 |
|
|
$req_select->execute;
|
31 |
|
|
|
32 |
|
|
while (my ($uid, $picture) = $req_select->fetchrow_array)
|
33 |
|
|
{
|
34 |
|
|
$picture =~ s#sites/assos.centrale-marseille.fr.expat/(.*)#sites/default/$1#;
|
35 |
|
|
$req_update->execute($picture, $uid);
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
$req_update->finish;
|
39 |
|
|
$req_select->finish;
|
40 |
|
|
|
41 |
|
|
# Update other file
|
42 |
|
|
$sql_select = "SELECT fid, filepath FROM expat_files";
|
43 |
|
|
$sql_update = "UPDATE expat_files SET filepath = ? WHERE fid = ?";
|
44 |
|
|
|
45 |
|
|
$req_select = $dbh->prepare($sql_select);
|
46 |
|
|
$req_update = $dbh->prepare($sql_update);
|
47 |
|
|
$req_select->execute;
|
48 |
|
|
|
49 |
|
|
while (my ($fid, $file_path) = $req_select->fetchrow_array)
|
50 |
|
|
{
|
51 |
|
|
$file_path =~ s#sites/assos.centrale-marseille.fr.expat/(.*)#sites/default/$1#;
|
52 |
|
|
$req_update->execute($file_path, $fid);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
$req_update->finish;
|
56 |
|
|
$req_select->finish;
|
57 |
|
|
|
58 |
|
|
$dbh->disconnect; |