Merge branch 'develop' into membertype_update_single_array_option_element

This commit is contained in:
Jon Bendtsen 2024-04-02 14:06:39 +02:00 committed by GitHub
commit efaf219a6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 171 additions and 162 deletions

View file

@ -196,28 +196,18 @@ print '<td>'.$langs->trans("Parameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n";
print '<tr class="oddeven"><td>';
print $langs->trans("NotificationEMailFrom").'</td>';
print '<td>';
print img_picto('', 'email', 'class="pictofixedwidth"');
print '<input class="width150 quatrevingtpercentminusx" type="email" name="email_from" value="'.getDolGlobalString('NOTIFICATION_EMAIL_FROM').'">';
if (getDolGlobalString('NOTIFICATION_EMAIL_FROM') && !isValidEmail($conf->global->NOTIFICATION_EMAIL_FROM)) {
if (getDolGlobalString('NOTIFICATION_EMAIL_FROM') && !isValidEmail(getDolGlobalString('NOTIFICATION_EMAIL_FROM'))) {
print ' '.img_warning($langs->trans("ErrorBadEMail"));
}
print '</td>';
print '</tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("NotificationDisableConfirmMessageContact").'</td>';
print '<td>';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT", $arrval, getDolGlobalString('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT'));
}
print '</td>';
print '</tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("NotificationDisableConfirmMessageUser").'</td>';
@ -231,6 +221,20 @@ if ($conf->use_javascript_ajax) {
print '</td>';
print '</tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("NotificationDisableConfirmMessageContact").'</td>';
print '<td>';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT", $arrval, getDolGlobalString('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT'));
}
print '</td>';
print '</tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("NotificationDisableConfirmMessageFix").'</td>';
print '<td>';
@ -242,6 +246,8 @@ if ($conf->use_javascript_ajax) {
}
print '</td>';
print '</tr>';
print '</table>';
print '</div>';

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -134,16 +135,41 @@ class DolibarrApi
*/
protected function _filterObjectProperties($object, $properties)
{
// phpcs:enable
// If properties is empty, we return all properties
if (empty($properties)) {
return $object;
}
// Else we filter properties
// Copy of exploded array for efficiency
$arr_properties = explode(',', $properties);
$magic_properties = array();
$real_properties = get_object_vars($object);
// Unsetting real properties may unset magic properties.
// We keep a copy of the requested magic properties
foreach ($arr_properties as $key) {
if (!array_key_exists($key, $real_properties)) {
// Not a real property,
// check if $key is a magic property (we want to keep '$obj->$key')
if (property_exists($object, $key) && isset($object->$key)) {
$magic_properties[$key] = $object->$key;
}
}
}
// Filter real properties (may indirectly unset magic properties)
foreach (get_object_vars($object) as $key => $value) {
if (!in_array($key, explode(',', $properties))) {
if (!in_array($key, $arr_properties)) {
unset($object->$key);
}
}
// Restore the magic properties
foreach ($magic_properties as $key => $value) {
$object->$key = $value;
}
return $object;
}

View file

@ -144,7 +144,7 @@ if (empty($reshook)) {
$form = new Form($db);
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
$title = $langs->trans("ContactEvents");
if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
$title = $object->lastname;
}

View file

@ -574,7 +574,6 @@ if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', get
$title = $object->lastname;
}
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
llxHeader('', $title, $help_url);

View file

@ -111,7 +111,7 @@ $formother = new FormOther($db);
$productstatic = new Product($db);
$objsoc = new Societe($db);
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
$title = $langs->trans("ContactRelatedItems");
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);

View file

@ -110,7 +110,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
$form = new Form($db);
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
$title = $langs->trans("ContactLinkedFiles");
if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
$title = $object->lastname;
}

View file

@ -78,7 +78,7 @@ if (empty($reshook)) {
$now = dol_now();
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
$title = $langs->trans("ContactNotes");
$form = new Form($db);

View file

@ -120,7 +120,7 @@ if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'con
$now = dol_now();
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
$title = $langs->trans("ContactPersonalData");
if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
$title = $object->lastname;
}

View file

