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)
|
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;
|
$this->red_path = $new_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +370,14 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
|
|||||||
|
|
||||||
if ($r) {
|
if ($r) {
|
||||||
$result = attach_mkdir($r[0], $this->auth->observer, array('filename' => $name, 'folder' => $this->folder_hash));
|
$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);
|
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);
|
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']),
|
dbesc($this->data['hash']),
|
||||||
intval($this->data['id'])
|
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']);
|
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();
|
$ret = array();
|
||||||
|
|
||||||
@ -1828,6 +1828,15 @@ function attach_export_data($channel,$resource_id) {
|
|||||||
|
|
||||||
$hash_ptr = $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 {
|
do {
|
||||||
$r = q("select * from attach where hash = '%s' and uid = %d limit 1",
|
$r = q("select * from attach where hash = '%s' and uid = %d limit 1",
|
||||||
dbesc($hash_ptr),
|
dbesc($hash_ptr),
|
||||||
@ -1836,16 +1845,15 @@ function attach_export_data($channel,$resource_id) {
|
|||||||
if(! $r)
|
if(! $r)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if($hash_ptr === $resource_id)
|
if($hash_ptr === $resource_id) {
|
||||||
$attach_ptr = $r[0];
|
$attach_ptr = $r[0];
|
||||||
|
}
|
||||||
|
|
||||||
$hash_ptr = $r[0]['folder'];
|
$hash_ptr = $r[0]['folder'];
|
||||||
$paths[] = $r[0];
|
$paths[] = $r[0];
|
||||||
} while($hash_ptr);
|
} while($hash_ptr);
|
||||||
|
|
||||||
|
|
||||||
$ret['fetch_url'] = z_root() . '/getfile';
|
|
||||||
$ret['original_channel'] = $channel['channel_address'];
|
|
||||||
|
|
||||||
|
|
||||||
$paths = array_reverse($paths);
|
$paths = array_reverse($paths);
|
||||||
|
@ -890,6 +890,11 @@ function sync_files($channel,$files) {
|
|||||||
$attachment_stored = false;
|
$attachment_stored = false;
|
||||||
foreach($f['attach'] as $att) {
|
foreach($f['attach'] as $att) {
|
||||||
|
|
||||||
|
if($att['deleted']) {
|
||||||
|
attach_delete($channel,$att['hash']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$attach_exists = false;
|
$attach_exists = false;
|
||||||
$x = attach_by_hash($att['hash']);
|
$x = attach_by_hash($att['hash']);
|
||||||
|
|
||||||
|
@ -23,9 +23,6 @@ use Zotlabs\Storage;
|
|||||||
|
|
||||||
require_once('vendor/autoload.php');
|
require_once('vendor/autoload.php');
|
||||||
require_once('include/attach.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.
|
* @brief Returns an array with viewable channels.
|
||||||
|
@ -126,6 +126,34 @@ function photos_post(&$a) {
|
|||||||
|
|
||||||
if($_REQUEST['dropalbum'] == t('Delete Album')) {
|
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();
|
$res = array();
|
||||||
|
|
||||||
// get the list of photos we are about to delete
|
// get the list of photos we are about to delete
|
||||||
@ -149,9 +177,6 @@ function photos_post(&$a) {
|
|||||||
if($r) {
|
if($r) {
|
||||||
foreach($r as $i) {
|
foreach($r as $i) {
|
||||||
attach_delete($page_owner_uid, $i['resource_id'], 1 );
|
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
|
// @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']);
|
goaway(z_root() . '/photos/' . App::$data['channel']['channel_address']);
|
||||||
@ -183,23 +217,11 @@ function photos_post(&$a) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if($r) {
|
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 );
|
attach_delete($page_owner_uid, $r[0]['resource_id'], 1 );
|
||||||
/*
|
$sync = attach_export_data(App::$data['channel'],$r[0]['resource_id'], true);
|
||||||
$i = q("SELECT * FROM `item` WHERE `resource_id` = '%s' AND resource_type = 'photo' and `uid` = %d LIMIT 1",
|
|
||||||
dbesc($r[0]['resource_id']),
|
if($sync)
|
||||||
intval($page_owner_uid)
|
build_sync_packet($page_owner_uid,array('file' => array($sync)));
|
||||||
);
|
|
||||||
if(count($i)) {
|
|
||||||
drop_item($i[0]['id'],true,DROPITEM_PHASE1);
|
|
||||||
$url = z_root();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
goaway(z_root() . '/photos/' . App::$data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']);
|
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);
|
$acl->set_from_array($_POST);
|
||||||
$perm = $acl->get();
|
$perm = $acl->get();
|
||||||
|
|
||||||
$resource_id = App::$argv[2];
|
$resource_id = argv(2);
|
||||||
|
|
||||||
if(! strlen($albname))
|
if(! strlen($albname))
|
||||||
$albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
|
$albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
|
||||||
@ -443,6 +465,11 @@ function photos_post(&$a) {
|
|||||||
goaway(z_root() . '/' . $_SESSION['photo_return']);
|
goaway(z_root() . '/' . $_SESSION['photo_return']);
|
||||||
return; // NOTREACHED
|
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 = "";
|
||||||
|
|
||||||
$o .= "<script> var profile_uid = " . App::$profile['profile_uid']
|
$o .= "<script> var profile_uid = " . App::$profile['profile_uid']
|
||||||
. "; var netargs = '?f='; var profile_page = " . App::$pager['page'] . "; </script>\r\n";
|
. "; var netargs = '?f='; var profile_page = " . App::$pager['page'] . "; </script>\r\n";
|
||||||
|
|
||||||
// tabs
|
// tabs
|
||||||
|
|
||||||
|
@ -23,23 +23,6 @@ function wall_attach_post(&$a) {
|
|||||||
$observer = App::get_observer();
|
$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_album = get_pconfig($channel['channel_id'],'system','photo_path');
|
||||||
$def_attach = get_pconfig($channel['channel_id'],'system','attach_path');
|
$def_attach = get_pconfig($channel['channel_id'],'system','attach_path');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user