more testing of attach_move() uncovered some issues
This commit is contained in:
parent
38e99c8354
commit
ce13fef6aa
@ -2286,33 +2286,22 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
|
|||||||
if(! ($c && $resource_id))
|
if(! ($c && $resource_id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
// find the resource to be moved
|
||||||
|
|
||||||
$r = q("select * from attach where hash = '%s' and uid = %d limit 1",
|
$r = q("select * from attach where hash = '%s' and uid = %d limit 1",
|
||||||
dbesc($resource_id),
|
dbesc($resource_id),
|
||||||
intval($channel_id)
|
intval($channel_id)
|
||||||
);
|
);
|
||||||
if(! $r)
|
if(! $r) {
|
||||||
|
logger('resource_id not found');
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$oldstorepath = dbunescbin($r[0]['content']);
|
$oldstorepath = dbunescbin($r[0]['content']);
|
||||||
|
|
||||||
if($r[0]['is_dir']) {
|
|
||||||
$move_success = true;
|
|
||||||
$x = q("select hash from attach where folder = '%s' and uid = %d",
|
|
||||||
dbesc($r[0]['hash']),
|
|
||||||
intval($channel_id)
|
|
||||||
);
|
|
||||||
if($x) {
|
|
||||||
foreach($x as $xv) {
|
|
||||||
$rs = attach_move($channel_id,$xv['hash'],$r[0]['hash']);
|
|
||||||
if(! $rs) {
|
|
||||||
$move_success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $move_success;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// find the resource we are moving to
|
||||||
|
|
||||||
if($new_folder_hash) {
|
if($new_folder_hash) {
|
||||||
$n = q("select * from attach where hash = '%s' and uid = %d and is_dir = 1 limit 1",
|
$n = q("select * from attach where hash = '%s' and uid = %d and is_dir = 1 limit 1",
|
||||||
@ -2326,6 +2315,10 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
|
|||||||
$newstorepath = dbunescbin($n[0]['content']) . '/' . $resource_id;
|
$newstorepath = dbunescbin($n[0]['content']) . '/' . $resource_id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// root directory
|
||||||
|
|
||||||
|
$newdirname = EMPTY_STR;
|
||||||
$newstorepath = 'store/' . $c['channel_address'] . '/' . $resource_id;
|
$newstorepath = 'store/' . $c['channel_address'] . '/' . $resource_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2335,6 +2328,10 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
|
|||||||
|
|
||||||
$filename = $r[0]['filename'];
|
$filename = $r[0]['filename'];
|
||||||
|
|
||||||
|
// don't do duplicate check unless our parent folder has changed.
|
||||||
|
|
||||||
|
if($r[0]['folder'] !== $new_folder_hash) {
|
||||||
|
|
||||||
$s = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
|
$s = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
|
||||||
dbesc($filename),
|
dbesc($filename),
|
||||||
dbesc($new_folder_hash)
|
dbesc($new_folder_hash)
|
||||||
@ -2387,6 +2384,7 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
|
|||||||
$filename = $basename . $ext;
|
$filename = $basename . $ext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$t = q("update attach set content = '%s', folder = '%s', filename = '%s' where id = %d",
|
$t = q("update attach set content = '%s', folder = '%s', filename = '%s' where id = %d",
|
||||||
dbescbin($newstorepath),
|
dbescbin($newstorepath),
|
||||||
@ -2423,6 +2421,24 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($r[0]['is_dir']) {
|
||||||
|
$move_success = true;
|
||||||
|
$x = q("select hash from attach where folder = '%s' and uid = %d",
|
||||||
|
dbesc($r[0]['hash']),
|
||||||
|
intval($channel_id)
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
foreach($x as $xv) {
|
||||||
|
$rs = attach_move($channel_id,$xv['hash'],$r[0]['hash']);
|
||||||
|
if(! $rs) {
|
||||||
|
$move_success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $move_success;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user