From 279f32b13deb45f3fe0ab2d32f6d2a0ea6e224e5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 7 Apr 2016 18:54:48 -0700 Subject: send file sync packets for all known file operations --- Zotlabs/Storage/Directory.php | 26 +++++++++++++++- Zotlabs/Storage/File.php | 21 +++++++++++++ include/attach.php | 16 +++++++--- include/import.php | 5 +++ include/reddav.php | 3 -- mod/photos.php | 71 +++++++++++++++++++++++++++++-------------- mod/wall_attach.php | 17 ----------- 7 files changed, 112 insertions(+), 47 deletions(-) diff --git a/Zotlabs/Storage/Directory.php b/Zotlabs/Storage/Directory.php index 95d7ebf46..edbef5a95 100644 --- a/Zotlabs/Storage/Directory.php +++ b/Zotlabs/Storage/Directory.php @@ -168,6 +168,14 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota { intval($this->auth->owner_id) ); + + $ch = channelx_by_n($this->auth->owner_id); + if($ch) { + $sync = attach_export_data($ch,$this->folder_hash); + if($sync) + build_sync_packet($ch['channel_id'],array('file' => array($sync))); + } + $this->red_path = $new_path; } @@ -362,7 +370,14 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota { if ($r) { $result = attach_mkdir($r[0], $this->auth->observer, array('filename' => $name, 'folder' => $this->folder_hash)); - if (! $result['success']) { + + if($result['success']) { + $sync = attach_export_data($r[0],$ret['data']['hash']); + if($sync) { + build_sync_packet($r[0]['channel_id'],array('file' => array($sync))); + } + } + else { logger('error ' . print_r($result, true), LOGGER_DEBUG); } } @@ -386,6 +401,15 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota { } attach_delete($this->auth->owner_id, $this->folder_hash); + + $ch = channelx_by_n($this->auth->owner_id); + if($ch) { + $sync = attach_export_data($ch,$this->folder_hash,true); + if($sync) + build_sync_packet($ch['channel_id'],array('file' => array($sync))); + } + + } diff --git a/Zotlabs/Storage/File.php b/Zotlabs/Storage/File.php index 5c3dcd9c6..897f24edd 100644 --- a/Zotlabs/Storage/File.php +++ b/Zotlabs/Storage/File.php @@ -84,6 +84,20 @@ class File extends DAV\Node implements DAV\IFile { dbesc($this->data['hash']), intval($this->data['id']) ); + + if($this->data->is_photo) { + $r = q("update photo set filename = '%s' where resource_id = '%s' and uid = %d", + dbesc($newName), + dbesc($this->data['hash']), + intval($this->auth->owner_id) + ); + } + $ch = channelx_by_n($this->auth->owner_id); + if($ch) { + $sync = attach_export_data($ch,$this->data['hash']); + if($sync) + build_sync_packet($ch['channel_id'],array('file' => array($sync))); + } } /** @@ -324,5 +338,12 @@ class File extends DAV\Node implements DAV\IFile { } attach_delete($this->auth->owner_id, $this->data['hash']); + + $ch = channelx_by_n($this->auth->owner_id); + if($ch) { + $sync = attach_export_data($ch,$this->data['hash'],true); + if($sync) + build_sync_packet($ch['channel_id'],array('file' => array($sync))); + } } } diff --git a/include/attach.php b/include/attach.php index 8d8cfe65f..ae4681994 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1820,7 +1820,7 @@ function filepath_macro($s) { } -function attach_export_data($channel,$resource_id) { +function attach_export_data($channel, $resource_id, $deleted = false) { $ret = array(); @@ -1828,6 +1828,15 @@ function attach_export_data($channel,$resource_id) { $hash_ptr = $resource_id; + $ret['fetch_url'] = z_root() . '/getfile'; + $ret['original_channel'] = $channel['channel_address']; + + + if($deleted) { + $ret['attach'] = array(array('hash' => $resource_id, 'deleted' => 1)); + return $ret; + } + do { $r = q("select * from attach where hash = '%s' and uid = %d limit 1", dbesc($hash_ptr), @@ -1836,16 +1845,15 @@ function attach_export_data($channel,$resource_id) { if(! $r) break; - if($hash_ptr === $resource_id) + if($hash_ptr === $resource_id) { $attach_ptr = $r[0]; + } $hash_ptr = $r[0]['folder']; $paths[] = $r[0]; } while($hash_ptr); - $ret['fetch_url'] = z_root() . '/getfile'; - $ret['original_channel'] = $channel['channel_address']; $paths = array_reverse($paths); diff --git a/include/import.php b/include/import.php index 3525ee948..f15dedfe0 100644 --- a/include/import.php +++ b/include/import.php @@ -890,6 +890,11 @@ function sync_files($channel,$files) { $attachment_stored = false; foreach($f['attach'] as $att) { + if($att['deleted']) { + attach_delete($channel,$att['hash']); + continue; + } + $attach_exists = false; $x = attach_by_hash($att['hash']); diff --git a/include/reddav.php b/include/reddav.php index a0bd1b1fc..abf21b86d 100644 --- a/include/reddav.php +++ b/include/reddav.php @@ -23,9 +23,6 @@ use Zotlabs\Storage; require_once('vendor/autoload.php'); require_once('include/attach.php'); -//require_once('Zotlabs/Storage/File.php'); -//require_once('Zotlabs/Storage/Directory.php'); -//require_once('Zotlabs/Storage/BasicAuth.php'); /** * @brief Returns an array with viewable channels. diff --git a/mod/photos.php b/mod/photos.php index 0adbf752a..bf904db22 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -126,6 +126,34 @@ function photos_post(&$a) { if($_REQUEST['dropalbum'] == t('Delete Album')) { + + // This is dangerous because we combined file storage and photos into one interface + // This function will remove all photos from any directory with the same name since + // we have not passed the path value. + + // The correct solution would be to use a full pathname from your storage root for 'album' + // We also need to prevent/block removing the storage root folder. + + $folder_hash = ''; + + $r = q("select * from attach where is_dir = 1 and uid = %d and filename = '%s'", + intval($page_owner_uid), + dbesc($album) + ); + if(! $r) { + notice( t('Album not found.') . EOL); + return; + } + if(count($r) > 1) { + notice( t('Multiple storage folders exist with this album name, but within different directories. Please remove the desired folder or folders using the Files manager') . EOL); + return; + } + else { + $folder_hash = $r[0]['hash']; + } + + + $res = array(); // get the list of photos we are about to delete @@ -149,9 +177,6 @@ function photos_post(&$a) { if($r) { foreach($r as $i) { attach_delete($page_owner_uid, $i['resource_id'], 1 ); - // This is now being done in attach_delete() - // drop_item($i['id'],false,DROPITEM_PHASE1,true /* force removal of linked items */); - // proc_run('php','include/notifier.php','drop',$i['id']); } } @@ -163,6 +188,15 @@ function photos_post(&$a) { // @FIXME do the same for the linked attach + if($folder_hash) { + attach_delete($page_owner_uid,$folder_hash, 1); + + $sync = attach_export_data(App::$data['channel'],$folder_hash, true); + + if($sync) + build_sync_packet($page_owner_uid,array('file' => array($sync))); + } + } goaway(z_root() . '/photos/' . App::$data['channel']['channel_address']); @@ -183,23 +217,11 @@ function photos_post(&$a) { ); if($r) { -/* - q("DELETE FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s'", - intval($page_owner_uid), - dbesc($r[0]['resource_id']) - ); -*/ attach_delete($page_owner_uid, $r[0]['resource_id'], 1 ); -/* - $i = q("SELECT * FROM `item` WHERE `resource_id` = '%s' AND resource_type = 'photo' and `uid` = %d LIMIT 1", - dbesc($r[0]['resource_id']), - intval($page_owner_uid) - ); - if(count($i)) { - drop_item($i[0]['id'],true,DROPITEM_PHASE1); - $url = z_root(); - } -*/ + $sync = attach_export_data(App::$data['channel'],$r[0]['resource_id'], true); + + if($sync) + build_sync_packet($page_owner_uid,array('file' => array($sync))); } goaway(z_root() . '/photos/' . App::$data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']); @@ -218,7 +240,7 @@ function photos_post(&$a) { $acl->set_from_array($_POST); $perm = $acl->get(); - $resource_id = App::$argv[2]; + $resource_id = argv(2); if(! strlen($albname)) $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); @@ -443,6 +465,11 @@ function photos_post(&$a) { goaway(z_root() . '/' . $_SESSION['photo_return']); return; // NOTREACHED + $sync = attach_export_data(App::$data['channel'],$resource_id); + + if($sync) + build_sync_packet($page_owner_uid,array('file' => array($sync))); + } @@ -555,8 +582,8 @@ function photos_content(&$a) { $o = ""; - $o .= "\r\n"; + $o .= "\r\n"; // tabs diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 75786b479..7f054705f 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -23,23 +23,6 @@ function wall_attach_post(&$a) { $observer = App::get_observer(); -// if($_FILES['userfile']['tmp_name']) { -// $x = @getimagesize($_FILES['userfile']['tmp_name']); -// logger('getimagesize: ' . print_r($x,true), LOGGER_DATA); -// if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) { -// $args = array( 'source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash'])); -// $ret = photo_upload($channel,$observer,$args); -// if($ret['success']) { -// echo "\n\n" . $ret['body'] . "\n\n"; -// killme(); -// } -// if($using_api) -// return; -// notice($ret['message']); -// killme(); -// } -// } - $def_album = get_pconfig($channel['channel_id'],'system','photo_path'); $def_attach = get_pconfig($channel['channel_id'],'system','attach_path'); -- cgit v1.2.3