@ -646,7 +646,7 @@ class Notify
if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
$application = getDolGlobalString('MAIN_APPLICATION_TITLE');
}
$replyto = $conf->notification->email_from;
$from = getDolGlobalString('NOTIFICATION_EMAIL_FROM');
$object_type = '';
$link = '';
$num = 0;
@ -945,7 +945,7 @@ class Notify
$sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
}
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'outputlangs' => $outputlangs, 'labeltouse' => $labeltouse);
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'from' => $from, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'outputlangs' => $outputlangs, 'labeltouse' => $labeltouse);
if (!isset($action)) {
$action = '';
}
@ -968,7 +968,7 @@ class Notify
$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$from,
$message,
$filename_list,
$mimetype_list,
@ -1211,7 +1211,7 @@ class Notify
}
if ($sendto) {
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'subject' => &$subject, 'message' => &$message);
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'from' => $from, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'subject' => &$subject, 'message' => &$message);
$reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) {
if (!empty($hookmanager->resArray['files'])) {
@ -1229,7 +1229,7 @@ class Notify
$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$from,
$message,
$filename_list,
$mimetype_list,

View file

@ -1367,6 +1367,41 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
return $res;
}
/**
* Get properties for an object - including magic properties when requested
*
* Only returns properties that exist
*
* @param object $obj Object to get properties from
* @param string[] $properties Optional list of properties to get.
* When empty, only gets public properties.
* @return array<string,mixed> Hash for retrieved values (key=name)
*/
function dol_get_object_properties($obj, $properties = [])
{
// Get real properties using get_object_vars() if $properties is empty
if (empty($properties)) {
return get_object_vars($obj);
}
$existingProperties = [];
$realProperties = get_object_vars($obj);
// Get the real or magic property values
foreach ($properties as $property) {
if (array_key_exists($property, $realProperties)) {
// Real property, add the value
$existingProperties[$property] = $obj->{$property};
} elseif (property_exists($obj, $property)) {
// Magic property
$existingProperties[$property] = $obj->{$property};
}
}
return $existingProperties;
}
/**
* Create a clone of instance of object (new instance with same value for each properties)
* With native = 0: Property that are reference are different memory area in the new object (full isolation clone). This means $this->db of new object may not be valid.

View file

@ -273,6 +273,11 @@ EditContact=Edit contact
EditContactAddress=Edit contact/address
Contact=Contact/Address
Contacts=Contacts/Addresses
ContactNotes=Notes
ContactPersonalData=Personal data
ContactRelatedItems=Related items
ContactLinkedFiles=Linked files
ContactEvents=Events/Agenda
ContactId=Contact id
ContactsAddresses=Contacts/Addresses
FromContactName=Name:

View file

@ -462,6 +462,12 @@ class Tasks extends DolibarrApi
$this->task->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->task->array_options[$index] = $this->_checkValForAPI($field, $val, $this->task);;
}
continue;
}
$this->task->$field = $this->_checkValForAPI($field, $value, $this->task);
}

View file

@ -235,6 +235,69 @@ abstract class CommonClassTest extends TestCase
}
}
/**
* Call method, even if protected.
*
* @param object $obj Object on which to call method
* @param string $name Method to call
* @param array $args Arguments to provide in method call
* @return mixed Return value
*/
public static function callMethod($obj, $name, array $args = [])
{
$class = new \ReflectionClass($obj);
$method = $class->getMethod($name);
// If PHP is older then 8.1.0
if (PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}
return $method->invokeArgs($obj, $args);
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
$aKeys = array_keys($oVarsA);
if (method_exists($oA, 'deprecatedProperties')) {
// Update exclusions
foreach (self::callMethod($oA, 'deprecatedProperties') as $deprecated => $new) {
if (in_array($deprecated, $fieldstoignorearray)) {
$fieldstoignorearray[] = $new;
}
}
}
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = get_class($oA).'::'.$sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : json_encode($oVarsA[$sKey])).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : json_encode($oVarsB[$sKey]));
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = get_class($oA).'::'.$sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : json_encode($oVarsA[$sKey])).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : json_encode($oVarsB[$sKey]));
}
}
}
return $retAr;
}
/**
* Map deprecated module names to new module names
*/

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -117,38 +118,4 @@ class FactureRecTest extends CommonClassTest
$localobject->note_private = 'New note';
//$localobject->note='New note after update';
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
$aKeys = array_keys($oVarsA);
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
}
}
return $retAr;
}
}

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -155,7 +156,7 @@ class FactureTest extends CommonClassTest
$this->assertLessThan($result, 0);
// Test everything are still same than specimen
// Test everything is still the same as specimen
$newlocalobject = new Facture($db);
$newlocalobject->initAsSpecimen();
$this->changeProperties($newlocalobject);
@ -168,6 +169,7 @@ class FactureTest extends CommonClassTest
$localobject,
$newlocalobject,
true,
// Not comparing:
array(
'newref','oldref','id','lines','client','thirdparty','brouillon','user_creation_id','date_creation','date_validation','datem','date_modification',
'ref','statut','status','paye','specimen','ref','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement',
@ -281,38 +283,4 @@ class FactureTest extends CommonClassTest
$localobject->note_private = 'New note';
//$localobject->note='New note after update';
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
$aKeys = array_keys($oVarsA);
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
}
}
return $retAr;
}
}

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -267,38 +268,4 @@ class InventoryTest extends CommonClassTest
return $result;
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
$aKeys = array_keys($oVarsA);
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
}
}
return $retAr;
}
}

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2010-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -403,38 +404,4 @@ class UserTest extends CommonClassTest
{
$localobject->note_private = 'New note after update';
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
$aKeys = array_keys($oVarsA);
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = $sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : $oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : $oVarsB[$sKey]);
}
}
}
return $retAr;
}
}