richdocuments/lib/view.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2013-08-07 21:14:36 +03:00
<?php
2013-08-08 00:22:21 +03:00
/**
2013-08-28 12:02:27 +02:00
* ownCloud - Documents App
2013-08-08 00:22:21 +03:00
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
2013-08-07 21:14:36 +03:00
2013-08-28 12:02:27 +02:00
namespace OCA\Documents;
2013-08-07 21:14:36 +03:00
class View extends \OC\Files\View{
2013-08-28 12:02:27 +02:00
const DOCUMENTS_DIRNAME='/documents';
protected static $documentsView;
2013-08-07 21:14:36 +03:00
2013-08-28 12:02:27 +02:00
public static function initDocumentsView($uid){
2013-08-07 21:14:36 +03:00
$view = new \OC\Files\View('/' . $uid);
2013-08-28 12:02:27 +02:00
if (!$view->is_dir(self::DOCUMENTS_DIRNAME)) {
$view->mkdir(self::DOCUMENTS_DIRNAME);
2013-08-07 21:14:36 +03:00
}
2013-08-28 12:02:27 +02:00
//if (!self::$documentsView){
// self::$documentsView = new \OC\Files\View('/' . $uid . self::DOCUMENTS_DIRNAME);
2013-08-08 00:08:20 +03:00
//}
2013-08-07 21:14:36 +03:00
2013-08-08 00:08:20 +03:00
// it was a bad idea to use a static method.
// to be changed later
2013-08-28 12:02:27 +02:00
return new \OC\Files\View('/' . $uid . self::DOCUMENTS_DIRNAME);
2013-08-07 21:14:36 +03:00
}
public static function storeDocument($uid, $filePath){
2013-08-07 21:14:36 +03:00
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
2013-08-08 00:08:20 +03:00
$view = new \OC\Files\View('/' . $uid);
if (!$view->file_exists($filePath)){
throw new \Exception($filePath . ' doesn\'t exist');
2013-08-17 19:42:50 +03:00
}
if (!$view->is_file($filePath)){
throw new \Exception('Object ' . $filePath . ' is not a file.');
}
$newName = '/' . sha1($view->file_get_contents($filePath)) . '.odt';
2013-08-08 14:02:54 +03:00
$view->copy($filePath, self::DOCUMENTS_DIRNAME . $newName);
2013-08-07 21:14:36 +03:00
\OC_FileProxy::$enabled = $proxyStatus;
2013-08-08 00:08:20 +03:00
return $newName;
}
public static function getHashByGenesis($uid, $genesisPath){
2013-08-28 12:02:27 +02:00
$documentsView = self::initDocumentsView($uid);
return sha1($documentsView->file_get_contents($genesisPath));
2013-08-07 21:14:36 +03:00
}
}