mirror of https://github.com/MISP/MISP
chg: [internal] Remove QueryTool
parent
0245034373
commit
e293da740f
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1252,7 +1252,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',
|
||||
|
@ -1327,10 +1327,17 @@ class Event extends AppModel
|
|||
)
|
||||
);
|
||||
}
|
||||
App::uses('QueryTool', 'Tools');
|
||||
$queryTool = new QueryTool();
|
||||
|
||||
$db = $this->getDataSource();
|
||||
$connection = $db->getConnection();
|
||||
foreach ($relations as $relation) {
|
||||
$queryTool->quickDelete($relation['table'], $relation['foreign_key'], $relation['value'], $this);
|
||||
if ($this->isMysql()) {
|
||||
$query = $connection->prepare('DELETE FROM ' . $relation['table'] . ' WHERE ' . $relation['foreign_key'] . ' = :value');
|
||||
} else {
|
||||
$query = $connection->prepare('DELETE FROM "' . $relation['table'] . '" WHERE "' . $relation['foreign_key'] . '" = :value');
|
||||
}
|
||||
$query->bindValue(':value', $relation['value'], PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
}
|
||||
$this->set($event);
|
||||
return $this->delete(null, false);
|
||||
|
|
Loading…
Reference in New Issue