Fixed some more timestamp bugs in RedDAV.

Fixed an SQL-query in RedFile::put(), where parameters where in wrong order.
This commit is contained in:
Klaus Weidenbach 2014-06-29 17:49:46 +02:00
parent 5be3ba8436
commit 322091cd12
3 changed files with 46 additions and 32 deletions

View File

@ -665,17 +665,25 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
); );
if($r) { if($r) {
if(mkdir($path,STORAGE_DEFAULT_PERMISSIONS, true)) { if(mkdir($path, STORAGE_DEFAULT_PERMISSIONS, true)) {
$ret['success'] = true; $ret['success'] = true;
$ret['data'] = $arr; $ret['data'] = $arr;
// update the parent folder's lastmodified timestamp
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($created),
dbesc($arr['folder']),
intval($channel_id)
);
} }
else { else {
logger('attach_mkdir: ' . mkdir . ' ' . $path . 'failed.'); logger('attach_mkdir: ' . mkdir . ' ' . $path . 'failed.');
$ret['message'] = t('mkdir failed.'); $ret['message'] = t('mkdir failed.');
} }
} }
else else {
$ret['message'] = t('database storage failed.'); $ret['message'] = t('database storage failed.');
}
return $ret; return $ret;
@ -729,29 +737,28 @@ function attach_change_permissions($channel_id, $resource, $allow_cid, $allow_gi
} }
/** /**
* @brief Delete a file. * @brief Delete a file/directory.
* *
* @param $channel_id * @param int $channel_id
* @param $resource * @param string $resource a hash to delete
*/ */
function attach_delete($channel_id, $resource) { function attach_delete($channel_id, $resource) {
$c = q("SELECT channel_address FROM channel WHERE channel_id = %d LIMIT 1",
$c = q("select channel_address from channel where channel_id = %d limit 1",
intval($channel_id) intval($channel_id)
); );
$channel_address = (($c) ? $c[0]['channel_address'] : 'notfound'); $channel_address = (($c) ? $c[0]['channel_address'] : 'notfound');
$r = q("select hash, flags from attach where hash = '%s' and uid = %d limit 1", $r = q("SELECT hash, flags, folder FROM attach WHERE hash = '%s' AND uid = %d limit 1",
dbesc($resource), dbesc($resource),
intval($channel_id) intval($channel_id)
); );
if(! $r) if(! $r)
return; return;
// 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, flags from attach where folder = '%s' and uid = %d",
dbesc($resource), dbesc($resource),
@ -763,8 +770,10 @@ function attach_delete($channel_id, $resource) {
} }
} }
} }
// delete a file from filesystem
if($r[0]['flags'] & ATTACH_FLAG_OS) { if($r[0]['flags'] & ATTACH_FLAG_OS) {
$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)
); );
@ -778,11 +787,19 @@ function attach_delete($channel_id, $resource) {
} }
} }
$z = q("delete from attach where hash = '%s' and uid = %d limit 1", // delete from database
$z = q("DELETE FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($resource), dbesc($resource),
intval($channel_id) intval($channel_id)
); );
// update the parent folder's lastmodified timestamp
$e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc($r[0]['folder']),
intval($channel_id)
);
return; return;
} }

View File

