Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 6b13cf7

Browse files
author
Julien Jomier
committed
ENH: Improved cassandra
1 parent 40546e1 commit 6b13cf7

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

core/models/base/UserModelBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public function createUser($email,$password,$firstname,$lastname,$admin=0)
7373
$feedpolicyuserModel=$this->ModelLoader->loadModel('Feedpolicyuser');
7474

7575
$anonymousGroup=$groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY);
76-
/*
76+
7777
$folderGlobal=$folderModel->createFolder('user_' . $userDao->getKey(),'Main folder of ' . $userDao->getFullName(),MIDAS_FOLDER_USERPARENT);
7878
$folderPrivate=$folderModel->createFolder('Private','Private folder of ' . $userDao->getFullName(),$folderGlobal);
7979
$folderPublic=$folderModel->createFolder('Public','Public folder of ' . $userDao->getFullName(),$folderGlobal);
80-
80+
8181
$folderpolicygroupModel->createPolicy($anonymousGroup,$folderPublic,MIDAS_POLICY_READ);
8282
$folderpolicyuserModel->createPolicy($userDao,$folderPrivate,MIDAS_POLICY_ADMIN);
8383
$folderpolicyuserModel->createPolicy($userDao,$folderGlobal,MIDAS_POLICY_ADMIN);
@@ -93,7 +93,7 @@ public function createUser($email,$password,$firstname,$lastname,$admin=0)
9393
$feed=$feedModel->createFeed($userDao,MIDAS_FEED_CREATE_USER,$userDao);
9494
$feedpolicygroupModel->createPolicy($anonymousGroup,$feed,MIDAS_POLICY_READ);
9595
$feedpolicyuserModel->createPolicy($userDao,$feed,MIDAS_POLICY_ADMIN);
96-
*/
96+
9797
return $userDao;
9898
}
9999

core/models/cassandra/FolderModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function getByFolder_id($folderid)
1414
try
1515
{
1616
$folder = new ColumnFamily($this->database->getDB(), 'folder');
17-
$folderarray = $folder->get($folderid);
17+
$folderarray = $folder->get($folderid);
1818
// Add the user_id
1919
$folderarray[$this->_key] = $folderid;
2020
$dao= $this->initDao('Folder',$userarray);

core/models/pdo/FolderModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class FolderModel extends FolderModelBase
1111
/** Get a folder by id */
1212
function getByFolder_id($folderid)
1313
{
14-
$row = $this->database->fetchRow($this->database->select()->where('folder_id = ?', $folderid));
15-
$dao= $this->initDao(ucfirst($this->_name),$row);
14+
$row = $this->database->fetchRow($this->database->select()->where('folder_id = ?', $folderid));
15+
$dao=$this->initDao(ucfirst($this->_name),$row);
1616
return $dao;
1717
} // end getByFolder_id()
1818

library/MIDAS/models/MIDASDatabaseCassandra.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,27 @@ public function getValue($var, $key, $dao)
131131
}
132132
else if ($this->_mainData[$var]['type'] == MIDAS_DATA && $key!=null)
133133
{
134-
/*$result = $this->fetchRow($this->select()->where($this->_key . ' = ?', $key));
135-
if (!isset($result->$var))
134+
try
136135
{
137-
return null;
136+
$columnfamily = new ColumnFamily($this->_db,$this->_name);
137+
$resultarray = $columnfamily->get($key); // retrieve only what we want
138+
if(!isset($resultarray[$var]))
139+
{
140+
throw new Zend_Exception('MIDASDatabaseCassandra::getValue() MIDAS_DATA not found. CF='.$this->_name.' and var='.$var);
141+
return null;
142+
}
143+
return $resultarray[$var];
138144
}
139-
return $result->$var;*/
145+
catch(cassandra_NotFoundException $e)
146+
{
147+
throw new Zend_Exception('MIDASDatabaseCassandra::getValue() MIDAS_DATA not found. CF='.$this->_name.' and var='.$var);
148+
return null;
149+
}
150+
catch(Exception $e)
151+
{
152+
throw new Zend_Exception($e);
153+
}
154+
140155
}
141156
else if ($this->_mainData[$var]['type'] == MIDAS_ONE_TO_MANY)
142157
{
@@ -147,17 +162,25 @@ public function getValue($var, $key, $dao)
147162
{
148163
throw new Zend_Exception($this->_mainData[$var]['parent_column']. " is not defined in the dao: ".get_class($dao));
149164
}
165+
throw new Zend_Exception('MIDASDatabaseCassandra::getValue() MIDAS_ONE_TO_MANY not defined yet. You can implement it if you want :)');
166+
150167
//return $model->__call("findBy" . ucfirst($this->_mainData[$var]['child_column']), array($dao->get($this->_mainData[$var]['parent_column'])));
151168
}
152169
else if ($this->_mainData[$var]['type'] == MIDAS_MANY_TO_ONE)
153170
{
154171
require_once BASE_PATH.'/library/MIDAS/models/ModelLoader.php';
155172
$this->ModelLoader = new MIDAS_ModelLoader();
156173
$model = $this->ModelLoader->loadModel($this->_mainData[$var]['model']);
157-
//return $model->__call("getBy" . ucfirst($this->_mainData[$var]['child_column']), array($dao->get($this->_mainData[$var]['parent_column'])));
174+
if(!method_exists($model, 'getBy'.ucfirst($this->_mainData[$var]['child_column'])))
175+
{
176+
throw new Zend_Exception(get_class($model).'::getBy'.ucfirst($this->_mainData[$var]['child_column'])." is not implemented");
177+
}
178+
return call_user_func(array($model,'getBy'.ucfirst($this->_mainData[$var]['child_column'])),
179+
array($dao->get($this->_mainData[$var]['parent_column'])));
158180
}
159181
else if ($this->_mainData[$var]['type'] == MIDAS_MANY_TO_MANY)
160182
{
183+
throw new Zend_Exception('MIDASDatabaseCassandra::getValue() MIDAS_MANY_TO_MANY not defined yet. You can implement it if you want :)');
161184
//return $this->getLinkedObject($var, $dao);
162185
}
163186
else

library/MIDAS/models/MIDASDatabasePdo.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ public function getValue($var, $key, $dao)
8686
require_once BASE_PATH.'/library/MIDAS/models/ModelLoader.php';
8787
$this->ModelLoader = new MIDAS_ModelLoader();
8888
$model = $this->ModelLoader->loadModel($this->_mainData[$var]['model']);
89+
if(!method_exists($model, 'getBy'.ucfirst($this->_mainData[$var]['child_column'])))
90+
{
91+
throw new Zend_Exception(get_class($model).'::getBy'.ucfirst($this->_mainData[$var]['child_column'])." is not implemented");
92+
}
8993
return call_user_func(array($model,'getBy'.ucfirst($this->_mainData[$var]['child_column'])),
9094
array($dao->get($this->_mainData[$var]['parent_column'])));
9195

92-
//$model->__call("getBy" . ucfirst($this->_mainData[$var]['child_column']), array($dao->get($this->_mainData[$var]['parent_column'])));
9396
}
9497
else if ($this->_mainData[$var]['type'] == MIDAS_MANY_TO_MANY)
9598
{

0 commit comments

Comments
 (0)