-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_articles.php
76 lines (63 loc) · 2.81 KB
/
export_articles.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
<?php
$servername = "7";
$username = "";
$password = "";
$dbname = "";
// Tworzenie połączenia
$conn = new mysqli($servername, $username, $password, $dbname);
// Sprawdzanie połączenia
if ($conn->connect_error) {
die("Połączenie nieudane: " . $conn->connect_error);
}
// Mapowanie kategorii
$category_map = [
1 => 8,
2 => 9,
3 => 2,
4 => 8,
5 => 9,
6 => 10,
7 => 11,
8 => 12,
9 => 8,
10 => 14,
11 => 15,
12 => 21,
13 => 22,
14 => 23,
15 => 24
];
// Pobieranie danych z tabeli jos_k2_items
$sql = "SELECT * FROM jos_k2_items";
$result = $conn->query($sql);
// Otwarcie pliku logu
$log_file = fopen("error_log.txt", "a");
if ($result->num_rows > 0) {
// Przechodzenie przez każdy wiersz
while ($row = $result->fetch_assoc()) {
$catid = isset($category_map[$row['catid']]) ? $category_map[$row['catid']] : $row['catid'];
$title = $conn->real_escape_string($row['title']);
$alias = $conn->real_escape_string($row['alias']);
$introtext = $conn->real_escape_string($row['introtext']);
$fulltext = $conn->real_escape_string($row['fulltext']);
$created_by_alias = $conn->real_escape_string($row['created_by_alias']);
$metakey = $conn->real_escape_string($row['metakey']);
$metadesc = $conn->real_escape_string($row['metadesc']);
$metadata = $conn->real_escape_string($row['metadata']);
$language = $conn->real_escape_string($row['language']);
$insert_sql = "INSERT INTO `jos_content` (`id`, `asset_id`, `title`, `alias`, `introtext`, `fulltext`, `state`, `catid`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `images`, `urls`, `attribs`, `version`, `ordering`, `metakey`, `metadesc`, `access`, `hits`, `metadata`, `featured`, `language`, `note`) VALUES (null, '0', '{$title}', '{$alias}', '{$introtext}', '{$fulltext}', '{$row['published']}', '{$catid}', '{$row['created']}', '{$row['created_by']}', '{$created_by_alias}', '{$row['modified']}', '{$row['modified_by']}', '{$row['checked_out']}', '{$row['checked_out_time']}', '{$row['publish_up']}', '{$row['publish_down']}', '', '', '', '1', '0', '{$metakey}', '{$metadesc}', '{$row['access']}', '{$row['hits']}', '{$metadata}', '{$row['featured']}', '{$language}', '')";
// Zapisanie pełnego zapytania SQL do pliku logu
fwrite($log_file, $insert_sql . "\n");
if ($conn->query($insert_sql) !== TRUE) {
// Logowanie bardziej szczegółowych komunikatów o błędach
echo "Błąd: " . $insert_sql . "<br>" . $conn->error . "<br>";
}
}
echo "Dane zostały przeniesione pomyślnie";
} else {
echo "Brak danych do przeniesienia";
}
// Zamknięcie pliku logu
fclose($log_file);
$conn->close();
?>