Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GLPI
glpi
Commits
312d3f95
Commit
312d3f95
authored
Feb 26, 2021
by
cconard96
Committed by
Johan Cwiklinski
Mar 02, 2021
Browse files
Add DB truncate method
parent
cafa2b21
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
312d3f95
...
...
@@ -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
...
...
inc/dbmysql.class.php
View file @
312d3f95
...
...
@@ -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
*
...
...
inc/notimportedemail.class.php
View file @
312d3f95
...
...
@@ -210,8 +210,7 @@ class NotImportedEmail extends CommonDBTM {
static
function
deleteLog
()
{
global
$DB
;
$query
=
"TRUNCATE `glpi_notimportedemails`"
;
$DB
->
query
(
$query
);
$DB
->
truncate
(
'glpi_notimportedemails'
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment