Created
June 24, 2014 11:34
-
-
Save jrenggli/731c9ca0321cf7052531 to your computer and use it in GitHub Desktop.
Adjust markup when migrating data from Redmine to JIRA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pattern = Array( | |
'/<pre>(\s)*<code class="(\S*)">/i', | |
'/<\/code><\/pre>/i', | |
'/<pre>/i', | |
'/<\/pre>/i', | |
'/@(\S*)@/i', | |
); | |
$replacement = Array( | |
'{code:$2}', | |
'{code}', | |
'{code}', | |
'{code}', | |
'{{$1}}', | |
); | |
$db = new PDO('mysql:host=localhost;dbname=redmine;charset=utf8', 'redmine', 'redmine'); | |
echo "MIGRATE MARKUP IN JOURNALS"; | |
$stmtNotesUpdate = $db->prepare("UPDATE journals SET notes=? WHERE id=?"); | |
foreach($db->query('SELECT id, notes FROM journals WHERE notes != ""') as $row) { | |
$id = $row['id']; | |
$note = $row['notes']; | |
echo $id . PHP_EOL; | |
$note2 = preg_replace($pattern, $replacement, $note); | |
if ($note2 === $note) { | |
continue; | |
} | |
$stmtNotesUpdate->execute(array($note2, $id)); | |
echo 'Note ' . $id . ' migrated. ' . $stmtNotesUpdate->rowCount(); | |
} | |
echo "MIGRATE MARKUP IN ISSUES"; | |
$stmtIssuesUpdate = $db->prepare("UPDATE issues SET description=? WHERE id=?"); | |
foreach($db->query('SELECT id, description FROM issues WHERE description != ""') as $row) { | |
$id = $row['id']; | |
$note = $row['description']; | |
echo $id . PHP_EOL; | |
$note2 = preg_replace($pattern, $replacement, $note); | |
if ($note2 === $note) { | |
continue; | |
} | |
$stmtIssuesUpdate->execute(array($note2, $id)); | |
echo 'Note ' . $id . ' migrated. ' . $stmtIssuesUpdate->rowCount(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment