This commit is contained in:
Frédéric FRANCE 2020-12-05 23:57:31 +01:00
parent 4e18f46f28
commit fbc0be3a43
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1

View File

@ -32,7 +32,7 @@ class Comment extends CommonObject
public $table_element = 'comment';
/**
* @var int ID of parent key (it's nome the name of a field)
* @var int ID of parent key (it's not the name of a field)
*/
public $fk_element;
@ -75,10 +75,16 @@ class Comment extends CommonObject
*/
public $entity;
/**
* @var string import key
*/
public $import_key;
public $comments = array();
/**
* @var Comment Object oldcopy
*/
public $oldcopy;
@ -134,26 +140,26 @@ class Comment extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
if (!$notrigger)
{
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('TASK_COMMENT_CREATE', $user);
if ($result < 0) { $error++; }
if ($result < 0) {
$error++;
}
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -193,12 +199,10 @@ class Comment extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num_rows = $this->db->num_rows($resql);
if ($num_rows)
{
if ($num_rows) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -215,8 +219,11 @@ class Comment extends CommonObject
$this->db->free($resql);
if ($num_rows) return 1;
else return 0;
if ($num_rows) {
return 1;
} else {
return 0;
}
} else {
$this->error = "Error ".$this->db->lasterror();
return -1;
@ -237,8 +244,12 @@ class Comment extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->fk_element)) $this->fk_project = (int) trim($this->fk_element);
if (isset($this->description)) $this->description = trim($this->description);
if (isset($this->fk_element)) {
$this->fk_project = (int) trim($this->fk_element);
}
if (isset($this->description)) {
$this->description = trim($this->description);
}
// Update request
@ -256,24 +267,24 @@ class Comment extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$notrigger)
{
if (!$error) {
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('TASK_COMMENT_MODIFY', $user);
if ($result < 0) { $error++; }
if ($result < 0) {
$error++;
}
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -306,24 +317,24 @@ class Comment extends CommonObject
$sql .= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$notrigger)
{
if (!$error) {
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('TASK_COMMENT_DELETE', $user);
if ($result < 0) { $error++; }
if ($result < 0) {
$error++;
}
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -358,13 +369,10 @@ class Comment extends CommonObject
dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num_rows = $this->db->num_rows($resql);
if ($num_rows > 0)
{
while ($obj = $this->db->fetch_object($resql))
{
if ($num_rows > 0) {
while ($obj = $this->db->fetch_object($resql)) {
$comment = new self($db);
$comment->fetch($obj->rowid);
$this->comments[] = $comment;