chg: [logging] fail silently if logging entry can't be saved

- can happen when the log change is too large for example
- no need to roll back / break sync for example if a log entry is too large, just fail silently.
pull/9438/head
iglocska 2023-12-07 15:17:58 +01:00
parent c124df0e47
commit 5bed463416
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
24 changed files with 65 additions and 56 deletions

View File

@ -1148,7 +1148,7 @@ class ACLComponent extends Component
if ($hit) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'User',
'model_id' => $user['id'],

View File

@ -73,7 +73,7 @@ class EventDelegationsController extends AppController
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
if (empty($result)) {
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => $event['Event']['id'],
@ -85,7 +85,7 @@ class EventDelegationsController extends AppController
));
throw new InvalidArgumentException('Invalid input, could not create the Delegation Request.');
}
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => $event['Event']['id'],
@ -150,7 +150,7 @@ class EventDelegationsController extends AppController
if ($this->request->is('post')) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => $delegation['Event']['id'],
@ -164,7 +164,7 @@ class EventDelegationsController extends AppController
$this->EventDelegation->delete($delegation['EventDelegation']['id']);
if ($result) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => 0,

View File

@ -4669,7 +4669,7 @@ class EventsController extends AppController
)
);
if (!$result) {
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => 0,

View File

@ -47,7 +47,7 @@ class NoticelistsController extends AppController
$change = $success['name'] . ' v' . $success['new'] . ' installed';
}
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
@ -63,7 +63,7 @@ class NoticelistsController extends AppController
if (isset($result['fails'])) {
foreach ($result['fails'] as $id => $fail) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
@ -78,7 +78,7 @@ class NoticelistsController extends AppController
}
} else {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => 0,

View File

@ -220,7 +220,7 @@ class ObjectTemplatesController extends AppController
$change = $success['name'] . ' v' . $success['new'] . ' installed';
}
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'ObjectTemplate',
'model_id' => $id,
@ -236,7 +236,7 @@ class ObjectTemplatesController extends AppController
if (isset($result['fails'])) {
foreach ($result['fails'] as $id => $fail) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'ObjectTemplate',
'model_id' => $id,
@ -251,7 +251,7 @@ class ObjectTemplatesController extends AppController
}
} else {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'ObjectTemplate',
'model_id' => 0,

View File

@ -1554,7 +1554,7 @@ class ServersController extends AppController
if (!Configure::read('MISP.system_setting_db') && !is_writeable(APP . 'Config/config.php')) {
$this->loadModel('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Server',
'model_id' => 0,

View File

@ -101,7 +101,7 @@ class ShadowAttributesController extends AppController
$this->Event->unpublishEvent($activeAttribute['Attribute']['event_id'], true);
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org_id' => $this->Auth->user('org_id'),
'model' => 'ShadowAttribute',
'model_id' => $id,
@ -145,7 +145,7 @@ class ShadowAttributesController extends AppController
}
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org_id' => $this->Auth->user('org_id'),
'model' => 'ShadowAttribute',
'model_id' => $id,

View File

@ -2815,7 +2815,7 @@ class UsersController extends AppController
} else {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'User',
'model_id' => 0,

View File

@ -78,7 +78,7 @@ class WarninglistsController extends AppController
$change = $success['name'] . ' v' . $success['new'] . ' installed';
}
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Warninglist',
'model_id' => $id,
@ -94,7 +94,7 @@ class WarninglistsController extends AppController
if (isset($result['fails'])) {
foreach ($result['fails'] as $id => $fail) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Warninglist',
'model_id' => $id,
@ -109,7 +109,7 @@ class WarninglistsController extends AppController
}
} else {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Warninglist',
'model_id' => 0,

View File

@ -311,7 +311,7 @@ class AppModel extends Model
} else {
$entry['change'] = 'Tried adding new feeds but something went wrong.';
}
$this->Log->save($entry);
$this->Log->saveOrFailSilently($entry);
}
// SQL scripts for updates
@ -2123,7 +2123,7 @@ class AppModel extends Model
$this->__setUpdateProgress($i, false);
$this->query($sql);
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -2158,7 +2158,7 @@ class AppModel extends Model
} else {
$logMessage['change'] = $logMessage['change'] . PHP_EOL . __('However, as this error is allowed, the update went through.');
}
$this->Log->save($logMessage);
$this->Log->saveOrFailSilently($logMessage);
}
}
}
@ -2200,7 +2200,7 @@ class AppModel extends Model
}
if ($flagStop && $errorCount > 0) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -2276,7 +2276,7 @@ class AppModel extends Model
$result = false;
}
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -2313,7 +2313,7 @@ class AppModel extends Model
$result = false;
}
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -2474,7 +2474,7 @@ class AppModel extends Model
// is only to limit the load.
if ($this->isUpdateLocked()) { // prevent creation of useless workers
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -2531,7 +2531,7 @@ class AppModel extends Model
// (could happens if multiple prio workers are up)
if ($this->isUpdateLocked()) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -3491,7 +3491,7 @@ class AppModel extends Model
'title' => 'Bumped the timestamps of locked events containing object references.',
'change' => sprintf('Event timestamps updated: %s; Object timestamps updated: %s', count($event_ids), count($object_ids))
);
$this->Log->save($entry);
$this->Log->saveOrFailSilently($entry);
}
return true;
}

