Skip to content

Instantly share code, notes, and snippets.

@flashwave
Created March 3, 2019 17:34
Show Gist options
  • Save flashwave/4f23618b99c9713af1278a785c4a059d to your computer and use it in GitHub Desktop.
Save flashwave/4f23618b99c9713af1278a785c4a059d to your computer and use it in GitHub Desktop.
sakura changelog export script
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
try {
$database = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=flash_sakura_changelog', '', '');
} catch (Exception $ex) {
die($ex->getMessage());
}
$tagOffset = (int)($_GET['tag_offset'] ?? 1);
$contributors = [
1 => 1,
2 => 3,
3 => 'NULL',
4 => 3,
];
$actions = [
0 => 'NULL',
1 => 1,
2 => 3,
3 => 4,
4 => 2,
5 => 5,
6 => 6,
];
$query = "INSERT INTO `msz_changelog_changes`\n";
$query .= " (`user_id`, `action_id`, `change_created`, `change_log`)\n";
$query .= "VALUES\n";
$changes = $database->query('
SELECT
CONCAT(`change_date`, " 00:00:00") as `change_created`,
`change_action` as `action_id`,
`change_message` as `change_log`,
`change_contributor` as `user_id`
FROM `changelog_entries`
')->fetchAll(PDO::FETCH_ASSOC);
$index = 0;
$count = count($changes);
foreach ($changes as $change) {
$query .= ' ';
$query .= "({$contributors[$change['user_id']]}, {$actions[$change['action_id']]}, '{$change['change_created']}', ";
$query .= $database->quote($change['change_log']);
$query .= ")";
$query .= (++$index >= $count) ? ";\n" : ",\n";
}
header('Content-Type: text/plain');
echo $query . "\n\n";
echo <<<EOF
INSERT INTO `msz_changelog_changes_tags`
(`change_id`, `tag_id`)
VALUES\n
EOF;
$tagsCount = count($changes);
$tagIndex = 0;
for ($i = $tagOffset; $i < $tagsCount + $tagOffset; $i++) {
echo " ({$i}, 1), ({$i}, 5)" . (++$tagIndex >= $tagsCount ? ';' : ',') . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment