Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F174766
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/Kolab/DAV/Node.php b/lib/Kolab/DAV/Node.php
index c2bb549..aead1ef 100644
--- a/lib/Kolab/DAV/Node.php
+++ b/lib/Kolab/DAV/Node.php
@@ -1,215 +1,216 @@
<?php
/**
* SabreDAV File Backend implementation for Kolab.
*
* @author Aleksander Machniak <machniak@kolabsys.com>
*
* Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Kolab\DAV;
use \Exception;
/**
* Node class
*/
class Node implements \Sabre\DAV\INode
{
/**
* The path to the current node
*
* @var string
*/
protected $path;
/**
* The file API backend class
*
* @var Kolab\DAV\Backend
*/
protected $backend;
/**
* Internal node data (e.g. file parameters)
*
* @var array
*/
protected $data;
/**
* Parent node
*
* @var Kolab\DAV\Node
*/
protected $parent;
/**
* @brief Sets up the node, expects a full path name
* @param string $path Node name with path
* @param Kolab\DAV\Node $parent Parent node
* @param array $data Node data
*
* @return void
*/
public function __construct($path, $parent = null, $data = array())
{
$this->data = $data;
$this->path = $path;
$this->parent = $parent;
$this->backend = Backend::get_instance();
if ($this->path == Collection::ROOT_DIRECTORY) {
$this->path = '';
}
else if (strpos($this->path, Collection::ROOT_DIRECTORY . '/') === 0) {
$this->path = substr($this->path, strlen(Collection::ROOT_DIRECTORY . '/'));
}
}
/**
* Returns the last modification time
*
* In this case, it will simply return the current time
*
* @return int
*/
public function getLastModified()
{
return $this->data['modified'] ? $this->data['modified'] : null;
}
/**
* Deletes the current node (folder)
*
* @throws Sabre\DAV\Exception
* @return void
*/
public function delete()
{
try {
$this->backend->folder_delete($this->path);
}
catch (Exception $e) {
$this->throw_exception($e);
}
// reset cache
if ($this->parent) {
$this->parent->children = null;
}
}
/**
* Renames the node
*
* @throws Sabre\DAV\Exception
* @param string $name The new name
* @return void
*/
public function setName($name)
{
$path = explode('/', $this->path);
array_pop($path);
$newname = implode('/', $path) . '/' . $name;
$method = (is_a($this, 'Kolab\\DAV\\File') ? 'file' : 'folder') . '_move';
try {
$this->backend->$method($this->path, $newname);
}
catch (Exception $e) {
$this->throw_exception($e);
}
// reset cache
if ($this->parent) {
$this->parent->children = null;
}
}
/**
* @brief Returns the name of the node
* @return string
*/
public function getName()
{
if ($this->path === '') {
return Collection::ROOT_DIRECTORY;
}
return array_pop(explode('/', $this->path));
}
/**
* Build file data array to pass into backend
*/
protected function fileData($name, $data = null)
{
if ($this->data && $this->data['type']) {
$type = $this->data['type'];
}
else {
$type = 'application/octet-stream';
}
// $data can be a resource or a string
if (is_resource($data)) {
- rewind($data);
-
// $data can be php://input or php://temp
// php://input is not seekable, we need to "convert"
// it to seekable resource, fstat/rewind later will work
$meta = stream_get_meta_data($data);
if (!$meta['seekable']) {
$new_data = fopen('php://temp','r+');
stream_copy_to_stream($data, $new_data);
rewind($new_data);
$data = $new_data;
}
+ else {
+ rewind($data);
+ }
}
$filedata = array(
'content' => $data,
'type' => $type,
);
return $filedata;
}
/**
* Convert Chwala exceptions to Sabre exceptions
*
* @param Exception Chwala exception
* @throws Sabre\DAV\Exception
*/
protected function throw_exception($e)
{
$error = $e->getCode();
$msg = $e->getMessage();
if ($error == \file_storage::ERROR_UNAVAILABLE) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($msg);
}
else if ($error == \file_storage::ERROR_FORBIDDEN) {
throw new \Sabre\DAV\Exception\Forbidden($msg);
}
throw new \Sabre\DAV\Exception($msg);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jan 20, 5:44 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
120111
Default Alt Text
(5 KB)
Attached To
Mode
R5 irony
Attached
Detach File
Event Timeline
Log In to Comment