Having trouble with onBeforeSync. the following code doesn’t even trigger the log entries. This is after numerous ‘Save and reset all events in feed’ attempts. the feed url contains the string ‘admissionsEvents’ and the sync works just fine bringing in events. But the titles remain unchanged and no log entries.
<?php
$_LW->REGISTERED_APPS['admissions_feed']=[
'title'=>'AdmissionsFeed',
'handlers'=>array('onBeforeSync')
];
class LiveWhaleApplicationAdmissionsFeed {
// perform additional form validations
public function onBeforeSync($type, $subscription_id, $buffer) {
error_log('module Admissions Feed: onBeforeSync');
global $_LW;
if ($type == 'events') {
error_log('module AdmissionsFeed: '.$_LW->linked_calendar_url);
// example processing of a feed $buffer:
if (strpos(@$_LW->linked_calendar_url, 'admissionsEvents')!==false) { // if this is an Admissions feed
error_log('module AdmissionsFeed (title): '.$buffer['title']);
$buffer['title'] = $buffer['title'].' (Admissions)';
};
}
return $buffer;
}
}
?>
Happy to help – error_log('module Admissions Feed: onBeforeSync'); isn’t the syntax you want. Instead, if you use the $_LW->logDebug tool for debugging that should do the trick. More info about that is in the docs here: $_LW Functions - LiveWhale Support
My adjusted code is below. However I should note that I have two other modules running that successfully add entries to the log using error_log.
After adjusting my code to the snippet below and trying several more times, the log remains unmodified and the text is not being added to the titles.
<?php
$_LW->REGISTERED_APPS['admissions_feed']=[
'title'=>'AdmissionsFeed',
'handlers'=>array('onBeforeSync')
];
class LiveWhaleApplicationAdmissionsFeed {
// perform additional form validations
public function onBeforeSync($type, $subscription_id, $buffer) {
$_LW->logDebug('module Admissions Feed: onBeforeSync');
global $_LW;
if ($type == 'events') {
$_LW->logDebug('module AdmissionsFeed: '.$_LW->linked_calendar_url);
// example processing of a feed $buffer:
if (strpos(@$_LW->linked_calendar_url, 'admissionsEvents')!==false) { // if this is an Admissions feed
$_LW->logDebug('module AdmissionsFeed (title): '.$buffer['title']);
$buffer['title'] = $buffer['title'].' (Admissions)';
};
}
return $buffer;
}
}
?>
One other suggestion: maybe double-check the scope of your custom module? As listed on Custom Module Handlers - LiveWhale Support, onBeforeSync runs in the back-end, so it needs to be in a “private” or "global"ly scoped module. If you happen to have onBeforeSync in a public module, it won’t ever run because the sync process is a back-end (“private”) process.
If you’re ever unsure, you can name your module file as global.application.my_module.php so it runs in both front- and back-end processes (we sometimes do this just to be able to call both types of handlers in one file, too). See if that helps?