aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <mike@macgirvin.com>2016-08-24 22:41:54 -0700
committerredmatrix <mike@macgirvin.com>2016-08-24 22:41:54 -0700
commit8d94402d25bc1f4c07d2182ea48badabc6642617 (patch)
tree896ed3a556ba449362036698f97b9b78b9569223 /include
parent35d12b9e59d6b969b4c08bd5cc18e40c621e74ec (diff)
downloadvolse-hubzilla-8d94402d25bc1f4c07d2182ea48badabc6642617.tar.gz
volse-hubzilla-8d94402d25bc1f4c07d2182ea48badabc6642617.tar.bz2
volse-hubzilla-8d94402d25bc1f4c07d2182ea48badabc6642617.zip
attach_move() function created to relocate files or photos to different directories in the cloud area and photo albums without deleting and recreating (which would create a new resource_id and invalidate any existing links).
Diffstat (limited to 'include')
-rw-r--r--include/attach.php70
-rw-r--r--include/photos.php2
2 files changed, 72 insertions, 0 deletions
diff --git a/include/attach.php b/include/attach.php
index 172840b96..8dac57bb6 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1994,3 +1994,73 @@ function get_filename_by_cloudname($cloudname, $channel, $storepath) {
}
return null;
}
+
+/**
+ * attach_move()
+ * This function performs an in place directory-to-directory move of a stored attachment or photo.
+ * 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.
+ * This takes a channel_id, attach.hash of the file to move (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 file is relocated to the root of the channel's storage area.
+ *
+ * @fixme: this operation is currently not synced to clones !!
+ */
+
+function attach_move($channel_id,$resource_id,$new_folder_hash) {
+
+ $c = channelx_by_n($channel_id);
+ if(! $c)
+ return false;
+
+ $r = q("select * from attach where hash = '%s' and uid = %d limit 1",
+ dbesc($resource_id),
+ intval($channel_id)
+ );
+ if(! $r)
+ return false;
+
+ $oldstorepath = $r[0]['content'];
+
+ if($new_folder_hash) {
+ $n = q("select * from attach where hash = '%s' and uid = %d limit 1",
+ dbesc($new_folder_hash),
+ intval($channel_id)
+ );
+ if(! $n)
+ return;
+ $newdirname = $n[0]['filename'];
+ $newstorepath = $n[0]['content'] . '/' . $resource_id;
+ }
+ else {
+ $newstorepath = 'store/' . $c['channel_address'] . '/' . $resource_id;
+ }
+
+ rename($oldstorepath,$newstorepath);
+
+ $t = q("update attach set content = '%s', folder = '%s' where id = %d",
+ dbesc($newstorepath),
+ dbesc($new_folder_hash),
+ intval($r[0]['id'])
+ );
+
+ if($r[0]['is_photo']) {
+ $t = q("update photo set album = '%s' where resource_id = '%s' and uid = %d",
+ dbesc($newdirname),
+ dbesc($resource_id),
+ intval($channel_id)
+ );
+
+ $t = q("update photo set content = '%s' where resource_id = '%s' and uid = %d and imgscale = 0",
+ dbesc($newstorepath),
+ dbesc($resource_id),
+ intval($channel_id)
+ );
+ }
+
+ return true;
+
+}
+
+
diff --git a/include/photos.php b/include/photos.php
index d14c12d84..9d15d3692 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -588,6 +588,8 @@ function photos_album_rename($channel_id, $oldname, $newname) {
);
}
+
+
/**
* @brief
*