Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
741519fa
Commit
741519fa
authored
14 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
loging system
parent
4e2ef271
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/log.php
+42
-5
42 additions, 5 deletions
lib/log.php
with
42 additions
and
5 deletions
lib/log.php
+
42
−
5
View file @
741519fa
...
@@ -50,8 +50,9 @@ class OC_LOG {
...
@@ -50,8 +50,9 @@ class OC_LOG {
*
*
* This function adds another entry to the log database
* This function adds another entry to the log database
*/
*/
public
static
function
add
(
$appid
,
$subject
,
$predicate
,
$object
=
null
){
public
static
function
add
(
$appid
,
$subject
,
$predicate
,
$object
=
' '
){
// TODO: write function
$query
=
OC_DB
::
prepare
(
"INSERT INTO *PREFIX*log(`timestamp`,appid,user,action,info) VALUES(NOW(),?,?,?,?)"
);
$query
->
execute
(
array
(
$appid
,
$subject
,
$predicate
,
$object
));
return
true
;
return
true
;
}
}
...
@@ -71,8 +72,27 @@ class OC_LOG {
...
@@ -71,8 +72,27 @@ class OC_LOG {
* - app: only entries for this app
* - app: only entries for this app
*/
*/
public
static
function
get
(
$filter
=
array
()){
public
static
function
get
(
$filter
=
array
()){
// TODO: write function
$queryString
=
'SELECT * FROM *PREFIX*log WHERE 1=1 '
;
return
array
();
$params
=
array
();
if
(
isset
(
$filter
[
'from'
])){
$queryString
.
=
'AND `timestamp`>? '
;
array_push
(
$params
,
$filter
(
'from'
));
}
if
(
isset
(
$filter
[
'until'
])){
$queryString
.
=
'AND `timestamp`<? '
;
array_push
(
$params
,
$filter
(
'until'
));
}
if
(
isset
(
$filter
[
'user'
])){
$queryString
.
=
'AND user=? '
;
array_push
(
$params
,
$filter
(
'user'
));
}
if
(
isset
(
$filter
[
'app'
])){
$queryString
.
=
'AND appid=? '
;
array_push
(
$params
,
$filter
(
'app'
));
}
$query
=
OC_DB
::
prepare
(
$queryString
);
return
$query
->
execute
(
$params
)
->
fetchAll
();
}
}
/**
/**
...
@@ -83,9 +103,26 @@ class OC_LOG {
...
@@ -83,9 +103,26 @@ class OC_LOG {
* This function deletes all entries that are older than $date.
* This function deletes all entries that are older than $date.
*/
*/
public
static
function
deleteBefore
(
$date
){
public
static
function
deleteBefore
(
$date
){
// TODO: write function
$query
=
OC_DB
::
prepare
(
"DELETE FROM *PREFIX*log WHERE `timestamp`<?"
);
$query
->
execute
(
array
(
$date
));
return
true
;
return
true
;
}
}
/**
* @brief filter an array of log entries on action
* @param array $logs the log entries to filter
* @param array $actions an array of actions to filter for
* @returns array
*/
public
static
function
filterAction
(
$logs
,
$actions
){
$filteredLogs
=
array
();
foreach
(
$logs
as
$log
){
if
(
array_search
(
$log
[
'action'
],
$actions
)
!==
false
){
$filteredLogs
[]
=
$log
;
}
}
return
$filteredLogs
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment