FIX issue on Task delete
Added a control on time spent so it is not possible to delete a task where some time spent has already been tracked.
This commit is contained in:
parent
49fc8129ac
commit
c6bd1a7d7d
@ -535,6 +535,40 @@ class Task extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return nb of time spent
|
||||||
|
*
|
||||||
|
* @return int <0 if KO, 0 if no children, >0 if OK
|
||||||
|
*/
|
||||||
|
function hasTimeSpent()
|
||||||
|
{
|
||||||
|
$error=0;
|
||||||
|
$ret=0;
|
||||||
|
|
||||||
|
$sql = "SELECT COUNT(*) as nb";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time";
|
||||||
|
$sql.= " WHERE fk_task=".$this->id;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::hasTimeSpent", LOG_DEBUG);
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$obj=$this->db->fetch_object($resql);
|
||||||
|
if ($obj) $ret=$obj->nb;
|
||||||
|
$this->db->free($resql);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return clicable name (with picto eventually)
|
* Return clicable name (with picto eventually)
|
||||||
|
|||||||
@ -551,7 +551,7 @@ if ($id > 0 || ! empty($ref))
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
if ($user->rights->projet->supprimer && ! $object->hasChildren())
|
if ($user->rights->projet->supprimer && ! $object->hasChildren() && ! $object->hasTimeSpent())
|
||||||
{
|
{
|
||||||
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&withproject='.$withproject.'">'.$langs->trans('Delete').'</a>';
|
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&withproject='.$withproject.'">'.$langs->trans('Delete').'</a>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user