View File

@ -404,7 +404,7 @@ class DecayingModel extends AppModel
} catch (Exception $e) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'DecayingModel',
'model_id' => 0,

View File

@ -2118,7 +2118,7 @@ class Event extends AppModel
if ($event['Event']['distribution'] == 4 && !in_array($event['Event']['sharing_group_id'], $sgids)) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Event',
'model_id' => $event['Event']['id'],
@ -3107,7 +3107,7 @@ class Event extends AppModel
if (Configure::read('MISP.disable_emailing')) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Event',
'model_id' => $id,
@ -3125,7 +3125,7 @@ class Event extends AppModel
$banError = $banStatus['error'] || $banStatusUser['error'];
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Event',
'model_id' => $id,
@ -7418,7 +7418,7 @@ class Event extends AppModel
if ($largest_event/$memory_scaling_factor > $memory_in_mb) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Event',
'model_id' => 0,

View File

@ -2158,7 +2158,7 @@ class Feed extends AppModel
}
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Feed',
'model_id' => $id,

View File

@ -202,7 +202,7 @@ class Galaxy extends AppModel
if (is_array($v)) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Galaxy',
'model_id' => 0,

View File

@ -1175,4 +1175,13 @@ class Log extends AppModel
}
return $this->elasticSearchClient;
}
public function saveOrFailSilently($data, $options = null)
{
try {
return $this->save($data, $options);
} catch (Exception $e) {
return false;
}
}
}

View File

@ -322,7 +322,7 @@ class Organisation extends AppModel
}
$backupFile->append($sql . PHP_EOL);
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Organisation',
'model_id' => $currentOrg['Organisation']['id'],
@ -359,7 +359,7 @@ class Organisation extends AppModel
$sql = 'UPDATE "' . $data['table'] . '" SET "' . $field . '" = ' . $currentOrg['Organisation']['id'] . ' WHERE "id" IN (' . implode(',', $dataMoved['values_changed'][$model][$field]) . ');';
}
$backupFile->append($sql . PHP_EOL);
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Organisation',
'model_id' => $currentOrg['Organisation']['id'],
@ -370,7 +370,7 @@ class Organisation extends AppModel
'change' => '',
));
} catch (Exception $e) {
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Organisation',
'model_id' => $currentOrg['Organisation']['id'],

View File

@ -1069,7 +1069,7 @@ class Server extends AppModel
$message = __('Push to server %s failed. Reason: %s', $id, $push);
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Server',
'model_id' => $id,
@ -1233,7 +1233,7 @@ class Server extends AppModel
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Server',
'model_id' => $id,
@ -2366,7 +2366,7 @@ class Server extends AppModel
if ($beforeResult !== true) {
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'Server',
'model_id' => 0,
@ -3898,7 +3898,7 @@ class Server extends AppModel
'change' => sprintf(__('Stopping a worker. Worker was of type %s with pid %s'), $queue, $pid)
)
);
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => $user['Organisation']['name'],
'model' => 'User',
'model_id' => $user['id'],

