CC-2282 Import script does not restore storage from backup if database is intact

not considering a duplicate to exist just because there's a row in the database, checking if its file exists on the system as well.
This commit is contained in:
Naomi 2011-05-20 16:10:22 -04:00 committed by Paul Baranowski
parent 05e02f6081
commit 71ac8d4b1b
2 changed files with 52 additions and 8 deletions

View file

@ -734,7 +734,14 @@ class StoredFile {
$storedFile->mtime = $row['mtime']; $storedFile->mtime = $row['mtime'];
$storedFile->md5 = $row['md5']; $storedFile->md5 = $row['md5'];
$storedFile->filepath = $row['filepath']; $storedFile->filepath = $row['filepath'];
$storedFile->exists = TRUE;
if(file_exists($row['filepath'])) {
$storedFile->exists = true;
}
else {
$storedFile->exists = false;
}
$storedFile->setFormat($row['ftype']); $storedFile->setFormat($row['ftype']);
return $storedFile; return $storedFile;
} }
@ -867,7 +874,7 @@ class StoredFile {
* local path * local path
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function replaceFile($p_localFilePath) public function replaceFile($p_localFilePath, $p_copyMedia=TRUE)
{ {
// Dont do anything if the source and destination files are // Dont do anything if the source and destination files are
// the same. // the same.
@ -881,7 +888,7 @@ class StoredFile {
return $r; return $r;
} }
} }
return $this->addFile($p_localFilePath); return $this->addFile($p_localFilePath, $p_copyMedia);
} }
@ -1783,8 +1790,17 @@ class StoredFile {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}'); die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
} }
else { else {
$duplicateName = $duplicate->getMetadataValue(UI_MDATA_KEY_TITLE); if(file_exists($duplicate->getRealFilePath())) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}'); $duplicateName = $duplicate->getMetadataValue(UI_MDATA_KEY_TITLE);
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}');
}
else{
$res = $duplicate->replaceFile($audio_file);
if (PEAR::isError($res)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
}
return $duplicate;
}
} }
} }

View file

@ -112,6 +112,7 @@ function import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = fals
global $STORAGE_SERVER_PATH; global $STORAGE_SERVER_PATH;
global $g_fileCount; global $g_fileCount;
global $g_duplicates; global $g_duplicates;
global $g_replaced;
// Check parameters // Check parameters
$p_importMode = strtolower($p_importMode); $p_importMode = strtolower($p_importMode);
@ -204,9 +205,32 @@ function import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = fals
// Look up md5sum in database // Look up md5sum in database
$duplicate = StoredFile::RecallByMd5($md5sum); $duplicate = StoredFile::RecallByMd5($md5sum);
if ($duplicate) { if (PEAR::isError($duplicate)) {
echo "DUPLICATE: $p_filepath\n"; echo $duplicate->getMessage();
$g_duplicates++; echo "\n";
}
//row exists in database
if(isset($duplicate)) {
if (file_exists($duplicate->getRealFilePath())) {
echo "DUPLICATE: $p_filepath\n";
$g_duplicates++;
}
else{
if ($p_importMode == "copy") {
$doCopyFiles = true;
}
else if ($p_importMode == "link") {
$doCopyFiles = false;
}
$res = $duplicate->replaceFile($p_filepath, $doCopyFiles);
if (PEAR::isError($res)) {
echo $res->getMessage();
echo "\n";
return;
}
$g_replaced++;
}
return; return;
} }
@ -323,7 +347,10 @@ if ( ($importMode == "copy") && !is_writable($CC_CONFIG["storageDir"])) {
global $g_fileCount; global $g_fileCount;
global $g_duplicates; global $g_duplicates;
global $g_replaced;
$g_fileCount = 0; $g_fileCount = 0;
$g_duplicates = 0;
$g_replaced = 0;
if (is_array($files)) { if (is_array($files)) {
foreach ($files as $filepath) { foreach ($files as $filepath) {
// absolute path // absolute path
@ -356,6 +383,7 @@ if ($importMode == "copy") {
echo " *** Destination folder: ".$CC_CONFIG['storageDir']."\n"; echo " *** Destination folder: ".$CC_CONFIG['storageDir']."\n";
} }
echo " *** Files imported: $g_fileCount\n"; echo " *** Files imported: $g_fileCount\n";
echo " *** Files restored: $g_replaced\n";
echo " *** Duplicate files (not imported): $g_duplicates\n"; echo " *** Duplicate files (not imported): $g_duplicates\n";
if ($g_errors > 0) { if ($g_errors > 0) {
echo " *** Errors: $g_errors\n"; echo " *** Errors: $g_errors\n";