diff --git a/appinfo/app.php b/appinfo/app.php index db7e43eb..c57024a1 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -36,8 +36,3 @@ OCP\App::addNavigationEntry(array( 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\Range'] = 'office/lib/download/range.php'; - -// Testing -if (!\OCA\Office\Session::getSession('dev0')){ - \OCA\Office\Session::setMockSession(); -} \ No newline at end of file diff --git a/lib/session.php b/lib/session.php index 83a16995..fa8c95f8 100644 --- a/lib/session.php +++ b/lib/session.php @@ -22,13 +22,13 @@ class Session { 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 (?, ?, ?, ?) '); $data = array( self::getSessionId(), $genesis, - self::getHash($genesis), + $hash, \OCP\User::getUser() ); $result = $query->execute($data); @@ -39,14 +39,8 @@ class Session { return false; } - public static function setMockSession(){ - //self::addSession('/welcome.odt'); - } protected static function getSessionId(){ return (string) time(); } - protected static function getHash($genesis){ - return '0xdeadbeef'; - } } diff --git a/lib/view.php b/lib/view.php index 1ad952db..44f9e0fa 100644 --- a/lib/view.php +++ b/lib/view.php @@ -12,20 +12,28 @@ class View extends \OC\Files\View{ $view->mkdir(self::OFFICE_DIRNAME); } - if (!self::$officeView){ - self::$officeView = new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME); - } + //if (!self::$officeView){ + // 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){ - $view = new \OC\Files\View('/' . $uid); - $proxyStatus = \OC_FileProxy::$enabled; \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; - return $path; + return $newName; + } + + public static function getHashByGenesis($uid, $genesisPath){ + $officeView = self::initOfficeView($uid); + return sha1($officeView->file_get_contents($genesisPath)); } }