Browse Source

FIX last_main_doc var not saved

Conflicts:
	htdocs/core/class/commonobject.class.php
Laurent Destailleur 6 years ago
parent
commit
3d218cadb7
1 changed files with 12 additions and 1 deletions
  1. 12 1
      htdocs/core/class/commonobject.class.php

+ 12 - 1
htdocs/core/class/commonobject.class.php

@@ -311,6 +311,12 @@ abstract class CommonObject
 	 */
 	public $modelpdf;
 
+	/**
+	 * @var string
+	 * Contains relative path of last generated main file
+	 */
+	public $last_main_doc;
+
 	/**
 	 * @var int Bank account ID
 	 * @see SetBankAccount()
@@ -4611,10 +4617,15 @@ abstract class CommonObject
 						if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1;
 						if ($update_main_doc_field && ! empty($this->table_element))
 						{
-							$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'";
+							$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath.'/'.$ecmfile->filename)."'";
 							$sql.= ' WHERE rowid = '.$this->id;
+
 							$resql = $this->db->query($sql);
 							if (! $resql) dol_print_error($this->db);
+							else
+							{
+							    $this->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
+							}
 						}
 					}
 				}