View File

@ -781,7 +781,7 @@ class ShadowAttribute extends AppModel
$this->Log = ClassRegistry::init('Log');
if (!Configure::read('MISP.background_jobs')) {
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -794,7 +794,7 @@ class ShadowAttribute extends AppModel
$count = $this->generateCorrelation();
$this->Log->create();
if (is_numeric($count)) {
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -805,7 +805,7 @@ class ShadowAttribute extends AppModel
'change' => 'The generation of Proposal correlations as part of the 2.4.20 datamodel upgrade is completed. ' . $count . ' proposals used.'
));
} else {
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,
@ -840,7 +840,7 @@ class ShadowAttribute extends AppModel
);
$this->Log->create();
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'Server',
'model_id' => 0,

View File

@ -932,7 +932,7 @@ class SharingGroup extends AppModel
'user_id' => 0,
'title' => 'Tried to update a sharing group as part of the 2.4.49 update, but the user used for creating the sharing group locally doesn\'t exist any longer.'
);
$this->Log->save($entry);
$this->Log->saveOrFailSilently($entry);
unset($syncUsers[$sg['SharingGroup']['sync_user_id']]);
continue;
}
@ -951,7 +951,7 @@ class SharingGroup extends AppModel
'user_id' => 0,
'title' => 'Tried to update a sharing group as part of the 2.4.49 update, but saving the changes has resulted in the following error: ' . json_encode($this->SharingGroupOrg->validationErrors)
);
$this->Log->save($entry);
$this->Log->saveOrFailSilently($entry);
}
}
}

View File

@ -181,7 +181,7 @@ class SharingGroupBlueprint extends AppModel
'title' => 'Updated the sharing group.',
'change' => __('Updated sharing group. Added %s and removed %s organisations', $added, $removed)
);
$this->Log->save($entry);
$this->Log->saveOrFailSilently($entry);
return true;
}
return false;

View File

@ -875,7 +875,7 @@ class User extends AppModel
} catch (SendEmailException $e) {
$this->logException("Exception during sending e-mail", $e);
$log->create();
$log->save(array(
$Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'User',
'model_id' => $user['User']['id'],
@ -892,7 +892,7 @@ class User extends AppModel
$logTitle .= $replyToLog . ' to ' . $user['User']['email'] . ' sent, titled "' . $result['subject'] . '".';
$log->create();
$log->save(array(
$Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'User',
'model_id' => $user['User']['id'],
@ -1410,7 +1410,7 @@ class User extends AppModel
$error[$key] = $key . ': ' . implode(', ', $errors);
}
$error = implode(PHP_EOL, $error);
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'User',
'model_id' => $added_by['id'],
@ -1425,7 +1425,7 @@ class User extends AppModel
'recursive' => -1,
'conditions' => array('id' => $this->id)
));
$this->Log->save(array(
$this->Log->saveOrFailSilently(array(
'org' => 'SYSTEM',
'model' => 'User',
'model_id' => $added_by['id'],

View File

@ -120,7 +120,7 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
'action' => 'auth',
'title' => $logmessage
];
$this->Log->save($log);
$this->Log->saveOrFailSilently($log);
CakeLog::write($level, $logmessage);
return true;

View File

@ -539,7 +539,7 @@ class LogableBehavior extends ModelBehavior {
$logData['Log']['description'] .= '.';
}
$this->Log->create($logData);
$this->Log->save(null, array(
$this->Log->saveOrFailSilently(null, array(
'validate' => false,
'callbacks' => false));
}

View File

@ -259,7 +259,7 @@ class SysLogLogableBehavior extends LogableBehavior
}
}
$this->Log->create($logData);
$this->Log->save(null, array('validate' => false));
$this->Log->saveOrFailSilently(null, array('validate' => false));
}
function setup(Model $Model, $config = array())