2
0
forked from Wavyzz/dolibarr

Fix use of const trigger to avoid compatibility pb in future.

This commit is contained in:
ldestailleur
2025-08-06 19:08:01 +02:00
parent 285e697e6c
commit d03af36d95
7 changed files with 16 additions and 15 deletions

View File

@@ -54,10 +54,6 @@ abstract class CommonObject
use DolDeprecationHandler;
use CommonTrigger;
// Should be in Commontrigger but Traits can not have constant.
const TRIGGER_PREFIX = ''; // to be overridden in child class implementations, i.e. 'BILL', 'TASK', 'PROPAL', etc. It is used to check that trigger code matches object name.
/**
* @var string ID of module.
*/

View File

@@ -59,6 +59,10 @@ trait CommonTrigger
*/
public $errors = array();
// We do not use a constant because PHP does not support constant in Trait and does not allow overriding of constant without using "override" key that is not
// available on all PHP versions
public $TRIGGER_PREFIX = ''; // to be overridden in child class implementations, i.e. 'BILL', 'TASK', 'PROPAL', etc. It is used to check that trigger code matches object name.
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
@@ -76,10 +80,10 @@ trait CommonTrigger
// phpcs:enable
global $langs, $conf;
// @phan-suppress-next-line PhanUndeclaredConstantOfClass Phan thinks that parent static::CONSTANT must be declared locally (even if PHP does not allow this on Traits)
if (!empty(static::TRIGGER_PREFIX) && strpos($triggerName, static::TRIGGER_PREFIX . '_') !== 0) {
// @phan-suppress-next-line PhanUndeclaredConstantOfClass Phan thinks that parent static::CONSTANT must be declared locally (even if PHP does not allow this on Traits)
dol_print_error(null, 'The trigger "' . $triggerName . '" does not start with "' . static::TRIGGER_PREFIX . '_" as required.');
// @phan-suppress-next-line PhanUndeclaredConstantOfClass
if (!empty($this->TRIGGER_PREFIX) && strpos($triggerName, $this->TRIGGER_PREFIX . '_') !== 0) {
// @phan-suppress-next-line PhanUndeclaredConstantOfClass
dol_print_error(null, 'The trigger "' . $triggerName . '" does not start with "' . $this->TRIGGER_PREFIX . '_" as required.');
exit;
}
if (!is_object($langs)) { // If lang was not defined, we set it. It is required by run_triggers().

View File

@@ -30,7 +30,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/doldeprecationhandler.class.php';
*/
class ObjectLink extends CommonObject
{
const TRIGGER_PREFIX = 'OBJECTLINK';
public $TRIGGER_PREFIX = 'OBJECTLINK';
/**
* @var string ID to identify managed object
*/