-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing metadata collections in dav
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
Showing
6 changed files
with
449 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.