dolibarr 23.0.3
BlockedLog Class Reference

Class to manage Blocked Log. More...

Public Member Functions

 __construct (DoliDB $db)
 Constructor.
 
 loadTrackedEvents ()
 Load list of tracked events into $this->trackedevents.
 
 getObjectLink ()
 Try to retrieve source object (it it still exists).
 
 getUser ()
 Try to retrieve user author.
 
 setObjectData (&$object, $action, $amounts, $fuser=null, $amounts_taxexcl=null)
 Populate properties of an unalterable log entry from object data.
 
 fetch ($id)
 Get object from database.
 
 dolEncodeBlockedData ($data, $mode=0)
 Encode data.
 
 dolDecodeBlockedData ($data, $mode=0)
 Decode data.
 
 setCertified ()
 Set block certified by an external authority.
 
 create ($user, $forcesignature='')
 Create blocked log in database.
 
 checkSignature ($previoushash='', $returnarray=0)
 Check if calculated signature still correct compared to the value in the chain.
 
 buildKeyForSignature ()
 Return the string for signature (clear data).
 
 getPreviousHash ($withlock=0, $beforeid=0)
 Get previous signature/hash in chain.
 
 getLog ($element, $fk_object, $limit=0, $sortfield='', $sortorder='', $search_fk_user=-1, $search_start=-1, $search_end=-1, $search_ref='', $search_amount='', $search_code='', $search_signature='', $search_module_source='')
 Return array of log objects (with criteria)
 
 getOrInitFirstSignature ()
 Return the signature (hash) of the "genesis-block" (Block 0).
 
 alreadyUsed ($ignoresystem=0)
 Check if module was already used or not for at least one recording.
 
 canBeEnabled ()
 Check if module can be enabled.
 
 canBeDisabled ()
 Check if module can be disabled.
 

Private Member Functions

 buildFirstPartOfKeyForSignature ()
 Return first part of string for signature (clear data) Note: rowid of line not included as it is not a business data and this allow to make backup of a year and restore it into another database with different ids without comprimising checksums.
 
 buildFinalSignatureHash ($clearstring)
 Return a hash that is the signature of a line (hash_hmac en SHA256 des données + clé secrète)
 

Detailed Description

Class to manage Blocked Log.

Definition at line 28 of file blockedlog.class.php.

Constructor & Destructor Documentation

◆ __construct()

