Commit 312d3f95 authored by cconard96's avatar cconard96 Committed by Johan Cwiklinski
Browse files

Add DB truncate method

parent cafa2b21
......@@ -22,6 +22,7 @@ The present file will list all changes made to the project; according to the
#### Changes
- Format of `Message-Id` header sent in Tickets notifications changed to match format used by other items.
- Added `DB::truncate()` to replace raw SQL queries
#### Deprecated
- Usage of `GLPI_FORCE_EMPTY_SQL_MODE` constant
......
......@@ -1328,6 +1328,51 @@ class DBmysql {
}
/**
* Truncate table in the database
*
* @since x.x.x
*
* @param string $table Table name
*
* @return mysqli_result|boolean Query result handler
*/
public function truncate($table) {
$table_name = $this::quoteName($table);
return $this->query("TRUNCATE $table_name");
}
/**
* Truncate table in the database or die
* (optionally with a message) if it fails
*
* @since x.x.x
*
* @param string $table Table name
* @param string $message Explanation of query (default '')
*
* @return mysqli_result|boolean Query result handler
*/
function truncateOrDie($table, $message = '') {
$table_name = $this::quoteName($table);
$res = $this->query("TRUNCATE $table_name");
if (!$res) {
//TRANS: %1$s is the description, %2$s is the query, %3$s is the error message
$message = sprintf(
__('%1$s - Error during the database query: %2$s - Error is %3$s'),
$message,
"TRUNCATE $table",
$this->error()
);
if (isCommandLine()) {
throw new \RuntimeException($message);
}
echo $message . "\n";
die(1);
}
return $res;
}
/**
* Get table schema
*
......
......@@ -210,8 +210,7 @@ class NotImportedEmail extends CommonDBTM {
static function deleteLog() {
global $DB;
$query = "TRUNCATE `glpi_notimportedemails`";
$DB->query($query);
$DB->truncate('glpi_notimportedemails');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment