Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
civirules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ayduns
civirules
Commits
6eaf2db3
Commit
6eaf2db3
authored
9 years ago
by
jaapjansma
Browse files
Options
Downloads
Patches
Plain Diff
added util classes for logging
parent
b2e2d0ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Civirules/Utils/HookInvoker.php
+48
-0
48 additions, 0 deletions
CRM/Civirules/Utils/HookInvoker.php
CRM/Civirules/Utils/LoggerFactory.php
+35
-0
35 additions, 0 deletions
CRM/Civirules/Utils/LoggerFactory.php
with
83 additions
and
0 deletions
CRM/Civirules/Utils/HookInvoker.php
0 → 100644
+
48
−
0
View file @
6eaf2db3
<?php
/**
* Class CRM_Civirules_Utils_HookInvoker
*
* This class invokes hooks through the civicrm core hook invoker functionality
*/
class
CRM_Civirules_Utils_HookInvoker
{
private
static
$singleton
;
private
function
__construct
()
{
}
public
static
function
singleton
()
{
if
(
!
self
::
$singleton
)
{
self
::
$singleton
=
new
CRM_Civirules_Utils_HookInvoker
();
}
return
self
::
$singleton
;
}
/**
* hook_civicrm_civirules_logger
*
* @param \Psr\Log\LoggerInterface|NULL $logger
*
* This hook could set a logger class for Civirules
*/
public
function
hook_civirules_getlogger
(
&
$logger
=
null
)
{
$this
->
invoke
(
'civirules_logger'
,
1
,
$logger
);
if
(
$logger
&&
!
$logger
instanceof
\Psr\Log\LoggerInterface
)
{
$logger
=
null
;
}
}
private
function
invoke
(
$fnSuffix
,
$numParams
,
&
$arg1
=
null
,
&
$arg2
=
null
,
&
$arg3
=
null
,
&
$arg4
=
null
,
&
$arg5
=
null
)
{
$hook
=
CRM_Utils_Hook
::
singleton
();
$civiVersion
=
CRM_Core_BAO_Domain
::
version
();
if
(
version_compare
(
'4.4'
,
$civiVersion
,
'<='
))
{
//in CiviCRM 4.4 the invoke function has 5 arguments maximum
return
$hook
->
invoke
(
$numParams
,
$arg1
,
$arg2
,
$arg3
,
$arg4
,
$arg5
,
$fnSuffix
);
}
//in CiviCRM 4.5 and later the invoke function has 6 arguments
return
$hook
->
invoke
(
$numParams
,
$arg1
,
$arg2
,
$arg3
,
$arg4
,
$arg5
,
null
,
$fnSuffix
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
CRM/Civirules/Utils/LoggerFactory.php
0 → 100644
+
35
−
0
View file @
6eaf2db3
<?php
class
CRM_Civirules_Utils_LoggerFactory
{
private
static
$logger
=
null
;
private
static
$loggerHookInvoked
=
false
;
/**
* @return \Psr\Log\LoggerInterface|NULL
*/
public
static
function
getLogger
()
{
if
(
empty
(
self
::
$logger
)
&&
self
::
$loggerHookInvoked
===
false
)
{
$hook
=
CRM_Civirules_Utils_HookInvoker
::
singleton
();
$hook
->
hook_civirules_getlogger
(
self
::
$logger
);
self
::
$loggerHookInvoked
=
true
;
}
return
self
::
$logger
;
}
public
static
function
logError
(
$reason
,
$original_error
,
CRM_Civirules_EventData_EventData
$eventData
,
$context
=
array
())
{
$logger
=
CRM_Civirules_Utils_LoggerFactory
::
getLogger
();
if
(
empty
(
$logger
))
{
return
;
}
$error
=
"Rule: '
{
rule_title
}
' with id
{
rule_id
}
failed for contact
{
contact_id
}
because of
{
reason
}
"
;
$context
[
'rule_id'
]
=
$eventData
->
getEvent
()
->
getRuleId
();
$context
[
'rule_title'
]
=
$eventData
->
getEvent
()
->
getRuleTitle
();
$context
[
'original_error'
]
=
$original_error
;
$context
[
'contact_id'
]
=
$eventData
->
getContactId
();
$context
[
'reason'
]
=
$reason
;
$logger
->
error
(
$error
,
$context
);
}
}
\ No newline at end of file
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