Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
glpi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
GLPI
glpi
Commits
d629ab52
Commit
d629ab52
authored
Apr 11, 2019
by
Johan Cwiklinski
Committed by
Johan Cwiklinski
Apr 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix usage of INFORMATION_SCHEMA db on MySQL 8
parent
e3568eab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
35 deletions
+45
-35
inc/console/migration/buildmissingtimestampscommand.class.php
...console/migration/buildmissingtimestampscommand.class.php
+9
-6
inc/console/migration/timestampscommand.class.php
inc/console/migration/timestampscommand.class.php
+22
-15
inc/dbmysql.class.php
inc/dbmysql.class.php
+8
-8
tests/units/Migration.php
tests/units/Migration.php
+6
-6
No files found.
inc/console/migration/buildmissingtimestampscommand.class.php
View file @
d629ab52
...
...
@@ -57,14 +57,17 @@ class BuildMissingTimestampsCommand extends AbstractCommand {
$tables_iterator
=
$this
->
db
->
request
(
[
'SELECT'
=>
[
'TABLE_NAME'
,
'COLUMN_NAME'
],
'FROM'
=>
'INFORMATION_SCHEMA.COLUMNS'
,
'SELECT'
=>
[
'table_name AS TABLE_NAME'
,
'column_name AS COLUMN_NAME'
,
],
'FROM'
=>
'information_schema.columns'
,
'WHERE'
=>
[
'
TABLE_SCHEMA
'
=>
$this
->
db
->
dbdefault
,
'
TABLE_NAME
'
=>
[
'LIKE'
,
'glpi_%'
],
'
COLUMN_NAME
'
=>
[
'date_creation'
,
'date_mod'
],
'
table_schema
'
=>
$this
->
db
->
dbdefault
,
'
table_name
'
=>
[
'LIKE'
,
'glpi_%'
],
'
column_name
'
=>
[
'date_creation'
,
'date_mod'
],
],
'ORDER'
=>
[
'
TABLE_NAME'
,
'COLUMN_NAME
'
],
'ORDER'
=>
[
'
table_name'
,
'column_name
'
],
]
);
...
...
inc/console/migration/timestampscommand.class.php
View file @
d629ab52
...
...
@@ -48,7 +48,7 @@ class TimestampsCommand extends AbstractCommand {
parent
::
configure
();
$this
->
setName
(
'glpi:migration:timestamps'
);
$this
->
setDescription
(
__
(
'Convert
DATETIME to timestamps
to use timezones.'
));
$this
->
setDescription
(
__
(
'Convert
"datetime" fields to "timestamp"
to use timezones.'
));
}
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
...
...
@@ -56,31 +56,31 @@ class TimestampsCommand extends AbstractCommand {
// we are going to update datetime, date and time (?) types to timestamp type
$tbl_iterator
=
$this
->
db
->
request
([
'SELECT'
=>
[
'
INFORMATION_SCHEMA.COLUMNS.
TABLE_NAME'
],
'SELECT'
=>
[
'
information_schema.columns.table_name as
TABLE_NAME'
],
'DISTINCT'
=>
true
,
'FROM'
=>
'
INFORMATION_SCHEMA.COLUMNS
'
,
'FROM'
=>
'
information_schema.columns
'
,
'INNER JOIN'
=>
[
'
INFORMATION_SCHEMA.TABLES
'
=>
[
'
information_schema.tables
'
=>
[
'ON'
=>
[
'
INFORMATION_SCHEMA.TABLES.TABLE_NAME
'
,
'
INFORMATION_SCHEMA.COLUMNS.TABLE_NAME
'
,
[
'AND'
=>
[
'
INFORMATION_SCHEMA.TABLES.TABLE_TYPE
'
=>
'BASE TABLE'
]
'
information_schema.tables.table_name
'
,
'
information_schema.columns.table_name
'
,
[
'AND'
=>
[
'
information_schema.tables.table_type
'
=>
'BASE TABLE'
]
]
]
]
],
'WHERE'
=>
[
'
INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA
'
=>
$this
->
db
->
dbdefault
,
'
INFORMATION_SCHEMA.COLUMNS.COLUMN_TYPE'
=>
'DATETIME
'
'
information_schema.columns.table_schema
'
=>
$this
->
db
->
dbdefault
,
'
information_schema.columns.data_type'
=>
'datetime
'
],
'ORDER'
=>
[
'
INFORMATION_SCHEMA.COLUMNS.TABLE_NAME
'
'
information_schema.columns.table_name
'
]
]);
$output
->
writeln
(
sprintf
(
'<info>'
.
__
(
'Found %s table(s)
using
requiring migration.'
)
.
'</info>'
,
'<info>'
.
__
(
'Found %s table(s) requiring migration.'
)
.
'</info>'
,
$tbl_iterator
->
count
()
)
);
...
...
@@ -118,11 +118,18 @@ class TimestampsCommand extends AbstractCommand {
// get accurate info from information_schema to perform correct alter
$col_iterator
=
$this
->
db
->
request
([
'FROM'
=>
'INFORMATION_SCHEMA.COLUMNS'
,
'SELECT'
=>
[
'table_name AS TABLE_NAME'
,
'column_name AS COLUMN_NAME'
,
'column_default AS COLUMN_DEFAULT'
,
'column_comment AS COLUMN_COMMENT'
,
'is_nullable AS IS_NULLABLE'
,
],
'FROM'
=>
'information_schema.columns'
,
'WHERE'
=>
[
'
TABLE_SCHEMA
'
=>
$this
->
db
->
dbdefault
,
'
TABLE_NAME
'
=>
$table
[
'TABLE_NAME'
],
'
COLUMN_TYPE'
=>
'DATETIME
'
'
table_schema
'
=>
$this
->
db
->
dbdefault
,
'
table_name
'
=>
$table
[
'TABLE_NAME'
],
'
data_type'
=>
'datetime
'
]
]);
...
...
inc/dbmysql.class.php
View file @
d629ab52
...
...
@@ -537,12 +537,12 @@ class DBmysql {
*/
function
listTables
(
$table
=
'glpi_%'
,
array
$where
=
[])
{
$iterator
=
$this
->
request
([
'SELECT'
=>
'TABLE_NAME'
,
'FROM'
=>
'information_schema.
TABLES
'
,
'SELECT'
=>
'
table_name as
TABLE_NAME'
,
'FROM'
=>
'information_schema.
tables
'
,
'WHERE'
=>
[
'
TABLE_SCHEMA
'
=>
$this
->
dbdefault
,
'
TABLE_TYPE
'
=>
'BASE TABLE'
,
'
TABLE_NAME
'
=>
[
'LIKE'
,
$table
]
'
table_schema
'
=>
$this
->
dbdefault
,
'
table_type
'
=>
'BASE TABLE'
,
'
table_name
'
=>
[
'LIKE'
,
$table
]
]
+
$where
]);
return
$iterator
;
...
...
@@ -1510,10 +1510,10 @@ class DBmysql {
$result
=
$DB
->
request
([
'COUNT'
=>
'cpt'
,
'FROM'
=>
'
INFORMATION_SCHEMA.COLUMNS
'
,
'FROM'
=>
'
information_schema.columns
'
,
'WHERE'
=>
[
'
INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA
'
=>
$DB
->
dbdefault
,
'
INFORMATION_SCHEMA.COLUMNS.COLUMN_TYPE'
=>
[
'DATETIME
'
]
'
information_schema.columns.table_schema
'
=>
$DB
->
dbdefault
,
'
information_schema.columns.column_type'
=>
[
'datetime
'
]
]
])
->
next
();
return
(
int
)
$result
[
'cpt'
];
...
...
tests/units/Migration.php
View file @
d629ab52
...
...
@@ -188,12 +188,12 @@ class Migration extends \GLPITestCase {
)
->
isIdenticalTo
(
"Task completed."
);
$this
->
array
(
$this
->
queries
)
->
isIdenticalTo
([
0
=>
'SELECT `
TABLE_NAME` FROM `information_schema`.`TABLES
`'
.
' WHERE `
TABLE_SCHEMA
` = \''
.
$DB
->
dbdefault
.
'\' AND `
TABLE_TYPE` = \'BASE TABLE\' AND `TABLE_NAME
` LIKE \'%table1%\''
,
1
=>
'SELECT `
TABLE_NAME` FROM `information_schema`.`TABLES
`'
.
' WHERE `
TABLE_SCHEMA
` = \''
.
$DB
->
dbdefault
.
'\' AND `
TABLE_TYPE` = \'BASE TABLE\' AND `TABLE_NAME
` LIKE \'%table2%\''
0
=>
'SELECT `
table_name` AS `TABLE_NAME` FROM `information_schema`.`tables
`'
.
' WHERE `
table_schema
` = \''
.
$DB
->
dbdefault
.
'\' AND `
table_type` = \'BASE TABLE\' AND `table_name
` LIKE \'%table1%\''
,
1
=>
'SELECT `
table_name` AS `TABLE_NAME` FROM `information_schema`.`tables
`'
.
' WHERE `
table_schema
` = \''
.
$DB
->
dbdefault
.
'\' AND `
table_type` = \'BASE TABLE\' AND `table_name
` LIKE \'%table2%\''
]);
//try to backup existant tables
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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