BlockedLog::__construct ( DoliDB $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 189 of file blockedlog.class.php.

Member Function Documentation

◆ alreadyUsed()

BlockedLog::alreadyUsed ( $ignoresystem = 0)

Check if module was already used or not for at least one recording.

Parameters
int<0,1>$ignoresystem Ignore system events for the test
Returns
bool

Definition at line 1706 of file blockedlog.class.php.

References isBlockedLogUsed().

◆ buildFinalSignatureHash()

BlockedLog::buildFinalSignatureHash ( $clearstring)
private

Return a hash that is the signature of a line (hash_hmac en SHA256 des données + clé secrète)

Parameters
string$clearstringData to sign
Returns
string Signature string

Definition at line 1456 of file blockedlog.class.php.

References dol_hash(), dolDecrypt(), and getDolGlobalString().

Referenced by checkSignature(), and create().

◆ buildFirstPartOfKeyForSignature()

BlockedLog::buildFirstPartOfKeyForSignature ( )
private

Return first part of string for signature (clear data) Note: rowid of line not included as it is not a business data and this allow to make backup of a year and restore it into another database with different ids without comprimising checksums.

Returns
string First part of key for signature

Definition at line 1413 of file blockedlog.class.php.

Referenced by buildKeyForSignature(), and create().

◆ buildKeyForSignature()

BlockedLog::buildKeyForSignature ( )

Return the string for signature (clear data).

Returns
string Key for signature

Definition at line 1436 of file blockedlog.class.php.

References buildFirstPartOfKeyForSignature().

Referenced by checkSignature(), and create().

◆ canBeDisabled()

BlockedLog::canBeDisabled ( )

Check if module can be disabled.

Returns
int<0,1> 0=Can't be disabled, 1=Can be disabled

Definition at line 1737 of file blockedlog.class.php.

References $mysoc, and isALNEQualifiedVersion().

◆ canBeEnabled()

BlockedLog::canBeEnabled ( )

Check if module can be enabled.

Returns
string '' if ok, error message if not possible

Definition at line 1718 of file blockedlog.class.php.

References isALNEQualifiedVersion().

◆ checkSignature()

BlockedLog::checkSignature ( $previoushash = '',
$returnarray = 0 )

Check if calculated signature still correct compared to the value in the chain.

Parameters
string$previoushashIf previous signature hash is known, we can provide it to avoid to make a search of it in database.
int<0,2>$returnarray 1=Return array of details, 2=Return array of details including keyforsignature, 0=Boolean
Returns
boolean|array{checkresult:bool,calculatedsignature:string,previoushash:string,keyforsignature?:string} Array or true if OK, false if KO

Definition at line 1359 of file blockedlog.class.php.

References buildFinalSignatureHash(), buildKeyForSignature(), dol_syslog(), and getPreviousHash().

◆ create()

BlockedLog::create ( $user,
$forcesignature = '' )

Create blocked log in database.

Parameters
User$userObject user that create
string$forcesignatureForce signature (for example '0000000000' when we disabled the module, to force a non valid record, for test purpose for example)
Returns
int<-3,-1>|int<1,1> Return integer <0 if KO, >0 if OK

Definition at line 1185 of file blockedlog.class.php.

References $mysoc, buildFinalSignatureHash(), buildFirstPartOfKeyForSignature(), buildKeyForSignature(), dol_now(), dol_syslog(), dolEncodeBlockedData(), getDolGlobalString(), getPreviousHash(), and isALNERunningVersion().

◆ dolDecodeBlockedData()

BlockedLog::dolDecodeBlockedData ( $data,
$mode = 0 )

Decode data.

Parameters
string$dataData to unserialize
int$mode0=unserialize, 1=json_decode
Returns
Object Value unserialized, an object (stdClass)

Definition at line 1150 of file blockedlog.class.php.

References jsonOrUnserialize().

Referenced by fetch().

◆ dolEncodeBlockedData()

BlockedLog::dolEncodeBlockedData ( $data,
$mode = 0 )

Encode data.

Parameters
?stdClass$dataData to serialize
int<0,1>$mode 0=serialize, 1=json_encode
Returns
string Value serialized, an object (stdClass)

Definition at line 1130 of file blockedlog.class.php.

Referenced by create().

◆ fetch()

BlockedLog::fetch ( $id)

Get object from database.

Parameters
int$idId of object to load
Returns
int<-1,1> >0 if OK, <0 if KO, 0 if not found

Definition at line 1060 of file blockedlog.class.php.

References dolDecodeBlockedData().

◆ getLog()

BlockedLog::getLog ( $element,
$fk_object,
$limit = 0,
$sortfield = '',
$sortorder = '',
$search_fk_user = -1,
$search_start = -1,
$search_end = -1,
$search_ref = '',
$search_amount = '',
$search_code = '',
$search_signature = '',
$search_module_source = '' )

Return array of log objects (with criteria)

Parameters
string$elementElement to search
string | int$fk_objectId of object to search. Can be a UFS search criteria.
int<0,max>$limit Max number of element, 0 for all
string$sortfieldSort field
string$sortorderSort order
int$search_fk_userId of user(s)
int$search_startStart time limit
int$search_endEnd time limit
string$search_refSearch ref
string$search_amountSearch amount
string | string[]$search_codeSearch code
string$search_signatureSearch signature
string$search_module_sourceSearch on module source
Returns
BlockedLog[]|int<-2,-1> Array of object log or <0 if error

Definition at line 1562 of file blockedlog.class.php.

References natural_search().

◆ getObjectLink()

BlockedLog::getObjectLink ( )

Try to retrieve source object (it it still exists).

Returns
string URL string of source object

Definition at line 332 of file blockedlog.class.php.

References $object.

◆ getOrInitFirstSignature()

BlockedLog::getOrInitFirstSignature ( )

Return the signature (hash) of the "genesis-block" (Block 0).

Returns
string Signature of genesis-block for current conf->entity

Definition at line 1675 of file blockedlog.class.php.

References dolibarr_set_const(), and getDolGlobalString().

Referenced by getPreviousHash().

◆ getPreviousHash()

BlockedLog::getPreviousHash ( $withlock = 0,
$beforeid = 0 )

Get previous signature/hash in chain.

Parameters
int<0,1>$withlock 1=With a lock
int$beforeidID of a record
Returns
string Hash of previous record (if beforeid is defined) or hash of last record (if beforeid is 0)

Definition at line 1486 of file blockedlog.class.php.

References dol_print_error(), and getOrInitFirstSignature().

Referenced by checkSignature(), and create().

◆ getUser()

BlockedLog::getUser ( )

Try to retrieve user author.

Returns
string

Definition at line 456 of file blockedlog.class.php.

◆ loadTrackedEvents()

BlockedLog::loadTrackedEvents ( )

Load list of tracked events into $this->trackedevents.

Returns
int<1,1> Always 1

Definition at line 200 of file blockedlog.class.php.

References getDolGlobalString(), img_picto(), and isModEnabled().

◆ setCertified()

BlockedLog::setCertified ( )

Set block certified by an external authority.

Returns
boolean

Definition at line 1168 of file blockedlog.class.php.

◆ setObjectData()

BlockedLog::setObjectData ( & $object,
$action,
$amounts,
$fuser = null,
$amounts_taxexcl = null )

Populate properties of an unalterable log entry from object data.

This populates ->object_data but also other fields like ->action, ->module_source, ->amounts_taxexcl, ->amounts and ->linktoref and ->linktype It also populates some debug info like ->element and ->fk_object

Parameters
CommonObject | stdClass$objectObject to store
string$actionAction code ('BILL_VALIDATE', 'BILL_SENTBYMAIL', ...)
float | int$amountsamounts (incl tax)
?User$fuserUser object (forced)
float | int | null$amounts_taxexclamounts (excl tax or null if not relevant)
Returns
int<-1,-1>|int<1,1> Return >0 if OK, <0 if KO

var CashControl $object

Definition at line 490 of file blockedlog.class.php.

References $mysoc, $object, dol_getIdFromCode(), dol_syslog(), dol_trunc(), dolGetFirstLineOfText(), Facture\TYPE_CREDIT_NOTE, and FactureFournisseur\TYPE_CREDIT_NOTE.


The documentation for this class was generated from the following file: