-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkoken_backup.php
72 lines (60 loc) · 2.32 KB
/
koken_backup.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
<?php
parse_str(implode('&', array_slice($argv, 1)), $_GET);
error_reporting(0);
date_default_timezone_set('UTC');
if (isset($_GET['id'])) {
$album = $_GET['id'];
}
else {
die('You need to specify an album ID.' . PHP_EOL . 'example: php koken_backup.php id=12' . PHP_EOL);
}
if (isset($_SERVER['QUERY_STRING'])) {
$path = urldecode($_SERVER['QUERY_STRING']);
}
else {
if (isset($_SERVER['PATH_INFO'])) {
$path = $_SERVER['PATH_INFO'];
}
else {
if (isset($_SERVER['REQUEST_URI'])) {
$path = preg_replace('/.*\/i.php/', '', $_SERVER['REQUEST_URI']);
}
}
}
$ds = DIRECTORY_SEPARATOR;
$root = dirname(__FILE__);
$content = $root . $ds . 'storage';
require($content . $ds . 'configuration' . $ds . 'database.php');
$interface = $KOKEN_DATABASE['driver'];
if ($interface == 'mysqli') {
$db_link = mysqli_connect($KOKEN_DATABASE['hostname'], $KOKEN_DATABASE['username'], $KOKEN_DATABASE['password'], NULL, (int) $KOKEN_DATABASE['port'], $KOKEN_DATABASE['socket']);
// Get album name.
$query = "SELECT * from koken_albums where id = $album";
$db_link->select_db($KOKEN_DATABASE['database']);
$result = $db_link->query($query);
while ($row = $result->fetch_assoc()) {
$slug = $row['slug'];
mkdir($content . $ds . 'backup' . $ds . $slug, 0777, TRUE);
}
$query = "SELECT * from koken_content where id IN (select content_id from koken_join_albums_content where album_id = $album)";
$db_link->select_db($KOKEN_DATABASE['database']);
$result = $db_link->query($query);
$count_success = $count_fail = 0;
while ($row = $result->fetch_assoc()) {
$internal_path = substr($row['internal_id'], 0, 2) . $ds . substr($row['internal_id'], 2, 2);
$original = $content . $ds . 'originals' . $ds . $internal_path . $ds . $row['filename'];
$destination = $content . $ds . 'backup' . $ds . $slug . $ds . $row['filename'];
if (file_exists($original) && copy($original, $destination)) {
print_r('Copied ' . $original . ' to ' . $destination . PHP_EOL);
$count_success++;
}
else {
print_r('Failled to copy ' . $original . PHP_EOL);
$count_fail++;
}
}
$result->close();
$db_link->close();
print_r('--------------------' . PHP_EOL .
'Processed ' . ($count_success + $count_fail) . ' items (' . $count_success . ' created, ' . $count_fail . ' failed)' . PHP_EOL);
}