Merge pull request #20523 from ATM-Consulting/NEW_16.0_consistency_mechanism_for_trigger_names

NEW 16.0 - proposal for a prefix-based consistency mechanism for trigger names
This commit is contained in:
Laurent Destailleur 2022-04-07 18:25:03 +02:00 committed by GitHub
commit 6f413e03d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@
*/
abstract class CommonObject
{
const TRIGGER_PREFIX = ''; // to be overriden in child class implementations, i.e. 'BILL', 'TASK', 'PROPAL', etc.
/**
* @var DoliDb Database handler (result of a new DoliDB)
*/
@ -5618,7 +5619,10 @@ abstract class CommonObject
{
// phpcs:enable
global $langs, $conf;
if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX . '_') !== 0) {
dol_print_error('', 'The trigger "' . $triggerName . '" does not start with "' . self::TRIGGER_PREFIX . '_" as required.');
exit;
}
if (!is_object($langs)) { // If lang was not defined, we set it. It is required by run_triggers.
include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
$langs = new Translate('', $conf);