From 9a7113f4f5295b610e853beb3549257aad0413e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jul 2019 22:26:55 +0200 Subject: [PATCH 1/7] FIX Update the file index table when we validate/rename a ref. --- htdocs/bom/class/bom.class.php | 14 ++++++++++---- htdocs/comm/propal/class/propal.class.php | 16 ++++++++++------ htdocs/commande/class/commande.class.php | 12 +++++++++--- htdocs/compta/facture/class/facture.class.php | 11 ++++++++--- htdocs/contrat/class/contrat.class.php | 11 ++++++++--- htdocs/expedition/class/expedition.class.php | 11 ++++++++--- .../expensereport/class/expensereport.class.php | 12 +++++++++--- htdocs/fichinter/class/fichinter.class.php | 13 ++++++++++--- .../fourn/class/fournisseur.commande.class.php | 11 ++++++++--- htdocs/fourn/class/fournisseur.facture.class.php | 13 +++++++++---- htdocs/livraison/class/livraison.class.php | 11 ++++++++--- htdocs/reception/class/reception.class.php | 11 ++++++++--- .../class/supplier_proposal.class.php | 16 ++++++++++------ 13 files changed, 115 insertions(+), 47 deletions(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 10601303a61..dd861d5dc47 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -515,6 +515,7 @@ class BOM extends CommonObject public function valid($user, $notrigger = 0) { global $conf, $langs; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; @@ -582,13 +583,18 @@ class BOM extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref) - // in order not to lose the attachments - $oldref = dol_sanitizeFileName($this->ref); + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'bom/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'bom/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments + $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->bom->dir_output.'/'.$oldref; $dirdest = $conf->bom->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 0d3eacc56a4..5de2c9b23f5 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1739,10 +1739,10 @@ class Propal extends CommonObject */ public function valid($user, $notrigger = 0) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - global $conf; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $error=0; // Protection @@ -1808,14 +1808,18 @@ class Propal extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // Rename of propal directory ($this->ref = old ref, $num = new ref) - // to not lose the linked files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'propale/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'propale/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->propal->multidir_output[$this->entity].'/'.$oldref; $dirdest = $conf->propal->multidir_output[$this->entity].'/'.$newref; - - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index fd7832f868f..d0e0addbc94 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -321,6 +321,7 @@ class Commande extends CommonOrder public function valid($user, $idwarehouse = 0, $notrigger = 0) { global $conf,$langs; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; @@ -423,13 +424,18 @@ class Commande extends CommonOrder // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref) - // in order not to lose the attachments + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'commande/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'commande/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->commande->dir_output.'/'.$oldref; $dirdest = $conf->commande->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e5041217cb3..2a9a4f5686d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2418,13 +2418,18 @@ class Facture extends CommonInvoice // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // Rename of object directory ($this->ref = old ref, $num = new ref) - // to not lose the linked files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'facture/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'facture/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->facture->dir_output.'/'.$oldref; $dirdest = $conf->facture->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 6396b5e5f88..0b08d3723da 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -486,13 +486,18 @@ class Contrat extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // Rename of object directory ($this->ref = old ref, $num = new ref) - // to not lose the linked files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'contract/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'contract/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->contract->dir_output.'/'.$oldref; $dirdest = $conf->contract->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index d79b6976630..37f191a0ab0 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -813,13 +813,18 @@ class Expedition extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) - // in order not to lose the attached files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'expedition/sending/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'expedition/sending/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($numref); $dirsource = $conf->expedition->dir_output.'/sending/'.$oldref; $dirdest = $conf->expedition->dir_output.'/sending/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 3bdd026e62f..4cc935f95a2 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1151,13 +1151,18 @@ class ExpenseReport extends CommonObject { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - // On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref) - // in order not to lose the attachments + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'expensereport/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'expensereport/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->expensereport->dir_output.'/'.$oldref; $dirdest = $conf->expensereport->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::setValidate() rename dir ".$dirsource." into ".$dirdest); @@ -1176,6 +1181,7 @@ class ExpenseReport extends CommonObject } } } + } } diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 807b547a4bc..ce066fc8c11 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -574,13 +574,20 @@ class Fichinter extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // Rename of object directory ($this->ref = old ref, $num = new ref) - // to not lose the linked files + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'ficheinter/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'ficheinter/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->ficheinter->dir_output.'/'.$oldref; $dirdest = $conf->ficheinter->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 1dddd3e7319..b32e90c311d 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -551,13 +551,18 @@ class CommandeFournisseur extends CommonOrder // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // We rename directory ($this->ref = ancienne ref, $num = nouvelle ref) - // in order not to lose the attached files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'fournisseur/commande/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'fournisseur/commande/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->fournisseur->commande->dir_output.'/'.$oldref; $dirdest = $conf->fournisseur->commande->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 15169e79f6d..b13925bf29d 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1322,6 +1322,7 @@ class FactureFournisseur extends CommonInvoice public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0) { global $conf,$langs; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $now=dol_now(); @@ -1418,14 +1419,18 @@ class FactureFournisseur extends CommonInvoice // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref) - // in order not to lose the attached files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); - $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$oldref; $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 9a84274d0c5..f24a2aee713 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -441,13 +441,18 @@ class Livraison extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) - // afin de ne pas perdre les fichiers attaches + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'expedition/receipt/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'expedition/receipt/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($numref); $dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref; $dirdest = $conf->expedition->dir_output.'/receipt/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 811c2b8586f..84f95e40b9a 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -643,13 +643,18 @@ class Reception extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) - // in order not to lose the attached files + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'reception/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'reception/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($numref); $dirsource = $conf->reception->dir_output.'/'.$oldref; $dirdest = $conf->reception->dir_output.'/'.$newref; - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index ca16348dcd6..786485ad6dd 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1484,16 +1484,20 @@ class SupplierProposal extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { - // Rename of propal directory ($this->ref = old ref, $num = new ref) - // to not lose the linked files - $oldref = dol_sanitizeFileName($this->ref); + // Now we rename also files into index + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->newref."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'supplier_proposal/".$this->newref."'"; + $sql.= " WHERE filename LIKE '".$this->ref."%' AND filepath = 'supplier_proposal/".$this->ref."' and entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + + // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments + $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->supplier_proposal->dir_output.'/'.$oldref; $dirdest = $conf->supplier_proposal->dir_output.'/'.$newref; - - if (file_exists($dirsource)) + if (! $error && file_exists($dirsource)) { - dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); + dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); From 4e26eefe6e2c909c3a00a7de8f779e2fb9f8399d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jul 2019 22:57:07 +0200 Subject: [PATCH 2/7] Fix field not mandatory --- htdocs/stripe/admin/stripe.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 3966a3f439f..770678aae15 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -194,7 +194,7 @@ if (empty($conf->stripeconnect->enabled)) print ''; print ''; - print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; + print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { print ''; print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; @@ -267,7 +267,7 @@ if (empty($conf->stripeconnect->enabled)) print ''; print ''; - print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; + print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { print ''; print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; From a63a6a58537fda283d8c8fa76733737fa0b7ad4a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jul 2019 23:49:05 +0200 Subject: [PATCH 3/7] FIX Online payment --- htdocs/public/payment/newpayment.php | 44 ++++++++++++++++++++++++++-- htdocs/theme/eldy/global.inc.php | 3 ++ htdocs/theme/md/style.css.php | 3 ++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 5d04b6335c7..8c9eb93004f 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1687,26 +1687,51 @@ if ($action != 'dopayment') if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled)) { // If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of paybox - print '
'; + print '
'; print '
'; print ''.$langs->trans("CreditOrDebitCard").''; print '
'; + print ' + '; } if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled)) { // If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of stripe - print '
'; + print '
'; print '
'; print ''.$langs->trans("CreditOrDebitCard").''; print '
'; + print ' + '; } if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled)) { if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral'; - print '
'; + print '
'; if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') { print '
'; @@ -1718,6 +1743,19 @@ if ($action != 'dopayment') //print '
'.$langs->trans("PaypalAccount").'">'; } print '
'; + print ' + '; } } } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 58b076a953c..a137b91236f 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -147,6 +147,9 @@ input.buttonpayment, button.buttonpayment, div.buttonpayment { color: #fff; border-radius: 4px; } +div.buttonpayment input:focus { + color: #008; +} .buttonpaymentsmall { font-size: 0.65em; padding-left: 5px; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 9fad375eade..8999a73aaea 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -376,6 +376,9 @@ div.buttonpayment input { color: #333; cursor: pointer; } +div.buttonpayment input:focus { + color: #008; +} input.buttonpaymentcb { background-image: url(); background-size: 26px; From 9ca4d65965050e02a4afd746f06f2f323c656705 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jul 2019 01:12:03 +0200 Subject: [PATCH 4/7] Fix stripe error management --- htdocs/public/payment/newpayment.php | 10 ++++++++-- htdocs/stripe/class/stripe.class.php | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 8c9eb93004f..02dc94285f6 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -430,7 +430,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) 'dol_version' => DOL_VERSION, 'dol_entity' => $conf->entity, 'dol_company' => $mysoc->name, // Usefull when using multicompany - 'dol_tax_num' => $taxinfo, + 'dol_tax_num' => $vatnumber, 'ipaddress'=> getUserRemoteIP() ); @@ -455,7 +455,13 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $stripe = new Stripe($db); $stripeacc = $stripe->getStripeAccount($service); - $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1); + $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1); + if (empty($customer)) + { + $error++; + dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERROR, 0, '_stripe'); + setEventMessages('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, null, 'errors'); + } // Create Stripe card from Token if ($savesource) { diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 6b910236e96..c731637fce6 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -177,6 +177,7 @@ class Stripe extends CommonObject } catch(Exception $e) { + // For exemple, we may have error: 'No such customer: cus_XXXXX; a similar object exists in live mode, but a test mode key was used to make this request.' $this->error = $e->getMessage(); } } From 3112f2b1c564d549440cfbb63fb267237891b15f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jul 2019 01:13:49 +0200 Subject: [PATCH 5/7] Fix error level --- htdocs/public/payment/newpayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 02dc94285f6..e43089f0a8d 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -459,7 +459,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) if (empty($customer)) { $error++; - dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERROR, 0, '_stripe'); + dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERR, 0, '_stripe'); setEventMessages('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, null, 'errors'); } From 406375bfc444829764b844477a73a810ffb9248a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jul 2019 01:17:53 +0200 Subject: [PATCH 6/7] Fix error management --- htdocs/public/payment/newpayment.php | 76 +++++++++++++++------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index e43089f0a8d..0a967cb10a7 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -461,47 +461,51 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) $error++; dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERR, 0, '_stripe'); setEventMessages('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, null, 'errors'); + $action=''; } // Create Stripe card from Token - if ($savesource) { - $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata)); - } else { - $card = $stripeToken; - } - - if (empty($card)) + if (! $error) { - $error++; - dol_syslog('Failed to create card record', LOG_WARNING, 0, '_stripe'); - setEventMessages('Failed to create card record', null, 'errors'); - $action=''; - } - else - { - if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; - if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; - if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; + if ($savesource) { + $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata)); + } else { + $card = $stripeToken; + } - dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_stripe'); - $charge = \Stripe\Charge::create(array( - 'amount' => price2num($amountstripe, 'MU'), - 'currency' => $currency, - 'capture' => true, // Charge immediatly - 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref, - 'metadata' => $metadata, - 'customer' => $customer->id, - 'source' => $card, - 'statement_descriptor' => dol_trunc($FULLTAG, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description) - ), array("idempotency_key" => "$FULLTAG", "stripe_account" => "$stripeacc")); - // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...) - if (empty($charge)) - { - $error++; - dol_syslog('Failed to charge card', LOG_WARNING, 0, '_stripe'); - setEventMessages('Failed to charge card', null, 'errors'); - $action=''; - } + if (empty($card)) + { + $error++; + dol_syslog('Failed to create card record', LOG_WARNING, 0, '_stripe'); + setEventMessages('Failed to create card record', null, 'errors'); + $action=''; + } + else + { + if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; + if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; + if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; + + dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_stripe'); + $charge = \Stripe\Charge::create(array( + 'amount' => price2num($amountstripe, 'MU'), + 'currency' => $currency, + 'capture' => true, // Charge immediatly + 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref, + 'metadata' => $metadata, + 'customer' => $customer->id, + 'source' => $card, + 'statement_descriptor' => dol_trunc($FULLTAG, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description) + ), array("idempotency_key" => "$FULLTAG", "stripe_account" => "$stripeacc")); + // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...) + if (empty($charge)) + { + $error++; + dol_syslog('Failed to charge card', LOG_WARNING, 0, '_stripe'); + setEventMessages('Failed to charge card', null, 'errors'); + $action=''; + } + } } } else From 79bb9d951f5a47c786200006a89177ccfce9b950 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jul 2019 01:36:05 +0200 Subject: [PATCH 7/7] Fix phpcs --- htdocs/expensereport/class/expensereport.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 4cc935f95a2..2d9795e6f59 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1181,7 +1181,6 @@ class ExpenseReport extends CommonObject } } } - } }