Session interface cleanup

This commit is contained in:
Victor Dubiniuk 2013-08-09 18:29:36 +03:00 committed by Tobias Hintze
parent 2b440eadcc
commit 4abcc12489
4 changed files with 21 additions and 39 deletions

View File

@ -39,7 +39,7 @@ class Controller {
$session = Session::getSessionByOwnerAndGenesis($uid, $genesisPath); $session = Session::getSessionByOwnerAndGenesis($uid, $genesisPath);
if (!$session){ if (!$session){
$hash = View::getHashByGenesis($uid, $genesisPath); $hash = View::getHashByGenesis($uid, $genesisPath);
$session = Session::addSession($genesisPath, $hash, $path); $session = Session::add($genesisPath, $hash, $path);
} }
\OCP\JSON::success($session); \OCP\JSON::success($session);
exit(); exit();

View File

@ -44,7 +44,7 @@ try{
$command = $request->getParam('command'); $command = $request->getParam('command');
switch ($command){ switch ($command){
case 'session-list': case 'session-list':
$sessions = OCA\Office\Session::getAllSessions(); $sessions = OCA\Office\Session::getAll();
if (!is_array($sessions)){ if (!is_array($sessions)){
$sessions = array(); $sessions = array();
} }

View File

@ -1,18 +0,0 @@
<?php
/**
* ownCloud - Office App
*
* @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.
*/
namespace OCA\Office;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::success(array(
'sessions' => Session::getAllSessions()
));

View File

@ -13,25 +13,7 @@ namespace OCA\Office;
class Session { class Session {
public static function getAllSessions(){ public static function add($genesis, $hash, $documentPath){
$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){
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`, `document_path`) VALUES (?, ?, ?, ?, ?) '); $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`, `document_path`) VALUES (?, ?, ?, ?, ?) ');
$data = array( $data = array(
@ -49,6 +31,24 @@ class Session {
return false; 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(){ protected static function getUniqueSessionId(){
do { do {
$id = \OC_Util::generate_random_bytes(30); $id = \OC_Util::generate_random_bytes(30);