Commit a250a722 authored by Mario's avatar Mario
Browse files

make attach_{move,copy}() return an associative array and update documentation

parent b70a6d53
Pipeline #368105 passed with stage
in 5 minutes and 36 seconds
......@@ -32,12 +32,15 @@ class Attach_edit extends Controller {
$channel = App::get_channel();
if ($copy) {
attach_copy($channel['channel_id'], $resource, $newfolder, $newfilename);
$x = attach_copy($channel['channel_id'], $resource, $newfolder, $newfilename);
}
elseif ($folder !== $newfolder || $filename !== $newfilename) {
attach_move($channel['channel_id'], $resource, $newfolder, $newfilename);
$x = attach_move($channel['channel_id'], $resource, $newfolder, $newfilename);
}
if($x['success'])
$resource = $x['resource_id'];
$acl = new AccessList($channel);
$acl->set_from_array($_POST);
$x = $acl->get();
......
......@@ -484,7 +484,8 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo
return false;
}
return attach_move($this->auth->owner_id, $sourceNode->data->hash, $this->folder_hash);
$ret = attach_move($this->auth->owner_id, $sourceNode->data->hash, $this->folder_hash);
return $ret['success'];
}
......
......@@ -2495,7 +2495,7 @@ function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpat
return true;
}
/**
* This function performs an in place directory-to-directory move of a stored attachment or photo.
* This function performs an in place directory-to-directory move of a stored resource.
* The data is physically moved in the store/nickname storage location and the paths adjusted
* in the attach structure (and if applicable the photo table). The new 'album name' is recorded
* for photos and will show up immediately there.
......@@ -2507,13 +2507,21 @@ function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpat
* @param int $channel_id
* @param int $resource_id
* @param string $new_folder_hash
* @return void|boolean
* @param (optional) string $newname
* @return array Associative array with:
* * \e boolean \b success
* * \e string \b resource_id
*/
function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '') {
$ret = [
'success' => false,
'resource_id' => $resource_id
];
$c = channelx_by_n($channel_id);
if(! ($c && $resource_id))
return false;
return $ret;
// find the resource to be moved
......@@ -2524,7 +2532,7 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '')
);
if(! $r) {
logger('resource_id not found');
return false;
return $ret;
}
$oldstorepath = dbunescbin($r[0]['content']);
......@@ -2537,7 +2545,7 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '')
intval($channel_id)
);
if(! $n)
return false;
return $ret;
$newdirname = $n[0]['filename'];
$newalbumname = $n[0]['display_path'];
......@@ -2569,7 +2577,7 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '')
$overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
if($overwrite) {
/// @fixme
return;
return $ret;
}
else {
if(strpos($filename,'.') !== false) {
......@@ -2669,25 +2677,49 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '')
if($x) {
foreach($x as $xv) {
$rs = attach_move($channel_id, $xv['hash'], $r[0]['hash']);
if(! $rs) {
if(! $rs['success']) {
$move_success = false;
break;
}
}
}
return $move_success;
$ret['success'] = $move_success;
return $ret;
}
return true;
$ret['success'] = true;
return $ret;
}
/**
* This function performs an in place directory-to-directory copy of a stored resource.
* The data is physically copyed in the store/nickname storage location and the paths adjusted
* in the attach structure (and if applicable the photo table). The new 'album name' is recorded
* for photos and will show up immediately there.
* This takes a channel_id, attach.hash of the file to copy (this is the same as a photo resource_id), and
* the attach.hash of the new parent folder, which must already exist. If $new_folder_hash is blank or empty,
* the new file is copyed to the root of the channel's storage area.
*
*
* @param int $channel_id
* @param int $resource_id
* @param string $new_folder_hash
* @param (optional) string $newname
* @return array Associative array with:
* * \e boolean \b success
* * \e string \b resource_id
*/
function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '') {
$ret = [
'success' => false,
'resource_id' => ''
];
$c = channelx_by_n($channel_id);
if(! ($c && $resource_id))
return false;
return $ret;
// find the resource to be moved
......@@ -2697,12 +2729,14 @@ function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '')
);
if(! $r) {
logger('resource_id not found');
return false;
return $ret;
}
$a = $r[0];
$new_resource_id = new_uuid();
$ret['resource_id'] = $new_resource_id;
$oldstorepath = dbunescbin($r[0]['content']);
// find the resource we are copying to
......@@ -2714,7 +2748,7 @@ function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '')
);
if(! $n) {
logger('new_folder_hash not found');
return false;
return $ret;
}
$newdirname = $n[0]['filename'];
......@@ -2749,7 +2783,7 @@ function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '')
$overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
if($overwrite) {
/// @fixme
return;
return $ret;
}
else {
if(strpos($filename,'.') !== false) {
......@@ -2794,15 +2828,6 @@ function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '')
}
}
/*
q("update attach set content = '%s', folder = '%s', filename = '%s' where id = %d",
dbescbin($newstorepath),
dbesc($new_folder_hash),
dbesc($filename),
intval($r[0]['id'])
);
*/
unset($a['id']);
$a['hash'] = $new_resource_id;
$a['content'] = $newstorepath;
......@@ -2855,16 +2880,19 @@ function attach_copy($channel_id, $resource_id, $new_folder_hash, $newname = '')
if($x) {
foreach($x as $xv) {
$rs = attach_copy($channel_id,$xv['hash'],$new_resource_id);
if(! $rs) {
if(! $rs['success']) {
$copy_success = false;
break;
}
}
}
return $copy_success;
$ret['success'] = $copy_success;
return $ret;
}
return true;
$ret['success'] = true;
return $ret;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment