mirror of https://github.com/MISP/MISP
chg: [analyst-data:datetimes] Moved datetime manamgent of created and modified field from the DB to the app.
- This change is to enforce the usage of UTC time as using MySQL's CURRENT_TIMESTAMP uses the TZ of the serverpull/9583/head
parent
9573c308e0
commit
720336f65d
|
@ -89,7 +89,7 @@ class AnalystDataController extends AppController
|
|||
return $analystData;
|
||||
},
|
||||
'beforeSave' => function(array $analystData): array {
|
||||
$analystData[$this->modelSelection]['modified'] = date ('Y-m-d H:i:s');
|
||||
$analystData[$this->modelSelection]['modified'] = date('Y-m-d H:i:s');
|
||||
return $analystData;
|
||||
}
|
||||
];
|
||||
|
|
|
@ -126,7 +126,7 @@ class AnalystData extends AppModel
|
|||
|
||||
public function beforeValidate($options = array())
|
||||
{
|
||||
parent::beforeValidate();
|
||||
parent::beforeValidate($options);
|
||||
if (empty($this->id) && empty($this->data[$this->current_type]['uuid'])) {
|
||||
$this->data[$this->current_type]['uuid'] = CakeText::uuid();
|
||||
}
|
||||
|
@ -142,6 +142,20 @@ class AnalystData extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function beforeSave($options = [])
|
||||
{
|
||||
parent::beforeSave($options);
|
||||
if (empty($this->data[$this->current_type]['created'])) {
|
||||
$this->data[$this->current_type]['created'] = (new DateTime())->format('c');
|
||||
}
|
||||
if (empty($this->data[$this->current_type]['modified'])) {
|
||||
$this->data[$this->current_type]['modified'] = (new DateTime())->format('c');
|
||||
}
|
||||
$this->data[$this->current_type]['modified'] = (new DateTime($this->data[$this->current_type]['modified'], new DateTimeZone('UTC')))->format('c');
|
||||
$this->data[$this->current_type]['created'] = (new DateTime($this->data[$this->current_type]['created'], new DateTimeZone('UTC')))->format('c');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user can modify given analyst data
|
||||
*
|
||||
|
|
|
@ -91,6 +91,7 @@ class AppModel extends Model
|
|||
105 => false, 106 => false, 107 => false, 108 => false, 109 => false, 110 => false,
|
||||
111 => false, 112 => false, 113 => true, 114 => false, 115 => false, 116 => false,
|
||||
117 => false, 118 => false, 119 => false, 120 => false, 121 => false, 122 => false,
|
||||
123 => false,
|
||||
);
|
||||
|
||||
const ADVANCED_UPDATES_DESCRIPTION = array(
|
||||
|
@ -2155,6 +2156,14 @@ class AppModel extends Model
|
|||
UNIQUE KEY `unique_element` (`element_uuid`, `collection_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
|
||||
break;
|
||||
case 123:
|
||||
$sqlArray[] = 'ALTER TABLE `notes` MODIFY `created` datetime NOT NULL';
|
||||
$sqlArray[] = 'ALTER TABLE `opinions` MODIFY `created` datetime NOT NULL;';
|
||||
$sqlArray[] = 'ALTER TABLE `relationships` MODIFY `created` datetime NOT NULL;';
|
||||
$sqlArray[] = 'ALTER TABLE `notes` MODIFY `modified` datetime NOT NULL;';
|
||||
$sqlArray[] = 'ALTER TABLE `opinions` MODIFY `modified` datetime NOT NULL;';
|
||||
$sqlArray[] = 'ALTER TABLE `relationships` MODIFY `modified` datetime NOT NULL;';
|
||||
break;
|
||||
case 'fixNonEmptySharingGroupID':
|
||||
$sqlArray[] = 'UPDATE `events` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';
|
||||
$sqlArray[] = 'UPDATE `attributes` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';
|
||||
|
|
Loading…
Reference in New Issue