Bugfixing action class and adding error handling of sql querries

This commit is contained in:
Steven Mondji-Lerider 2013-04-22 13:28:59 +00:00
parent 2f58f53e63
commit c1d2971463
1 changed files with 29 additions and 18 deletions

View File

@ -56,7 +56,7 @@ class m_action {
* function archiving a directory ( upon account deletion ) * function archiving a directory ( upon account deletion )
*/ */
function archive($archive,$dir) { function archive($archive,$dir) {
global $cuid,$db; global $cuid,$db,$err;
$db->query("select login from membres where uid=$cuid;"); $db->query("select login from membres where uid=$cuid;");
$db->next_record(); $db->next_record();
if (!$db->Record["login"]) { if (!$db->Record["login"]) {
@ -75,36 +75,39 @@ class m_action {
*function inserting the action in the sql table *function inserting the action in the sql table
*/ */
function set($type,$user,$parameters) { function set($type,$user,$parameters) {
global $db; global $db,$err;
$serialized=serialize($parameters); $serialized=serialize($parameters);
switch($type){ switch($type){
case 'create_file': case 'create_file':
//do some shit //do some shit
$query="insert into actions values ('','CREATE_FILE','$serialized','','','','$user','');"; $query="insert into actions values ('','CREATE_FILE','$serialized',now(),'','','$user','');";
break; break;
case 'create_dir': case 'create_dir':
//do more shit //do more shit
$query="insert into actions values ('','CREATE_DIR','$serialized','','','','$user','');"; $query="insert into actions values ('','CREATE_DIR','$serialized',now(),'','','$user','');";
break; break;
case 'move': case 'move':
//do more shit //do more shit
$query="insert into actions values ('','MOVE','$serialized','','','','$user','');"; $query="insert into actions values ('','MOVE','$serialized',now(),'','','$user','');";
break; break;
case 'delete': case 'delete':
//do more shit //do more shit
$query="insert into actions values ('','DELETE','$serialized','','','','$user','');"; $query="insert into actions values ('','DELETE','$serialized',now(),'','','$user','');";
break;
case 'archive':
//do more shit
$query="insert into actions values ('','ARCHIVE','$serialized','','','','$user','');";
break; break;
default: default:
return false; return false;
} }
if(!$db->query($query)) if(!$db->query($query)){
$err->raise("action",_("Error setting actions"));
return false; return false;
return true }
$purge="delete actions where HOUR(now()) - HOUR(creation) > 1;";
if(!$db->query($purge)){
$err->raise("action",_("Error purging old actions"));
return false;
}
return true;
} }
@ -112,31 +115,39 @@ class m_action {
* function returning the first not locked line of the action table * function returning the first not locked line of the action table
*/ */
function get_action() { function get_action() {
global $db; global $db,$err;
$tab=array(); $tab=array();
$db->query('select * from actions where end is null and begin is null order by id limit 1;'); $db->query('select * from actions where end is null and begin is null order by id limit 1;');
if ($db->next_record()){ if ($db->next_record()){
$tab[]=$db->Record; $tab[]=$db->Record;
return $tab; return $tab;
}else }else{
$err->raise("action",_("Error selecting new action"));
return false; return false;
}
} }
/* /*
* function locking an entry while it is being executed by the action script * function locking an entry while it is being executed by the action script
*/ */
function begin($id) { function begin($id) {
global $db; global $db,$err;
$db->query("update actions set begin=now() where id=$id "); if($db->query("update actions set begin=now() where id=$id ")){
$err->raise("action",_("Error in setting locking the action : $id"));
return false;
}
return true; return true;
} }
/* /*
* function locking an entry while it is being executed by the action script * function locking an entry while it is being executed by the action script
*/ */
function finish($id,$return=0) { function finish($id,$return=0) {
global $db; global $db,$err;
$return=intval($return); $return=intval($return);
$db->query("update actions set end=now(),status=$return where id=$id"); if($db->query("update actions set end=now(),status=$return where id=$id")){
$err->raise("action",_("Error unlocking the action : $id"));
return false;
}
return true; return true;
} }
/* /*