send file sync packets for all known file operations
This commit is contained in:
parent
3a6187af3d
commit
279f32b13d
@ -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)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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']);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
Reference in New Issue
Block a user