Merge remote-tracking branch 'origin/develop' into fix-duplicated-uuids

pull/6168/head
Sami Mokaddem 2022-09-08 16:16:13 +02:00
commit db26b0cf66
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
9 changed files with 127 additions and 45 deletions

View File

@ -758,6 +758,8 @@ class AttributesController extends AppController
if (count($existingAttribute) && !$existingAttribute['Attribute']['deleted']) {
$this->request->data['Attribute']['id'] = $existingAttribute['Attribute']['id'];
$this->request->data['Attribute']['event_id'] = $existingAttribute['Attribute']['event_id'];
$this->request->data['Attribute']['object_id'] = $existingAttribute['Attribute']['object_id'];
$this->request->data['Attribute']['uuid'] = $existingAttribute['Attribute']['uuid'];
$skipTimeCheck = false;
if (!isset($this->request->data['Attribute']['timestamp'])) {
$this->request->data['Attribute']['timestamp'] = $dateObj->getTimestamp();
@ -790,7 +792,7 @@ class AttributesController extends AppController
}
$this->Attribute->Object->updateTimestamp($existingAttribute['Attribute']['object_id']);
} else {
$result = $this->Attribute->save($this->request->data);
$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);
}

View File

@ -629,6 +629,10 @@ class BackgroundJobsTool
];
}
if (!isset($this->settings['supervisor_host'])) {
throw new RuntimeException("Required option `supervisor_host` for BackgroundJobsTool is not set.");
}
$host = null;
if (substr($this->settings['supervisor_host'], 0, 5) === 'unix:') {
if (!defined('CURLOPT_UNIX_SOCKET_PATH')) {

View File

@ -1,25 +0,0 @@
<?php
class QueryTool
{
const PDO_MAP = array(
'integer' => PDO::PARAM_INT,
'float' => PDO::PARAM_STR,
'boolean' => PDO::PARAM_BOOL,
'string' => PDO::PARAM_STR,
'text' => PDO::PARAM_STR,
);
public function quickDelete($table, $field, $value, $model)
{
$db = $model->getDataSource();
$connection = $db->getConnection();
if (in_array($db->config['datasource'], ['Database/Mysql', 'Database/MysqlObserver', 'Database/MysqlExtended'])) {
$query = $connection->prepare('DELETE FROM ' . $table . ' WHERE ' . $field . ' = :value');
} elseif ($db->config['datasource'] == 'Database/Postgres' ) {
$query = $connection->prepare('DELETE FROM "' . $table . '" WHERE "' . $field . '" = :value');
}
$query->bindValue(':value', $value, self::PDO_MAP[$db->introspectType($value)]);
$query->execute();
}
}

View File

@ -7,6 +7,16 @@ App::uses('Mysql', 'Model/Datasource/Database');
*/
class MysqlExtended extends Mysql
{
/**
* Output MD5 as binary, that is faster and uses less memory
* @param string $value
* @return string
*/
public function cacheMethodHasher($value)
{
return md5($value, true);
}
/**
* Builds and generates an SQL statement from an array. Handles final clean-up before conversion.
*
@ -87,16 +97,15 @@ class MysqlExtended extends Mysql
* @return string|null Rendered SQL expression to be run, otherwise null.\
* @see DboSource::renderStatement()
*/
public function renderStatement($type, $data)
{
if ($type === 'select' && $data['indexHint'] != null) {
if ($type === 'select') {
extract($data);
$having = !empty($having) ? " $having" : '';
return trim("SELECT {$fields} FROM {$table} {$alias} {$indexHint} {$joins} {$conditions} {$group}{$having} {$order} {$limit}{$lock}");
} else {
return parent::renderStatement($type, $data);
$lock = !empty($lock) ? " $lock" : '';
return rtrim("SELECT {$fields} FROM {$table} {$alias} {$indexHint} {$joins} {$conditions} {$group}{$having} {$order} {$limit}{$lock}");
}
return parent::renderStatement($type, $data);
}
/**
@ -105,12 +114,93 @@ class MysqlExtended extends Mysql
* @param string|null $useIndexHint USE INDEX hint
* @return string
*/
private function __buildIndexHint($useIndexHint = null): string
private function __buildIndexHint($useIndexHint = null): ?string
{
$index = '';
if (isset($useIndexHint)) {
$index = 'USE INDEX ' . $useIndexHint;
return isset($useIndexHint) ? ('USE INDEX ' . $useIndexHint) : null;
}
/**
* Reduce memory usage for insertMulti
*
* @param string $table
* @param array $fields
* @param array $values
* @return bool
*/
public function insertMulti($table, $fields, $values)
{
$table = $this->fullTableName($table);
$holder = implode(',', array_fill(0, count($fields), '?'));
$fields = implode(',', array_map([$this, 'name'], $fields));
$pdoMap = [
'integer' => PDO::PARAM_INT,
'float' => PDO::PARAM_STR,
'boolean' => PDO::PARAM_BOOL,
'string' => PDO::PARAM_STR,
'text' => PDO::PARAM_STR
];
$columnMap = [];
foreach ($values[key($values)] as $key => $val) {
if (is_int($val)) {
$columnMap[$key] = PDO::PARAM_INT;
} elseif (is_bool($val)) {
$columnMap[$key] = PDO::PARAM_BOOL;
} else {
$type = $this->introspectType($val);
$columnMap[$key] = $pdoMap[$type];
}
}
return $index;
$sql = "INSERT INTO $table ($fields) VALUES ";
$sql .= implode(',', array_fill(0, count($values), "($holder)"));
$statement = $this->_connection->prepare($sql);
$valuesList = array();
$i = 1;
foreach ($values as $value) {
foreach ($value as $col => $val) {
if ($this->fullDebug) {
$valuesList[] = $val;
}
$statement->bindValue($i, $val, $columnMap[$col]);
$i++;
}
}
$result = $statement->execute();
$statement->closeCursor();
if ($this->fullDebug) {
$this->logQuery($sql, $valuesList);
}
return $result;
}
/**
* {@inheritDoc}
*/
public function value($data, $column = null, $null = true)
{
// Fast check if data is int, then return value
if (is_int($data)) {
return $data;
}
// No need to quote bool values
if (is_bool($data)) {
return $data ? '1' : '0';
}
// No need to call expensive array_map
if (is_array($data) && !empty($data)) {
$output = [];
foreach ($data as $d) {
if (is_int($d)) {
$output[] = $d;
} else {
$output[] = parent::value($d, $column);
}
}
return $output;
}
return parent::value($data, $column, $null);
}
}

View File

@ -1147,6 +1147,10 @@ class Event extends AppModel
return $data[0];
}
/**
* @param array $event
* @return bool
*/
public function quickDelete(array $event)
{
$id = (int)$event['Event']['id'];
@ -1156,7 +1160,7 @@ class Event extends AppModel
'fields' => array('Thread.id'),
'recursive' => -1
));
$thread_id = !empty($thread) ? $thread['Thread']['id'] : false;
$thread_id = !empty($thread) ? (int)$thread['Thread']['id'] : false;
$relations = array(
array(
'table' => 'attributes',
@ -1231,10 +1235,17 @@ class Event extends AppModel
)
);
}
App::uses('QueryTool', 'Tools');
$queryTool = new QueryTool();
$db = $this->getDataSource();
$db->begin();
$connection = $db->getConnection();
foreach ($relations as $relation) {
$queryTool->quickDelete($relation['table'], $relation['foreign_key'], $relation['value'], $this);
$query = $connection->prepare('DELETE FROM ' . $db->name($relation['table']) . ' WHERE ' . $db->name($relation['foreign_key']) . ' = :value');
$query->bindValue(':value', $relation['value'], PDO::PARAM_INT);
$query->execute();
}
if (!$db->commit()) {
return false;
}
$this->set($event);
return $this->delete(null, false);

@ -1 +1 @@
Subproject commit b0ffb843b0bb69ea94d3ce9318f5123612b4ccc9
Subproject commit 258515f9a8836ce7f49f00242f45d987fac43b24

@ -1 +1 @@
Subproject commit fc12a106f5481e466275799de71e29dd7cf764f7
Subproject commit aa251b6a4006372e66f3bf5e946111f6d5f6a2d6

View File

@ -478,7 +478,7 @@ $(document).ready( function() {
return false;
}
$(document).on('keydown', function(e) {
$("#chart").on('keydown', function(e) {
if (e.which == 69) {
if (highlighted == undefined) {
showPane(root['nodes'][0], 'selected');
@ -522,7 +522,7 @@ $(document).ready( function() {
});
*/
$(document).on('keydown', function(e) {
$("#chart").on('keydown', function(e) {
if (e.which == 88) {
e.preventDefault();
if (e.ctrlKey) {

View File

@ -9116,5 +9116,5 @@
"uuid": false
}
},
"db_version": "94"
"db_version": "95"
}