forked from Wavyzz/dolibarr
Debug v15
This commit is contained in:
@@ -5292,103 +5292,14 @@ abstract class CommonObject
|
||||
// Index file in database
|
||||
if (!empty($obj->result['fullpath'])) {
|
||||
$destfull = $obj->result['fullpath'];
|
||||
$upload_dir = dirname($destfull);
|
||||
$destfile = basename($destfull);
|
||||
$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
|
||||
|
||||
if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { // If not a tmp dir
|
||||
$filename = basename($destfile);
|
||||
$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
||||
$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
|
||||
$ecmfile = new EcmFiles($this->db);
|
||||
$result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename);
|
||||
|
||||
// Set the public "share" key
|
||||
$setsharekey = false;
|
||||
if ($this->element == 'propal') {
|
||||
$useonlinesignature = 1; // Replace this with 1 when feature to make online signature is ok
|
||||
if ($useonlinesignature) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
}
|
||||
if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
|
||||
if ($setsharekey) {
|
||||
if (empty($ecmfile->share)) { // Because object not found or share not set yet
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||
$ecmfile->share = getRandomPassword(true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result > 0) {
|
||||
$ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content
|
||||
$ecmfile->fullpath_orig = '';
|
||||
$ecmfile->gen_or_uploaded = 'generated';
|
||||
$ecmfile->description = ''; // indexed content
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
$result = $ecmfile->update($user);
|
||||
if ($result < 0) {
|
||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
||||
}
|
||||
} else {
|
||||
$ecmfile->entity = $conf->entity;
|
||||
$ecmfile->filepath = $rel_dir;
|
||||
$ecmfile->filename = $filename;
|
||||
$ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content
|
||||
$ecmfile->fullpath_orig = '';
|
||||
$ecmfile->gen_or_uploaded = 'generated';
|
||||
$ecmfile->description = ''; // indexed content
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
$ecmfile->src_object_type = $this->table_element; // $this->table_name is 'myobject' or 'mymodule_myobject'.
|
||||
$ecmfile->src_object_id = $this->id;
|
||||
|
||||
$result = $ecmfile->create($user);
|
||||
if ($result < 0) {
|
||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
||||
}
|
||||
}
|
||||
|
||||
/*$this->result['fullname']=$destfull;
|
||||
$this->result['filepath']=$ecmfile->filepath;
|
||||
$this->result['filename']=$ecmfile->filename;*/
|
||||
//var_dump($obj->update_main_doc_field);exit;
|
||||
|
||||
// Update the last_main_doc field into main object (if document generator has property ->update_main_doc_field set)
|
||||
$update_main_doc_field = 0;
|
||||
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 = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'";
|
||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
dol_print_error($this->db);
|
||||
} else {
|
||||
$this->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
|
||||
}
|
||||
}
|
||||
// Update the last_main_doc field into main object (if document generator has property ->update_main_doc_field set)
|
||||
$update_main_doc_field = 0;
|
||||
if (!empty($obj->update_main_doc_field)) {
|
||||
$update_main_doc_field = 1;
|
||||
}
|
||||
|
||||
$this->indexFile($destfull, $update_main_doc_field);
|
||||
} else {
|
||||
dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
|
||||
}
|
||||
@@ -5417,6 +5328,115 @@ abstract class CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Index a file into the ECM database
|
||||
*
|
||||
* @param string $destfull Full path of file to index
|
||||
* @param int $update_main_doc_field Update field main_doc file into table of object
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function indexFile($destfull, $update_main_doc_field)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$upload_dir = dirname($destfull);
|
||||
$destfile = basename($destfull);
|
||||
$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
|
||||
|
||||
if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { // If not a tmp dir
|
||||
$filename = basename($destfile);
|
||||
$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
||||
$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
|
||||
$ecmfile = new EcmFiles($this->db);
|
||||
$result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename);
|
||||
|
||||
// Set the public "share" key
|
||||
$setsharekey = false;
|
||||
if ($this->element == 'propal' || $this->element == 'proposal') {
|
||||
if (!isset($conf->global->PROPOSAL_ALLOW_ONLINESIGN) || !empty($conf->global->PROPOSAL_ALLOW_ONLINESIGN)) {
|
||||
$setsharekey = true; // feature to make online signature is not set or set to on (default)
|
||||
}
|
||||
if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
}
|
||||
if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
if ($this->element == 'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
|
||||
$setsharekey = true;
|
||||
}
|
||||
|
||||
if ($setsharekey) {
|
||||
if (empty($ecmfile->share)) { // Because object not found or share not set yet
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||
$ecmfile->share = getRandomPassword(true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result > 0) {
|
||||
$ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content
|
||||
$ecmfile->fullpath_orig = '';
|
||||
$ecmfile->gen_or_uploaded = 'generated';
|
||||
$ecmfile->description = ''; // indexed content
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
$result = $ecmfile->update($user);
|
||||
if ($result < 0) {
|
||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
$ecmfile->entity = $conf->entity;
|
||||
$ecmfile->filepath = $rel_dir;
|
||||
$ecmfile->filename = $filename;
|
||||
$ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content
|
||||
$ecmfile->fullpath_orig = '';
|
||||
$ecmfile->gen_or_uploaded = 'generated';
|
||||
$ecmfile->description = ''; // indexed content
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
$ecmfile->src_object_type = $this->table_element; // $this->table_name is 'myobject' or 'mymodule_myobject'.
|
||||
$ecmfile->src_object_id = $this->id;
|
||||
|
||||
$result = $ecmfile->create($user);
|
||||
if ($result < 0) {
|
||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*$this->result['fullname']=$destfull;
|
||||
$this->result['filepath']=$ecmfile->filepath;
|
||||
$this->result['filename']=$ecmfile->filename;*/
|
||||
//var_dump($obj->update_main_doc_field);exit;
|
||||
|
||||
if ($update_main_doc_field && !empty($this->table_element)) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'";
|
||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
} else {
|
||||
$this->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build thumb
|
||||
* @todo Move this into files.lib.php
|
||||
|
||||
Reference in New Issue
Block a user