log_functions.php
Table of Contents
Functions
- log_activity() : void
- Log activity in the system (e.g user deleted a user)
- logScript() : void
- Log script messages on screen and optionally in a file. If debug_log is enabled, it will also write the message in the debug log file.
- resource_log_last_rows() : array<string|int, mixed>
- Retrieve entries from resource log based on date or references
- get_activity_log() : array<string|int, mixed>|int
- Get activity log entries from log tables (e.g activity_log, resource_log and collection_log)
- get_user_downloads() : int
- Use resource log to obtain a count of resources downloaded by the specified user in the last X days
- log_node_changes() : bool
- Add detail of node changes to resource log
- log_search_event() : void
- Log search events
- generate_trace_id() : string
- Generate a fingerprint which could then be used as a trace ID for event correlation purposes.
- daily_stat_past_month_by_activity() : int
- Return sum of activity from the daily_stat table for the past month for a given activity_type.
Functions
log_activity()
Log activity in the system (e.g user deleted a user)
log_activity([string $note = null ][, string $log_code = LOG_CODE_UNSPECIFIED ][, string $value_new = null ][, string $remote_table = null ][, string $remote_column = null ][, string $remote_ref = null ][, string $ref_column_override = null ][, string $value_old = null ][, string $user = null ][, bool $generate_diff = false ]) : void
Parameters
- $note : string = null
-
Notes/comments regarding this activity
- $log_code : string = LOG_CODE_UNSPECIFIED
- $value_new : string = null
- $remote_table : string = null
- $remote_column : string = null
- $remote_ref : string = null
- $ref_column_override : string = null
- $value_old : string = null
- $user : string = null
-
User that ran the activity
- $generate_diff : bool = false
logScript()
Log script messages on screen and optionally in a file. If debug_log is enabled, it will also write the message in the debug log file.
logScript(string $message[, resource $file = null ]) : void
Parameters
- $message : string
- $file : resource = null
Tags
resource_log_last_rows()
Retrieve entries from resource log based on date or references
resource_log_last_rows([int $minref = 0 ][, int $days = 7 ][, int $maxrecords = 0 ][, array<string|int, mixed> $fields = [] ][, array<string|int, mixed> $log_codes = [] ]) : array<string|int, mixed>
Parameters
- $minref : int = 0
-
(Optional) Minimum ref of resource log entry to return (default 0)
- $days : int = 7
-
(Optional) Number of days to return. e.g 3 = all results for today, yesterday and the day before. Default = 7 (ignored if minref supplied)
- $maxrecords : int = 0
-
(Optional) Maximum number of records to return. Default = all rows (0)
- $fields : array<string|int, mixed> = []
-
(Optional) Limit results to particular metadata field(s)
- $log_codes : array<string|int, mixed> = []
-
(Optional) Limit results to particular log code(s)
Return values
array<string|int, mixed>get_activity_log()
Get activity log entries from log tables (e.g activity_log, resource_log and collection_log)
get_activity_log(string $search, int $offset, int $rows, array<string|int, mixed> $where_statements, string $table, int $table_reference[, bool $count = false ]) : array<string|int, mixed>|int
Parameters
- $search : string
-
Search text to filter down results using fuzzy searching
- $offset : int
-
Specifies the offset of the first row to return
- $rows : int
-
Specifies the maximum number of rows to return
- $where_statements : array<string|int, mixed>
-
Where statements for log tables Example of where statements: $where_statements = array( 'activity_log' => "
activity_log.user='{$actasuser}' AND ", 'resource_log' => "resource_log.user='{$actasuser}' AND ", 'collection_log' => "collection_log.user='{$actasuser}' AND ", ); - $table : string
-
Table name (e.g resource_type_field, user, resource)
- $table_reference : int
-
ID of the record in the referred table
- $count : bool = false
-
Switch for if the result should be a single count or the result set
Tags
Return values
array<string|int, mixed>|intget_user_downloads()
Use resource log to obtain a count of resources downloaded by the specified user in the last X days
get_user_downloads(int $userref, int $user_dl_days) : int
Parameters
- $userref : int
-
User reference
- $user_dl_days : int
-
The number of days to check the resource log for
Return values
int —download count
log_node_changes()
Add detail of node changes to resource log
log_node_changes(int $resource, array<string|int, mixed> $nodes_new, array<string|int, mixed> $nodes_current[, string $lognote = "" ][, array<string|int, mixed> $nodes_renamed = [] ]) : bool
Note that this function originally required only the added and removed nodes to be passed. This was prior to node reversion changes, which requires the logging of all the existing resource nodes
Parameters
- $resource : int
-
Resource ID
- $nodes_new : array<string|int, mixed>
-
Array of new node IDs
- $nodes_current : array<string|int, mixed>
-
Array of old node IDs
- $lognote : string = ""
-
Optional note to add to log entry
- $nodes_renamed : array<string|int, mixed> = []
-
Optional array of old node names with node id as key e.g. [345 => 'oldname',678 => "pastname"]
Return values
bool —Success/failure
log_search_event()
Log search events
log_search_event(string $search, array<string|int, mixed> $resource_types, array<string|int, mixed> $archive_states, int $result_count) : void
Parameters
- $search : string
-
Actual search string do_search()
- $resource_types : array<string|int, mixed>
-
Resource types filter
- $archive_states : array<string|int, mixed>
-
Archive states filter
- $result_count : int
-
Search result count
generate_trace_id()
Generate a fingerprint which could then be used as a trace ID for event correlation purposes.
generate_trace_id(array<string|int, mixed> $components) : string
Parameters
- $components : array<string|int, mixed>
-
Data making up our fingerprint.
Return values
stringdaily_stat_past_month_by_activity()
Return sum of activity from the daily_stat table for the past month for a given activity_type.
daily_stat_past_month_by_activity(string $activity_type) : int
Parameters
- $activity_type : string
Return values
int —Sum of activity for the requested type.