chg: [internal] Remove QueryTool

pull/8373/head
Jakub Onderka 2022-05-20 14:02:57 +02:00
parent 0245034373
commit e293da740f
2 changed files with 11 additions and 29 deletions

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

@ -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);