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:
parent
05e02f6081
commit
71ac8d4b1b
2 changed files with 52 additions and 8 deletions
|
@ -734,7 +734,14 @@ class StoredFile {
|
|||
$storedFile->mtime = $row['mtime'];
|
||||
$storedFile->md5 = $row['md5'];
|
||||
$storedFile->filepath = $row['filepath'];
|
||||
$storedFile->exists = TRUE;
|
||||
|
||||
if(file_exists($row['filepath'])) {
|
||||
$storedFile->exists = true;
|
||||
}
|
||||
else {
|
||||
$storedFile->exists = false;
|
||||
}
|
||||
|
||||
$storedFile->setFormat($row['ftype']);
|
||||
return $storedFile;
|
||||
}
|
||||
|
@ -867,7 +874,7 @@ class StoredFile {
|
|||
* local path
|
||||
* @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
|
||||
// the same.
|
||||
|
@ -881,7 +888,7 @@ class StoredFile {
|
|||
return $r;
|
||||
}
|
||||
}
|
||||
return $this->addFile($p_localFilePath);
|
||||
return $this->addFile($p_localFilePath, $p_copyMedia);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1783,9 +1790,18 @@ class StoredFile {
|
|||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
|
||||
}
|
||||
else {
|
||||
if(file_exists($duplicate->getRealFilePath())) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$metadata = Metadata::LoadFromFile($audio_file);
|
||||
|
|
|
@ -112,6 +112,7 @@ function import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = fals
|
|||
global $STORAGE_SERVER_PATH;
|
||||
global $g_fileCount;
|
||||
global $g_duplicates;
|
||||
global $g_replaced;
|
||||
|
||||
// Check parameters
|
||||
$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
|
||||
$duplicate = StoredFile::RecallByMd5($md5sum);
|
||||
if ($duplicate) {
|
||||
if (PEAR::isError($duplicate)) {
|
||||
echo $duplicate->getMessage();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -323,7 +347,10 @@ if ( ($importMode == "copy") && !is_writable($CC_CONFIG["storageDir"])) {
|
|||
|
||||
global $g_fileCount;
|
||||
global $g_duplicates;
|
||||
global $g_replaced;
|
||||
$g_fileCount = 0;
|
||||
$g_duplicates = 0;
|
||||
$g_replaced = 0;
|
||||
if (is_array($files)) {
|
||||
foreach ($files as $filepath) {
|
||||
// absolute path
|
||||
|
@ -356,6 +383,7 @@ if ($importMode == "copy") {
|
|||
echo " *** Destination folder: ".$CC_CONFIG['storageDir']."\n";
|
||||
}
|
||||
echo " *** Files imported: $g_fileCount\n";
|
||||
echo " *** Files restored: $g_replaced\n";
|
||||
echo " *** Duplicate files (not imported): $g_duplicates\n";
|
||||
if ($g_errors > 0) {
|
||||
echo " *** Errors: $g_errors\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue