Created
June 7, 2013 18:03
-
-
Save 01-Scripts/5731171 to your computer and use it in GitHub Desktop.
Reconnect commits that were imported into Mantis using the Source integration plugin but weren't linked to the correct issues.
This file contains 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 | |
// MySQL-Einstellungen: | |
$host = "localhost"; //Host/Server ihrer Mysql-Datenbank | |
$database = "test"; //Datenbankname | |
$user = "user"; //Usernamen für Mysql-Datenbank | |
$passw = ""; //Passwort zur Mysql-Datenbank | |
$table = "mantis_plugin_source_changeset_table"; | |
$bugtable = "mantis_plugin_Source_bug_table"; | |
//Connect to MySQL-DB | |
$db = @mysql_connect($host, $user, $passw) | |
or die ("Verbindungsaufnahme mit der MySQL-Server war <b>nicht</b> erfolgreich!<br />Bitte gehen Sie nochmals zurück.<br />Sollte weiterhin keine Verbindung zum MySQL-Server zu Stande kommen wenden Sie sich an den technischen Ansprechparnter"); | |
@mysql_select_db($database, $db) | |
or die ("Verbindungsaufnahme mit Datenbank war <b>nicht</b> erfolgreich!<br />Bitte gehen Sie nochmals zurück.<br />Sollte weiterhin keine Verbindung zur MySQL-Datenbank zu Stande kommen wenden Sie sich an den technischen Ansprechparnter"); | |
//Connect!!ED!! to MySQL-DB | |
$posts = mysql_query("SELECT * FROM ".$table.""); | |
while($row = mysql_fetch_array($posts)) | |
{ | |
//preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) | |
$matches = array(); | |
preg_match ( "/(?:#(?:\d+)[,\.\s]*)+/i" , $row['message'] , $matches); | |
if(!empty($matches)){ | |
$nr = array(); | |
preg_match ( "/#?(\d+)/" , $matches[0] , $nr); | |
echo $nr[1].": ".$row['message']."<br />"; | |
//print_r($nr); | |
$sql_insert = "INSERT INTO ".$bugtable." (change_id, bug_id) VALUES ('".$row['id']."', '".$nr[1]."')"; | |
$result = mysql_query($sql_insert, $db); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please make a backup of your the two mentioned mysql tables before you run that little script.
Please make sure to use the correct Regex pattern from your plugins settings page in line 25 and 29!