From 974c28d8a7fbac878a3c192c53923228a44778ae Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 27 Jul 2021 13:58:43 +0200 Subject: [PATCH 1/5] chg: [internal] Remove unused variable --- app/Model/Attribute.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 4d0ccda40..a58cfbbae 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -45,10 +45,6 @@ class Attribute extends AppModel 'distribution' => array('desc' => 'Describes who will have access to the attribute.') ); - public $defaultFields = array( - 'id', 'event_id', 'object_id', 'object_relation', 'category', 'type', 'value', 'to_ids', 'uuid', 'timestamp', 'distribution', 'sharing_group_id', 'comment', 'deleted', 'disable_correlation', 'first_seen', 'last_seen' - ); - public $editableFields = array('timestamp', 'category', 'value', 'value1', 'value2', 'to_ids', 'comment', 'distribution', 'sharing_group_id', 'deleted', 'disable_correlation', 'first_seen', 'last_seen'); public $distributionDescriptions = array( From 15e3cc799c8dc2196d8c534c5d5708de168f3054 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sat, 24 Jul 2021 22:58:21 +0200 Subject: [PATCH 2/5] chg: [internal] Removed unused variables --- app/Model/AppModel.php | 18 +++--------------- app/Model/Event.php | 2 ++ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index b501d4ad6..352c69298 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -24,6 +24,7 @@ App::uses('Model', 'Model'); App::uses('LogableBehavior', 'Assets.models/behaviors'); App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth'); App::uses('RandomTool', 'Tools'); + class AppModel extends Model { public $name; @@ -33,13 +34,8 @@ class AppModel extends Model */ private $loadedPubSubTool; - public $loadedKafkaPubTool = false; - - public $start = 0; - - public $assetCache = []; - - public $inserted_ids = array(); + /** @var KafkaPubTool */ + public $loadedKafkaPubTool; /** @var null|Redis */ private static $__redisConnection = null; @@ -107,14 +103,6 @@ class AppModel extends Model ), ); - public function afterSave($created, $options = array()) - { - if ($created) { - $this->inserted_ids[] = $this->getInsertID(); - } - return true; - } - public function isAcceptedDatabaseError($errorMessage, $dataSource) { $isAccepted = false; diff --git a/app/Model/Event.php b/app/Model/Event.php index ed698611e..19c50f0fc 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -376,6 +376,8 @@ class Event extends AppModel ); } + private $assetCache = []; + public function beforeDelete($cascade = true) { // blocklist the event UUID if the feature is enabled From bcb93288411424e88c66b0c5d227a77dfb4da798 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sat, 24 Jul 2021 22:57:15 +0200 Subject: [PATCH 3/5] chg: [internal] Simplified Attribute::deleteAttribute method --- app/Model/Attribute.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index a58cfbbae..ff98aa37f 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -13,6 +13,7 @@ App::uses('ComplexTypeTool', 'Tools'); * @property Event $Event * @property AttributeTag $AttributeTag * @property Sighting $Sighting + * @property MispObject $Object * @property-read array $typeDefinitions * @property-read array $categoryDefinitions */ @@ -3853,12 +3854,8 @@ class Attribute extends AppModel return true; } - public function deleteAttribute($id, $user, $hard = false) + public function deleteAttribute($id, array $user, $hard = false) { - $this->id = $id; - if (!$this->exists()) { - return false; - } $result = $this->fetchAttributes($user, array( 'conditions' => array('Attribute.id' => $id), 'flatten' => 1, @@ -3883,7 +3880,6 @@ class Attribute extends AppModel } } } - $date = new DateTime(); if ($hard) { $save = $this->delete($id); } else { @@ -3895,7 +3891,7 @@ class Attribute extends AppModel $result['Attribute']['to_ids'] = 0; } $result['Attribute']['deleted'] = 1; - $result['Attribute']['timestamp'] = $date->getTimestamp(); + $result['Attribute']['timestamp'] = time(); $save = $this->save($result); $object_refs = $this->Object->ObjectReference->find('all', array( 'conditions' => array( From db242d69016d84f9a377fde4a14e65e0e351b527 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 27 Jul 2021 18:49:40 +0200 Subject: [PATCH 4/5] chg: [internal] Convert array to const --- app/Model/AppModel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 352c69298..9a0cea8c5 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -57,7 +57,7 @@ class AppModel extends Model // deprecated, use $db_changes // major -> minor -> hotfix -> requires_logout - public $old_db_changes = array( + const OLD_DB_CHANGES = array( 2 => array( 4 => array( 18 => false, 19 => false, 20 => false, 25 => false, 27 => false, @@ -74,7 +74,7 @@ class AppModel extends Model ) ); - public $db_changes = array( + const DB_CHANGES = array( 1 => false, 2 => false, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => false, 9 => false, 10 => false, 11 => false, 12 => false, 13 => false, 14 => false, 15 => false, 18 => false, 19 => false, 20 => false, @@ -2363,12 +2363,12 @@ class AppModel extends Model } } - public function findUpgrades($db_version) + protected function findUpgrades($db_version) { $updates = array(); if (strpos($db_version, '.')) { $version = explode('.', $db_version); - foreach ($this->old_db_changes as $major => $rest) { + foreach (self::OLD_DB_CHANGES as $major => $rest) { if ($major < $version[0]) { continue; } elseif ($major == $version[0]) { @@ -2391,7 +2391,7 @@ class AppModel extends Model } $db_version = 0; } - foreach ($this->db_changes as $db_change => $requiresLogout) { + foreach (self::DB_CHANGES as $db_change => $requiresLogout) { if ($db_version < $db_change) { $updates[$db_change] = $requiresLogout; } From 180fb627ccd8063dccfbdb1c872dc8ffc3e94330 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 27 Jul 2021 18:58:04 +0200 Subject: [PATCH 5/5] chg: [internal] Convert array to const --- app/Controller/AttributesController.php | 2 +- app/Model/Attribute.php | 18 ++++++++++++++++-- app/Model/MispObject.php | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index 2297ef7af..bd4124fb7 100644 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -790,7 +790,7 @@ class AttributesController extends AppController } } if ($existingAttribute['Attribute']['object_id']) { - $result = $this->Attribute->save($this->request->data, array('fieldList' => $this->Attribute->editableFields)); + $result = $this->Attribute->save($this->request->data, array('fieldList' => Attribute::EDITABLE_FIELDS)); if ($result) { $this->Attribute->AttributeTag->handleAttributeTags($this->Auth->user(), $this->request->data['Attribute'], $attribute['Event']['id'], $capture=true); } diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index ff98aa37f..8e6a8ca68 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -46,7 +46,21 @@ class Attribute extends AppModel 'distribution' => array('desc' => 'Describes who will have access to the attribute.') ); - public $editableFields = array('timestamp', 'category', 'value', 'value1', 'value2', 'to_ids', 'comment', 'distribution', 'sharing_group_id', 'deleted', 'disable_correlation', 'first_seen', 'last_seen'); + const EDITABLE_FIELDS = [ + 'timestamp', + 'category', + 'value', + 'value1', + 'value2', + 'to_ids', + 'comment', + 'distribution', + 'sharing_group_id', + 'deleted', + 'disable_correlation', + 'first_seen', + 'last_seen', + ]; public $distributionDescriptions = array( 0 => array('desc' => 'This field determines the current distribution of the event', 'formdesc' => "This setting will only allow members of your organisation on this server to see it."), @@ -3786,7 +3800,7 @@ class Attribute extends AppModel $attribute['distribution'] = 5; } } - $fieldList = $this->editableFields; + $fieldList = self::EDITABLE_FIELDS; if (empty($existingAttribute)) { $addableFieldList = array('event_id', 'type', 'uuid'); $fieldList = array_merge($fieldList, $addableFieldList); diff --git a/app/Model/MispObject.php b/app/Model/MispObject.php index 6f0dd3be7..78346455f 100644 --- a/app/Model/MispObject.php +++ b/app/Model/MispObject.php @@ -884,7 +884,7 @@ class MispObject extends AppModel $newAttribute['event_id'] = $object['Object']['event_id']; $newAttribute['object_id'] = $object['Object']['id']; $newAttribute['timestamp'] = $date->getTimestamp(); - $result = $this->Event->Attribute->save(array('Attribute' => $newAttribute), array('fieldList' => $this->Attribute->editableFields)); + $result = $this->Event->Attribute->save(array('Attribute' => $newAttribute), array('fieldList' => Attribute::EDITABLE_FIELDS)); if ($result) { $this->Event->Attribute->AttributeTag->handleAttributeTags($user, $newAttribute, $newAttribute['event_id'], $capture=true); } @@ -926,7 +926,7 @@ class MispObject extends AppModel } foreach ($object['Attribute'] as $origKey => $originalAttribute) { $originalAttribute['deleted'] = 1; - $this->Event->Attribute->save($originalAttribute, array('fieldList' => $this->Attribute->editableFields)); + $this->Event->Attribute->save($originalAttribute, array('fieldList' => Attribute::EDITABLE_FIELDS)); } } } else { // we only add the new attribute