aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
authorredmatrix <mike@macgirvin.com>2016-08-26 01:37:46 -0700
committerredmatrix <mike@macgirvin.com>2016-08-26 01:37:46 -0700
commit8a2b96c2f950f828635441f357acfad94cea1266 (patch)
treed8995af32213e766674b3941ed242c59b9cc3ed9 /include/attach.php
parentc6b9eb7855aff2582bf0731546a739667faa81a0 (diff)
downloadvolse-hubzilla-8a2b96c2f950f828635441f357acfad94cea1266.tar.gz
volse-hubzilla-8a2b96c2f950f828635441f357acfad94cea1266.tar.bz2
volse-hubzilla-8a2b96c2f950f828635441f357acfad94cea1266.zip
- implemented but untested: duplicate detection for photo 'move to another folder'
- weekly string update
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php59
1 files changed, 57 insertions, 2 deletions
diff --git a/include/attach.php b/include/attach.php
index 8dac57bb6..ae7d71dc7 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -2039,15 +2039,70 @@ function attach_move($channel_id,$resource_id,$new_folder_hash) {
rename($oldstorepath,$newstorepath);
- $t = q("update attach set content = '%s', folder = '%s' where id = %d",
+ // duplicate detection. If 'overwrite' is specified, return false because we can't yet do that.
+
+ $filename = $r[0]['filename'];
+
+ $s = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
+ dbesc($filename),
+ dbesc($new_folder_hash)
+ );
+
+ if($s) {
+ $overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
+ if($overwrite) {
+ // @fixme
+ return;
+ }
+ else {
+ if(strpos($filename,'.') !== false) {
+ $basename = substr($filename,0,strrpos($filename,'.'));
+ $ext = substr($filename,strrpos($filename,'.'));
+ }
+ else {
+ $basename = $filename;
+ $ext = '';
+ }
+
+ $v = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
+ dbesc($basename . $ext),
+ dbesc($basename . '(%)' . $ext),
+ dbesc($new_folder_hash)
+ );
+
+ if($v) {
+ $x = 1;
+
+ do {
+ $found = false;
+ foreach($v as $vv) {
+ if($vv['filename'] === $basename . '(' . $x . ')' . $ext) {
+ $found = true;
+ break;
+ }
+ }
+ if($found)
+ $x++;
+ }
+ while($found);
+ $filename = $basename . '(' . $x . ')' . $ext;
+ }
+ else
+ $filename = $basename . $ext;
+ }
+ }
+
+ $t = q("update attach set content = '%s', folder = '%s', filename = '%s' where id = %d",
dbesc($newstorepath),
dbesc($new_folder_hash),
+ dbesc($filename),
intval($r[0]['id'])
);
if($r[0]['is_photo']) {
- $t = q("update photo set album = '%s' where resource_id = '%s' and uid = %d",
+ $t = q("update photo set album = '%s', filename = '%s' where resource_id = '%s' and uid = %d",
dbesc($newdirname),
+ dbesc($filename),
dbesc($resource_id),
intval($channel_id)
);