Skip to content

Commit

Permalink
Introducing metadata collections in dav
Browse files Browse the repository at this point in the history
This change is to have metadata collection
in dav app. This will help users to:
1) Create fileid with a UUID
2) Create subfolder "p" inside "meta" folder
3) Create subfolder "v" inside "meta" folder
The "p" folder stands for preview and "v"
folder stands for version.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Oct 13, 2017
1 parent 2d8b811 commit e74c028
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 1 deletion.
102 changes: 102 additions & 0 deletions apps/dav/lib/MetaData/MetaDataHome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* @author Sujith Haridasan <shariadsan@owncloud.com>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/


namespace OCA\DAV\MetaData;


use OC\Files\Meta\MetaVersionCollection;
use OCP\IMetaData;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
use Sabre\HTTP\URLUtil;

class MetaDataHome implements ICollection {

/** @var array */

private $metaData;

/**
* MetaDataHome constructor.
*/
public function __construct() {
}

function createFile($name, $data = null) {
throw new Forbidden('Permission denied to create a file');
}

function createDirectory($name) {
throw new Forbidden('Permission denied to create a folder');
}

function getChild($name) {
$metaVersion = new MetaVersionCollection('');
return new MetaDataNode($metaVersion);
}

function getChildren() {
try {
return [
$this->getChild('')
];
} catch(NotFound $exception) {
return [];
}
}

function childExists($name) {
try {
$ret = $this->getChild($name);
return !is_null($ret);
} catch (NotFound $ex) {
return false;
} catch (MethodNotAllowed $ex) {
return false;
}
}

function delete() {
throw new Forbidden('Permission denied to delete this folder');
}

function getName() {
return "meta";
}

function setName($name) {
throw new Forbidden('Permission denied to rename this folder');
}

/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
function getLastModified() {
return null;
}


}
89 changes: 89 additions & 0 deletions apps/dav/lib/MetaData/MetaDataNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* @author Sujith Haridasan <sharidasan@owncloud.com>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/


namespace OCA\DAV\MetaData;


use OC\Files\Meta\MetaVersionCollection;
use OCP\IMetaData;
use Sabre\DAV\File;

class MetaDataNode {

private $metaVersionCollection;
/**
* MetaDataNode constructor.
*
*/
public function __construct(MetaVersionCollection $metaVersionCollection) {
$this->metaVersionCollection = $metaVersionCollection;
}

/**
* Get the fileVersion Node
*
* @param $fileName
* @return \OCP\Files\Node
*/
public function getFileVersion($fileName) {
return $this->metaVersionCollection->get($fileName);
}

/**
* Get the name of the file
*
* @return string
*/
public function getName() {
return $this->metaVersionCollection->getName();
}

/**
* Returns the content of the file version
*
* @param $fileName
* @return false|string
*/
public function getFileVersionContent($fileName) {
$getVersion = $this->getFileVersion($fileName);
$path = $getVersion->getPath();
return $this->metaVersionCollection->getStorage()->file_get_contents($path);
}

/**
* Returns a list of versions (path) associated with file
*
* @param $fileName
* @return array
*/
public function getVersionsOfFile() {
$nodeVersionList = [];
$fileList = $this->metaVersionCollection->getDirectoryListing();

foreach ($fileList as $file) {
array_push($nodeVersionList, $file->getInternalPath());
}

return $nodeVersionList;
}

}
5 changes: 4 additions & 1 deletion apps/dav/lib/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function __construct() {
$avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
$avatarCollection->disableListing = $disableListing;

$metaDataCollection = new MetaData\MetaDataHome();

$children = [
new SimpleCollection('principals', [
$userPrincipals,
Expand All @@ -106,7 +108,8 @@ public function __construct() {
$systemTagCollection,
$systemTagRelationsCollection,
$uploadCollection,
$avatarCollection
$metaDataCollection,
$avatarCollection,
];

parent::__construct('root', $children);
Expand Down
Loading

0 comments on commit e74c028

Please sign in to comment.