class BlockedLog (View source)

Class to manage Blocked Log

Properties

DoliDB $db
int $id

Id of the log

int $entity Entity
string $picto Picto
string $error
string[] $errors
string $signature

Unique fingerprint of the log

float|string|null $amounts
float|string|null $amounts_taxexcl
string $action

trigger action

string $module_source

Module source

string $linktype
string $linktoref
string $element

Object element

int $fk_object

Object id

bool $certified

Log certified by remote authority or not

int $fk_user Author
int|string $date_creation
int|string $date_modification
int $date_object
string $ref_object
stdClass $object_data
string $object_version
string $object_format
string $user_fullname
string $debuginfo
array<string, string|mixed> $trackedevents

Array of tracked event codes

array<int|string, string> $trackedmodules

Array of tracked modules (key => label)

Methods

__construct(DoliDB $db)

Constructor

int<1, 1>
loadTrackedEvents()

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

string
getObjectLink()

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

string
getUser()

Try to retrieve user author

int<-1, -1>|int<1, 1>
setObjectData(CommonObject|stdClass $object, string $action, float|int $amounts, User $fuser = null, float|int|null $amounts_taxexcl = null)

Populate properties of an unalterable log entry from object data.

int<-1, 1>
fetch(int $id)

Get object from database

string
dolEncodeBlockedData(stdClass $data, int<0, 1> $mode = 0)

Encode data

object
dolDecodeBlockedData(string $data, int $mode = 0)

Decode data

bool
setCertified()

Set block certified by an external authority

int<-3, -1>|int<1, 1>
create(User $user, $forcesignature = '')

Create blocked log in database.

bool|array{checkresult: bool, calculatedsignature: string, previoushash: string, keyforsignature?: string}
checkSignature(string $previoushash = '', $returnarray = 0)

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

string
buildKeyForSignature()

Return the string for signature (clear data).

getPreviousHash(int<0, 1> $withlock = 0, int $beforeid = 0)

Get previous signature/hash in chain

BlockedLog[]|int<-2, -1>
getLog(string $element, string|int $fk_object, int<0, max> $limit = 0, string $sortfield = '', string $sortorder = '', int $search_fk_user = -1, int $search_start = -1, int $search_end = -1, $search_ref = '', $search_amount = '', $search_code = '', $search_signature = '', $search_module_source = '')

Return array of log objects (with criteria)

string
getOrInitFirstSignature()

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

bool
alreadyUsed(int<0, 1> $ignoresystem = 0)

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

string
canBeEnabled()

Check if module can be enabled.

int<0, 1>
canBeDisabled()

Check if module can be disabled.

Details

__construct(DoliDB $db)

Constructor

@param DoliDB $db Database handler

Parameters

DoliDB $db

int<1, 1> loadTrackedEvents()

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

Return Value

int<1, 1>

Always 1

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

Return Value

string

URL string of source object

string getUser()

Try to retrieve user author

Return Value

string

int<-1, -1>|int<1, 1> setObjectData(CommonObject|stdClass $object, string $action, float|int $amounts, User $fuser = null, float|int|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 $object

Object to store

string $action

Action code ('BILL_VALIDATE', 'BILL_SENTBYMAIL', ...)

float|int $amounts

amounts (incl tax)

User $fuser

User object (forced)

float|int|null $amounts_taxexcl

amounts (excl tax or null if not relevant)

Return Value

int<-1, -1>|int<1, 1>

Return >0 if OK, <0 if KO

int<-1, 1> fetch(int $id)

Get object from database

Parameters

int $id

Id of object to load

Return Value

int<-1, 1>

0 if OK, <0 if KO, 0 if not found

string dolEncodeBlockedData(stdClass $data, int<0, 1> $mode = 0)

Encode data

Parameters

stdClass $data

Data to serialize

int<0, 1> $mode

0=serialize, 1=json_encode

Return Value

string

Value serialized, an object (stdClass)

object dolDecodeBlockedData(string $data, int $mode = 0)

Decode data

Parameters

string $data

Data to unserialize

int $mode

0=unserialize, 1=json_decode

Return Value

object

Value unserialized, an object (stdClass)

bool setCertified()

Set block certified by an external authority

Return Value

bool

int<-3, -1>|int<1, 1> create(User $user, $forcesignature = '')

Create blocked log in database.

Parameters

User $user

Object user that create @param string $forcesignature Force signature (for example '0000000000' when we disabled the module, to force a non valid record, for test purpose for example)

$forcesignature

Return Value

int<-3, -1>|int<1, 1>

Return integer <0 if KO, >0 if OK

bool|array{checkresult: bool, calculatedsignature: string, previoushash: string, keyforsignature?: string} checkSignature(string $previoushash = '', $returnarray = 0)

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

Parameters

string $previoushash

If previous signature hash is known, we can provide it to avoid to make a search of it in database. @param int<0,2> $returnarray 1=Return array of details, 2=Return array of details including keyforsignature, 0=Boolean

$returnarray

Return Value

bool|array{checkresult: bool, calculatedsignature: string, previoushash: string, keyforsignature?: string}

Array or true if OK, false if KO

string buildKeyForSignature()

Return the string for signature (clear data).

Return Value

string

Key for signature

getPreviousHash(int<0, 1> $withlock = 0, int $beforeid = 0)

Get previous signature/hash in chain

Parameters

int<0, 1> $withlock

1=With a lock

int $beforeid

ID of a record @return string Hash of previous record (if beforeid is defined) or hash of last record (if beforeid is 0)

BlockedLog[]|int<-2, -1> getLog(string $element, string|int $fk_object, int<0, max> $limit = 0, string $sortfield = '', string $sortorder = '', int $search_fk_user = -1, int $search_start = -1, int $search_end = -1, $search_ref = '', $search_amount = '', $search_code = '', $search_signature = '', $search_module_source = '')

Return array of log objects (with criteria)

Parameters

string $element

Element to search

string|int $fk_object

Id of object to search. Can be a UFS search criteria.

int<0, max> $limit

Max number of element, 0 for all

string $sortfield

Sort field

string $sortorder

Sort order

int $search_fk_user

Id of user(s)

int $search_start

Start time limit

int $search_end

End time limit @param string $search_ref Search ref @param string $search_amount Search amount @param string|string[] $search_code Search code @param string $search_signature Search signature @param string $search_module_source Search on module source

$search_ref
$search_amount
$search_code
$search_signature
$search_module_source

Return Value

BlockedLog[]|int<-2, -1>

Array of object log or <0 if error

string getOrInitFirstSignature()

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

Return Value

string

Signature of genesis-block for current conf->entity

bool alreadyUsed(int<0, 1> $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

Return Value

bool

string canBeEnabled()

Check if module can be enabled.

Return Value

string

'' if ok, error message if not possible

int<0, 1> canBeDisabled()

Check if module can be disabled.

Return Value

int<0, 1>

0=Can't be disabled, 1=Can be disabled