@ -476,8 +476,8 @@ class RedFile extends DAV\Node implements DAV\IFile {
// @todo only 3 values are needed // @todo only 3 values are needed
$c = q("SELECT * FROM channel WHERE channel_id = %d AND NOT (channel_pageflags & %d) LIMIT 1", $c = q("SELECT * FROM channel WHERE channel_id = %d AND NOT (channel_pageflags & %d) LIMIT 1",
intval(PAGE_REMOVED), intval($this->auth->owner_id),
intval($this->auth->owner_id) intval(PAGE_REMOVED)
); );
$r = q("SELECT flags, folder, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1", $r = q("SELECT flags, folder, data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
@ -518,7 +518,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
); );
// update the folder's lastmodified timestamp // update the folder's lastmodified timestamp
$e = q("UPDATE attach SET edited = '%s' WHERE folder = '%s' AND uid = %d LIMIT 1", $e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d LIMIT 1",
dbesc($edited), dbesc($edited),
dbesc($r[0]['folder']), dbesc($r[0]['folder']),
intval($c[0]['channel_id']) intval($c[0]['channel_id'])
@ -628,12 +628,14 @@ class RedFile extends DAV\Node implements DAV\IFile {
} }
/** /**
* @brief Delete the current file. * @brief Delete the file.
* *
* @throw DAV\Exception\Forbidden * @throw DAV\Exception\Forbidden
* @return void * @return void
*/ */
public function delete() { public function delete() {
logger('RedFile::delete(): ' . basename($this->name), LOGGER_DEBUG);
if ((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage'))) { if ((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage'))) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
} }
@ -732,7 +734,7 @@ function RedCollectionData($file, &$auth) {
$permission_error = false; $permission_error = false;
for ($x = 1; $x < count($path_arr); $x++) { for ($x = 1; $x < count($path_arr); $x++) {
$r = q("select id, hash, filename, flags from attach where folder = '%s' and filename = '%s' and uid = %d and (flags & %d) $perms limit 1", $r = q("SELECT id, hash, filename, flags FROM attach WHERE folder = '%s' AND filename = '%s' AND uid = %d AND (flags & %d) $perms LIMIT 1",
dbesc($folder), dbesc($folder),
dbesc($path_arr[$x]), dbesc($path_arr[$x]),
intval($channel_id), intval($channel_id),

View File

@ -9,7 +9,6 @@
<th>{{t('Last modified')}}</th> <th>{{t('Last modified')}}</th>
</tr> </tr>
<tr><td colspan="8"><hr></td></tr> <tr><td colspan="8"><hr></td></tr>
{{if $parentpath}} {{if $parentpath}}
<tr> <tr>
<td>{{$parentpath.icon}}</td> <td>{{$parentpath.icon}}</td>
@ -20,26 +19,22 @@
<td></td> <td></td>
</tr> </tr>
{{/if}} {{/if}}
{{foreach $entries as $item}} {{foreach $entries as $item}}
<tr> <tr>
<td>{{$item.icon}}</td> <td>{{$item.icon}}</td>
<td style="min-width: 15em"><a href="{{$item.fullPath}}">{{$item.displayName}}</a></td> <td style="min-width: 15em"><a href="{{$item.fullPath}}">{{$item.displayName}}</a></td>
{{if $item.is_owner}} {{if $item.is_owner}}
<td>{{$item.attachIcon}}</td> <td>{{$item.attachIcon}}</td>
<td style="position:relative;"><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/edit" title="{{t('Edit')}}"><i class="icon-pencil btn btn-default"></i></a></td> <td style="position:relative;"><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/edit" title="{{t('Edit')}}"><i class="icon-pencil btn btn-default"></i></a></td>
<td><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/delete" title="{{t('Delete')}}" onclick="return confirm('{{t('Are you sure you want to delete this item?')}}');"><i class="icon-remove btn btn-default drop-icons"></i></a></td> <td><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/delete" title="{{t('Delete')}}" onclick="return confirm('{{t('Are you sure you want to delete this item?')}}');"><i class="icon-remove btn btn-default drop-icons"></i></a></td>
{{else}} {{else}}
<td></td><td></td><td></td> <td></td><td></td><td></td>
{{/if}} {{/if}}
<td>{{$item.type}}</td> <td>{{$item.type}}</td>
<td>{{$item.sizeFormatted}}</td> <td>{{$item.sizeFormatted}}</td>
<td>{{$item.lastmodified}}</td> <td>{{$item.lastmodified}}</td>
</tr> </tr>
{{/foreach}} {{/foreach}}
<tr><td colspan="8"><hr></td></tr> <tr><td colspan="8"><hr></td></tr>
</table> </table>