isolate the os_storage flag

This commit is contained in:
redmatrix 2015-06-13 15:57:28 -07:00
parent 3f0009ccd7
commit b7be79c5e7
3 changed files with 29 additions and 23 deletions

View File

@ -220,7 +220,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
$is_photo = 1; $is_photo = 1;
} }
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, folder, flags, filetype, filesize, revision, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid ) $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, folder, os_storage, filetype, filesize, revision, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($c[0]['channel_account_id']), intval($c[0]['channel_account_id']),
intval($c[0]['channel_id']), intval($c[0]['channel_id']),
@ -228,7 +228,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection, DAV\IQuota {
dbesc($this->auth->observer), dbesc($this->auth->observer),
dbesc($name), dbesc($name),
dbesc($this->folder_hash), dbesc($this->folder_hash),
dbesc(ATTACH_FLAG_OS), intval(1),
dbesc($mimetype), dbesc($mimetype),
intval($filesize), intval($filesize),
intval(0), intval(0),

View File

@ -102,12 +102,12 @@ class RedFile extends DAV\Node implements DAV\IFile {
intval(PAGE_REMOVED) intval(PAGE_REMOVED)
); );
$r = q("SELECT flags, folder, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1", $r = q("SELECT flags, folder, os_storage, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($this->data['hash']), dbesc($this->data['hash']),
intval($c[0]['channel_id']) intval($c[0]['channel_id'])
); );
if ($r) { if ($r) {
if ($r[0]['flags'] & ATTACH_FLAG_OS) { if (intval($r[0]['os_storage'])) {
$fname = dbunescbin($r[0]['data']); $fname = dbunescbin($r[0]['data']);
$f = 'store/' . $this->auth->owner_nick . '/' . (($fname) ? $fname : ''); $f = 'store/' . $this->auth->owner_nick . '/' . (($fname) ? $fname : '');
// @todo check return value and set $size directly // @todo check return value and set $size directly
@ -179,7 +179,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
public function get() { public function get() {
logger('get file ' . basename($this->name), LOGGER_DEBUG); logger('get file ' . basename($this->name), LOGGER_DEBUG);
$r = q("SELECT data, flags, filename, filetype FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1", $r = q("SELECT data, flags, os_storage, filename, filetype FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($this->data['hash']), dbesc($this->data['hash']),
intval($this->data['uid']) intval($this->data['uid'])
); );
@ -192,7 +192,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
header('Content-type: text/plain'); header('Content-type: text/plain');
} }
if ($r[0]['flags'] & ATTACH_FLAG_OS ) { if (intval($r[0]['os_storage'])) {
$f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . dbunescbin($r[0]['data']); $f = 'store/' . $this->auth->owner_nick . '/' . (($this->os_path) ? $this->os_path . '/' : '') . dbunescbin($r[0]['data']);
return fopen($f, 'rb'); return fopen($f, 'rb');
} }

View File

@ -202,7 +202,7 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $
// Retrieve all columns except 'data' // Retrieve all columns except 'data'
$r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra $orderby $limit", $r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra $orderby $limit",
intval($channel_id) intval($channel_id)
); );
@ -310,7 +310,7 @@ function attach_by_hash_nodata($hash, $rev = 0) {
// Now we'll see if we can access the attachment // Now we'll see if we can access the attachment
$r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1", $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1",
intval($r[0]['uid']), intval($r[0]['uid']),
dbesc($hash) dbesc($hash)
); );
@ -391,7 +391,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($options === 'update' && $arr && array_key_exists('revision',$arr)) if($options === 'update' && $arr && array_key_exists('revision',$arr))
$sql_options = " and revision = " . intval($arr['revision']) . " "; $sql_options = " and revision = " . intval($arr['revision']) . " ";
$x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1", $x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1",
dbesc($arr['hash']), dbesc($arr['hash']),
intval($channel_id) intval($channel_id)
); );
@ -446,10 +446,11 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$created = datetime_convert(); $created = datetime_convert();
if($options === 'replace') { if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', filesize = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d", $r = q("update attach set filename = '%s', filetype = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
dbesc($filename), dbesc($filename),
dbesc($mimetype), dbesc($mimetype),
intval($filesize), intval($filesize),
intval(0),
intval($is_photo), intval($is_photo),
dbescbin(@file_get_contents($src)), dbescbin(@file_get_contents($src)),
dbesc($created), dbesc($created),
@ -458,8 +459,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
elseif($options === 'revise') { elseif($options === 'revise') {
$r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid ) $r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($x[0]['aid']), intval($x[0]['aid']),
intval($channel_id), intval($channel_id),
dbesc($x[0]['hash']), dbesc($x[0]['hash']),
@ -468,6 +469,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
dbesc($mimetype), dbesc($mimetype),
intval($filesize), intval($filesize),
intval($x[0]['revision'] + 1), intval($x[0]['revision'] + 1),
intval(0),
intval($is_photo), intval($is_photo),
dbescbin(@file_get_contents($src)), dbescbin(@file_get_contents($src)),
dbesc($created), dbesc($created),
@ -479,12 +481,13 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
elseif($options === 'update') { elseif($options === 'update') {
$r = q("update attach set filename = '%s', filetype = '%s', edited = '%s', is_photo = %d, $r = q("update attach set filename = '%s', filetype = '%s', edited = '%s', os_storage = %d, is_photo = %d,
allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where id = %d and uid = %d", allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where id = %d and uid = %d",
dbesc((array_key_exists('filename',$arr)) ? $arr['filename'] : $x[0]['filename']), dbesc((array_key_exists('filename',$arr)) ? $arr['filename'] : $x[0]['filename']),
dbesc((array_key_exists('filetype',$arr)) ? $arr['filetype'] : $x[0]['filetype']), dbesc((array_key_exists('filetype',$arr)) ? $arr['filetype'] : $x[0]['filetype']),
dbesc($created), dbesc($created),
intval($is_photo), dbesc((array_key_exists('os_storage',$arr)) ? $arr['os_storage'] : $x[0]['os_storage']),
dbesc((array_key_exists('is_photo',$arr)) ? $arr['is_photo'] : $x[0]['is_photo']),
dbesc((array_key_exists('allow_cid',$arr)) ? $arr['allow_cid'] : $x[0]['allow_cid']), dbesc((array_key_exists('allow_cid',$arr)) ? $arr['allow_cid'] : $x[0]['allow_cid']),
dbesc((array_key_exists('allow_gid',$arr)) ? $arr['allow_gid'] : $x[0]['allow_gid']), dbesc((array_key_exists('allow_gid',$arr)) ? $arr['allow_gid'] : $x[0]['allow_gid']),
dbesc((array_key_exists('deny_cid',$arr)) ? $arr['deny_cid'] : $x[0]['deny_cid']), dbesc((array_key_exists('deny_cid',$arr)) ? $arr['deny_cid'] : $x[0]['deny_cid']),
@ -494,8 +497,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
else { else {
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid ) $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']), intval($channel['channel_account_id']),
intval($channel_id), intval($channel_id),
dbesc($hash), dbesc($hash),
@ -504,6 +507,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
dbesc($mimetype), dbesc($mimetype),
intval($filesize), intval($filesize),
intval(0), intval(0),
intval(0),
intval($is_photo), intval($is_photo),
dbescbin(@file_get_contents($src)), dbescbin(@file_get_contents($src)),
dbesc($created), dbesc($created),
@ -525,7 +529,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// Caution: This re-uses $sql_options set further above // Caution: This re-uses $sql_options set further above
$r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_options limit 1", $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_options limit 1",
intval($channel_id), intval($channel_id),
dbesc($hash) dbesc($hash)
); );
@ -693,8 +697,8 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
$created = datetime_convert(); $created = datetime_convert();
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, flags, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid ) $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, flags, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']), intval($channel['channel_account_id']),
intval($channel_id), intval($channel_id),
dbesc($arr['hash']), dbesc($arr['hash']),
@ -704,7 +708,8 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
intval(0), intval(0),
intval(0), intval(0),
dbesc($arr['folder']), dbesc($arr['folder']),
intval(ATTACH_FLAG_DIR|ATTACH_FLAG_OS), intval(1),
intval(ATTACH_FLAG_DIR),
dbesc($path), dbesc($path),
dbesc($created), dbesc($created),
dbesc($created), dbesc($created),
@ -816,7 +821,7 @@ function attach_delete($channel_id, $resource) {
// If resource is a directory delete everything in the directory recursive // If resource is a directory delete everything in the directory recursive
if($r[0]['flags'] & ATTACH_FLAG_DIR) { if($r[0]['flags'] & ATTACH_FLAG_DIR) {
$x = q("SELECT hash, flags FROM attach WHERE folder = '%s' AND uid = %d", $x = q("SELECT hash, os_storage, flags FROM attach WHERE folder = '%s' AND uid = %d",
dbesc($resource), dbesc($resource),
intval($channel_id) intval($channel_id)
); );
@ -828,7 +833,7 @@ function attach_delete($channel_id, $resource) {
} }
// delete a file from filesystem // delete a file from filesystem
if($r[0]['flags'] & ATTACH_FLAG_OS) { if(intval($r[0]['os_storage'])) {
$y = q("SELECT data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1", $y = q("SELECT data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($resource), dbesc($resource),
intval($channel_id) intval($channel_id)
@ -1184,7 +1189,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
*/ */
function get_file_activity_object($channel_id, $hash, $cloudpath) { function get_file_activity_object($channel_id, $hash, $cloudpath) {
$x = q("SELECT creator, filename, filetype, filesize, revision, folder, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", $x = q("SELECT creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
intval($channel_id), intval($channel_id),
dbesc($hash) dbesc($hash)
); );
@ -1212,6 +1217,7 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) {
'revision' => $x[0]['revision'], 'revision' => $x[0]['revision'],
'folder' => $x[0]['folder'], 'folder' => $x[0]['folder'],
'flags' => $x[0]['flags'], 'flags' => $x[0]['flags'],
'flags' => $x[0]['os_storage'],
'is_photo' => $x[0]['is_photo'], 'is_photo' => $x[0]['is_photo'],
'created' => $x[0]['created'], 'created' => $x[0]['created'],
'edited' => $x[0]['edited'], 'edited' => $x[0]['edited'],