diff --git a/ajax/controller.php b/ajax/controller.php index 2e4b6310..01c9622b 100644 --- a/ajax/controller.php +++ b/ajax/controller.php @@ -39,7 +39,7 @@ class Controller { $session = Session::getSessionByOwnerAndGenesis($uid, $genesisPath); if (!$session){ $hash = View::getHashByGenesis($uid, $genesisPath); - $session = Session::addSession($genesisPath, $hash, $path); + $session = Session::add($genesisPath, $hash, $path); } \OCP\JSON::success($session); exit(); diff --git a/ajax/otpoll.php b/ajax/otpoll.php index b23d3568..4c73e3a6 100644 --- a/ajax/otpoll.php +++ b/ajax/otpoll.php @@ -44,7 +44,7 @@ try{ $command = $request->getParam('command'); switch ($command){ case 'session-list': - $sessions = OCA\Office\Session::getAllSessions(); + $sessions = OCA\Office\Session::getAll(); if (!is_array($sessions)){ $sessions = array(); } diff --git a/ajax/sessions.php b/ajax/sessions.php deleted file mode 100644 index d7526d9e..00000000 --- a/ajax/sessions.php +++ /dev/null @@ -1,18 +0,0 @@ - Session::getAllSessions() -)); \ No newline at end of file diff --git a/lib/session.php b/lib/session.php index 0cde911d..d6fb55b9 100644 --- a/lib/session.php +++ b/lib/session.php @@ -13,25 +13,7 @@ namespace OCA\Office; class Session { - public static function getAllSessions(){ - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session`'); - $result = $query->execute(); - return $result->fetchAll(); - } - - public static function getSession($id){ - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `es_id`= ?'); - $result = $query->execute(array($id)); - return $result->fetchRow(); - } - - public static function getSessionByOwnerAndGenesis($uid, $url){ - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? '); - $result = $query->execute(array($url, $uid)); - return $result->fetchRow(); - } - - public static function addSession($genesis, $hash, $documentPath){ + public static function add($genesis, $hash, $documentPath){ $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`, `document_path`) VALUES (?, ?, ?, ?, ?) '); $data = array( @@ -49,6 +31,24 @@ class Session { return false; } + public static function getAll(){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session`'); + $result = $query->execute(); + return $result->fetchAll(); + } + + public static function getSession($id){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `es_id`= ?'); + $result = $query->execute(array($id)); + return $result->fetchRow(); + } + + public static function getSessionByOwnerAndGenesis($uid, $url){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? '); + $result = $query->execute(array($url, $uid)); + return $result->fetchRow(); + } + protected static function getUniqueSessionId(){ do { $id = \OC_Util::generate_random_bytes(30);