Created
December 5, 2012 00:06
-
-
Save abma/4210521 to your computer and use it in GitHub Desktop.
script to move database store attachments to disk in mantisbt, see http://www.mantisbt.org/bugs/view.php?id=7176
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
<pre> | |
<?php | |
include('../../springpw.php'); | |
mysql_connect($spring_dbhost, $spring_dbuser, $spring_dbpass); | |
mysql_select_db($spring_dbname); | |
$res = mysql_query("SELECT f.id, filename, filesize, p.file_path | |
FROM mantis_bug_file_table f | |
LEFT JOIN mantis_bug_table b ON f.bug_id = b.id | |
LEFT JOIN mantis_project_table p ON b.project_id = p.id | |
WHERE content<>''"); | |
while ($row = mysql_fetch_array($res)) | |
{ | |
$res2 = mysql_query("SELECT content from mantis_bug_file_table WHERE id = ".$row['id']); | |
$file = mysql_fetch_array($res2); | |
print "size: ".$row['filesize']." id: ".$row['id'] ."\n"; | |
$sha1 = sha1($file['content']); | |
$filename = $sha1.'-'.$row['id']; | |
$full_filename = $row['file_path'].$filename; | |
if (file_exists($full_filename)) | |
{ | |
printf("file already exists\n"); | |
if($sha1 == sha1(file_get_contents($full_filename))) { | |
printf("file is identical!\n"); | |
} else { | |
die("file is not identical!\n"); | |
} | |
} | |
$size = file_put_contents($full_filename, $file['content']); | |
if ($row['filesize'] == $size) { | |
$query="UPDATE mantis_bug_file_table SET diskfile ='" .$filename."', folder = '".$row['file_path']."', content='' WHERE id = ".$row['id']; | |
echo $query."\n"; | |
mysql_query($query); | |
} else { | |
die("filesize missmatch: ".$size." expected:".$row['filesize']."\n"); | |
} | |
ob_flush(); | |
flush(); | |
} | |
?> | |
</pre> |
yep, but its meant to be run only once, so this can be safely ignored...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where the file is not identical, it calls die but this means there's no closing pre tag?