forked from OPSnet/Gazelle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate-logs.php
62 lines (53 loc) · 1.79 KB
/
migrate-logs.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
<?php
/* The torrents_logs.Log column no longer exists as of this commit.
* This script is left for historical purposes and for people who
* want to migrate an existing Gazelle installation.
* Similarly, the Gazelle\File\RipLog::pathLegacy() method no
* longer exists.
*/
require_once(__DIR__ . '/../lib/bootstrap.php');
ini_set('max_execution_time', -1);
define('CHUNK', 100);
$offset = 0;
$last = 0;
$processed = 0;
$newLog = 0;
$errLog = 0;
$newHtml = 0;
$errHtml = 0;
$db = Gazelle\DB::DB();
$logFiler = new Gazelle\File\RipLog();
$htmlFiler = new Gazelle\File\RipLogHTML();
while (true) {
$db->prepared_query('
SELECT LogID, TorrentID, Log
FROM torrents_logs
WHERE LogID > ?
ORDER BY LogID
LIMIT ?
', $offset, CHUNK
);
if (!$db->has_results()) {
break;
}
while (list($logId, $torrentId, $log) = $db->next_record(MYSQLI_NUM, false)) {
$last = $logId;
++$processed;
if (file_exists($logFiler->pathLegacy([$torrentId, $logId])) && !file_exists($logFiler->path([$torrentId, $logId]))) { /** @phpstan-ignore-line */
if (!copy($logFiler->pathLegacy([$torrentId, $logId]), $logFiler->path([$torrentId, $logId]))) { /** @phpstan-ignore-line */
++$errLog;
}
++$newLog;
}
if (!file_exists($htmlFiler->path([$torrentId, $logId]))) {
if (!$htmlFiler->put($log, [$torrentId, $logId])) {
++$errHtml;
}
$htmlFiler->put($log . "\n", [$torrentId, $logId]);
++$newHtml;
}
}
printf("begin %7d end %7d processed %7d / log %7d error %7d / html %7d error %7d\n",
$offset, $last, $processed, $newLog, $errLog, $newHtml, $errHtml);
$offset = $last;
}