diff --git a/ajax/controller.php b/ajax/controller.php index c8d85a84..4b682ea1 100644 --- a/ajax/controller.php +++ b/ajax/controller.php @@ -31,13 +31,16 @@ class Controller { public static function startSession($args){ $uid = self::preDispatch(); try{ - $fileId = @$_POST['fileid']; - if (!$fileId){ - throw new \Exception('No fileId has been passed'); + $path = @$_POST['path']; + if (!$path){ + throw new \Exception('No file has been passed'); } $officeView = View::initOfficeView($uid); - $genesisPath = View::storeDocument($uid, $fileId); + $genesisPath = View::storeDocument($uid, $path); + $info = \OC_Files::getFileInfo($path); + + $fileId = $info['fileid']; if (!$genesisPath){ throw new \Exception('Unable to copy document. Check permissions and make sure you have enought free space.'); } @@ -52,7 +55,7 @@ class Controller { \OCP\JSON::success($session); exit(); } catch (\Exception $e){ - Helper::warnLog('Starting a session failed. Reason:') . $e->getMessage(); + Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage()); \OCP\JSON::error(); exit(); } @@ -75,7 +78,7 @@ class Controller { \OCP\JSON::success($session); exit(); } catch (\Exception $e){ - Helper::warnLog('Joining a session failed. Reason:') . $e->getMessage(); + Helper::warnLog('Joining a session failed. Reason:' . $e->getMessage()); \OCP\JSON::error(); exit(); } diff --git a/ajax/otpoll.php b/ajax/otpoll.php index 8d97e03d..ff42d3db 100644 --- a/ajax/otpoll.php +++ b/ajax/otpoll.php @@ -66,18 +66,6 @@ try{ $members ); - break; - case 'session_list': - OCA\Office\Controller::listSessions(); - exit(); - break; - case 'join_session': - // should fail when session is non-existent - break; - OCA\Office\Controller::joinSession(array( - 'es_id' => $request->getParam('args/es_id') - )); - exit(); break; case 'sync_ops': $seqHead = (string) $request->getParam('args/seq_head'); diff --git a/js/office.js b/js/office.js index 503dfe4d..6e3efa1d 100644 --- a/js/office.js +++ b/js/office.js @@ -92,7 +92,7 @@ var officeMain = { } $.post(OC.Router.generate('office_session_start'), - {'fileid': filepath}, + {'path': filepath}, officeMain.initSession ); }, diff --git a/lib/session.php b/lib/session.php index 153a310a..b08976dc 100644 --- a/lib/session.php +++ b/lib/session.php @@ -59,7 +59,7 @@ class Session { } return $info; } - + public static function getSessionByFileId($fileId){ $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `file_id`= ?'); $result = $query->execute(array($fileId)); diff --git a/lib/view.php b/lib/view.php index c9771738..511d4f73 100644 --- a/lib/view.php +++ b/lib/view.php @@ -30,21 +30,20 @@ class View extends \OC\Files\View{ return new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME); } - public static function storeDocument($uid, $fileid){ + public static function storeDocument($uid, $filePath){ $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - $path = \OC\Files\Cache\Cache::getById($fileid); - if (is_null($path)){ - // No longer exists - } else { - $path = $path[1]; + $view = new \OC\Files\View('/' . $uid); + + $relPath = '/files' . $filePath; + if (!$view->file_exists($relPath)){ + throw new \Exception('Original document doesn\'t exist any more'); } - $view = new \OC\Files\View('/' . $uid); $newName = '/' . sha1($view->file_get_contents($path)) . '.odt'; - $view->copy( $path, self::OFFICE_DIRNAME . $newName); + $view->copy($relPath, self::OFFICE_DIRNAME . $newName); \OC_FileProxy::$enabled = $proxyStatus; return $newName; } diff --git a/templates/documents.php b/templates/documents.php index e179f9c5..7c15527d 100755 --- a/templates/documents.php +++ b/templates/documents.php @@ -29,7 +29,7 @@ - +