-
Notifications
You must be signed in to change notification settings - Fork 108
/
migrate.php
111 lines (104 loc) · 4.54 KB
/
migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
if (php_sapi_name() !== 'cli') {
echo "Only run from command line!";
die;
}
ini_set('max_execution_time', 2400);
require 'vendor/autoload.php';
require 'config.php';
require 'db.php';
$get = $dbh->prepare("SELECT `game_id`, `files`, `uploading` FROM old_gog.`games_filelist`");
$get->execute();
$old_data = $get->fetchAll(\PDO::FETCH_OBJ);
$getTimes = $dbh->prepare("SELECT `id`, UNIX_TIMESTAMP(`time_upload`) as time_upload, UNIX_TIMESTAMP(`time_update`) as time_update FROM old_gog.`games`");
$getTimes->execute();
$times = $getTimes->fetchAll(\PDO::FETCH_OBJ);
$setTime = $dbh->prepare("UPDATE `games` SET `last_update` = :update, `last_upload` = :upload WHERE `id` = :id");
$setTime->bindParam(':id', $id, \PDO::PARAM_INT);
$setTime->bindParam(':upload', $upload, \PDO::PARAM_INT);
$setTime->bindParam(':update', $update, \PDO::PARAM_INT);
foreach ($times as $key => $value) {
$id = intval($value->id);
$upload = $value->time_upload;
$update = $value->time_update;
$setTime->execute();
}
$getTags = $dbh->prepare("SELECT `id`, `updated`, `new`, `hidden` FROM old_gog.`games`");
$getTags->execute();
$tags = $getTags->fetchAll(\PDO::FETCH_OBJ);
$setTags = $dbh->prepare("UPDATE `games` SET `new` = :new, `updated` = :updated, `hidden` = :hidden WHERE `id` = :id");
$setTags->bindParam(':id', $id, \PDO::PARAM_INT);
$setTags->bindParam(':new', $new, \PDO::PARAM_INT);
$setTags->bindParam(':updated', $updated, \PDO::PARAM_INT);
$setTags->bindParam(':hidden', $hidden, \PDO::PARAM_INT);
foreach ($tags as $key => $value) {
$id = intval($value->id);
$updated = intval($value->updated);
$new = intval($value->new);
$hidden = intval($value->hidden);
$setTags->execute();
}
foreach ($old_data as $key => $value) {
if ($value->uploading == 1) {
continue;
}
$id = intval($value->game_id);
$file_info = json_decode($value->files);
foreach ($file_info as $key => $file) {
switch ($key) {
case 'goodies':
$set = $dbh->prepare("INSERT IGNORE INTO `links` (`game_id`, `link`, `type`) VALUES (:id, :link, 'GOODIES')");
foreach ($file as $key => $link) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':link', $link, \PDO::PARAM_STR);
$set->execute();
}
break;
case 'game':
$set = $dbh->prepare("INSERT IGNORE INTO `links` (`game_id`, `link`, `type`) VALUES (:id, :link, 'GAME')");
foreach ($file as $key => $link) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':link', $link, \PDO::PARAM_STR);
$set->execute();
}
break;
case 'goodies_list':
$set = $dbh->prepare("INSERT IGNORE INTO `files` (`game_id`, `name`, `type`) VALUES (:id, :name, 'GOODIES')");
foreach ($file as $key => $name) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':name', $name, \PDO::PARAM_STR);
$set->execute();
}
break;
case 'game_list':
$set = $dbh->prepare("INSERT IGNORE INTO `files` (`game_id`, `name`, `type`) VALUES (:id, :name, 'GAME')");
foreach ($file as $key => $name) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':name', $name, \PDO::PARAM_STR);
$set->execute();
}
break;
case 'patch_list':
$set = $dbh->prepare("INSERT IGNORE INTO `files` (`game_id`, `name`, `type`) VALUES (:id, :name, 'PATCHES')");
foreach ($file as $key => $name) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':name', $name, \PDO::PARAM_STR);
$set->execute();
}
break;
case 'patch':
$set = $dbh->prepare("INSERT IGNORE INTO `links` (`game_id`, `link`, `type`) VALUES (:id, :link, 'PATCHES')");
foreach ($file as $key => $link) {
$set->bindParam(':id', $id, \PDO::PARAM_INT);
$set->bindParam(':link', $link, \PDO::PARAM_STR);
$set->execute();
}
break;
default:
echo "oh shit\n";
echo $key;
die;
break;
}
}
}