Store genesis as sha1(content)
This commit is contained in:
parent
9586253c38
commit
76682cfe1c
@ -36,8 +36,3 @@ OCP\App::addNavigationEntry(array(
|
|||||||
OC::$CLASSPATH['OCA\Office\Genesis'] = 'office/lib/genesis.php';
|
OC::$CLASSPATH['OCA\Office\Genesis'] = 'office/lib/genesis.php';
|
||||||
OC::$CLASSPATH['OCA\Office\Download\Simple'] = 'office/lib/download/simple.php';
|
OC::$CLASSPATH['OCA\Office\Download\Simple'] = 'office/lib/download/simple.php';
|
||||||
OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php';
|
OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php';
|
||||||
|
|
||||||
// Testing
|
|
||||||
if (!\OCA\Office\Session::getSession('dev0')){
|
|
||||||
\OCA\Office\Session::setMockSession();
|
|
||||||
}
|
|
@ -22,13 +22,13 @@ class Session {
|
|||||||
return $result->fetchRow();
|
return $result->fetchRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addSession($genesis){
|
public static function addSession($genesis, $hash){
|
||||||
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`) VALUES (?, ?, ?, ?) ');
|
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`) VALUES (?, ?, ?, ?) ');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
self::getSessionId(),
|
self::getSessionId(),
|
||||||
$genesis,
|
$genesis,
|
||||||
self::getHash($genesis),
|
$hash,
|
||||||
\OCP\User::getUser()
|
\OCP\User::getUser()
|
||||||
);
|
);
|
||||||
$result = $query->execute($data);
|
$result = $query->execute($data);
|
||||||
@ -39,14 +39,8 @@ class Session {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setMockSession(){
|
|
||||||
//self::addSession('/welcome.odt');
|
|
||||||
}
|
|
||||||
protected static function getSessionId(){
|
protected static function getSessionId(){
|
||||||
return (string) time();
|
return (string) time();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function getHash($genesis){
|
|
||||||
return '0xdeadbeef';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
24
lib/view.php
24
lib/view.php
@ -12,20 +12,28 @@ class View extends \OC\Files\View{
|
|||||||
$view->mkdir(self::OFFICE_DIRNAME);
|
$view->mkdir(self::OFFICE_DIRNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self::$officeView){
|
//if (!self::$officeView){
|
||||||
self::$officeView = new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME);
|
// self::$officeView = new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME);
|
||||||
}
|
//}
|
||||||
|
|
||||||
return self::$officeView;
|
// it was a bad idea to use a static method.
|
||||||
|
// to be changed later
|
||||||
|
return new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeDocument($uid, $path){
|
public static function storeDocument($uid, $path){
|
||||||
$view = new \OC\Files\View('/' . $uid);
|
|
||||||
|
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
$view->copy('/files' . $path, self::OFFICE_DIRNAME . $path);
|
|
||||||
|
$newName = '/' . self::getHashByGenesis($uid, $path) . '.odt';
|
||||||
|
$view = new \OC\Files\View('/' . $uid);
|
||||||
|
$view->copy('/files' . $path, self::OFFICE_DIRNAME . $newName);
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
return $path;
|
return $newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getHashByGenesis($uid, $genesisPath){
|
||||||
|
$officeView = self::initOfficeView($uid);
|
||||||
|
return sha1($officeView->file_get_contents($genesisPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user