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
981aa912
Commit
981aa912
authored
Apr 08, 2019
by
Cédric Anne
Committed by
Johan Cwiklinski
Apr 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bad usage of \d in MySQL regexp; fixes #5457
parent
503c1d1d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
2 deletions
+87
-2
inc/document.class.php
inc/document.class.php
+1
-1
install/update_940_941.php
install/update_940_941.php
+6
-1
install/update_941_942.php
install/update_941_942.php
+80
-0
No files found.
inc/document.class.php
View file @
981aa912
...
...
@@ -846,7 +846,7 @@ class Document extends CommonDBTM {
* @return string
*/
private
function
getSelfUrlRegexPattern
()
{
return
'document\\\.send\\\.php\\\?docid='
.
$this
->
fields
[
'id'
]
.
'[^
\\\d
]+'
;
return
'document\\\.send\\\.php\\\?docid='
.
$this
->
fields
[
'id'
]
.
'[^
0-9
]+'
;
}
static
function
rawSearchOptionsToAdd
(
$itemtype
=
null
)
{
...
...
install/update_940_941.php
View file @
981aa912
...
...
@@ -57,6 +57,11 @@ function update940to941() {
));
/** Fix URL of images inside ITIL objects contents */
// There is an exact copy of this process in "update941to942()".
// First version of this migration was working
// on MariaDB but not on MySQL due to usage of "\d" in a REGEXP expression.
// It has been fixed here for people who had not yet updated to 9.4.1 but have been put there
// for people already having updated to 9.4.1.
$migration
->
displayMessage
(
sprintf
(
__
(
'Fix URL of images in ITIL tasks, followups ans solutions.'
)));
// Search for contents that does not contains the itil object parameter after the docid parameter
...
...
@@ -64,7 +69,7 @@ function update940to941() {
// 1st capturing group is the end of href attribute value
// 2nd capturing group is the href attribute ending quote
$quotes_possible_exp
=
[
'\''
,
'''
,
'''
,
'''
,
'"'
,
'"'
,
'"'
,
'"'
];
$missing_param_pattern
=
'(document\.send\.php\?docid=
\d
+)('
.
implode
(
'|'
,
$quotes_possible_exp
)
.
')'
;
$missing_param_pattern
=
'(document\.send\.php\?docid=
[0-9]
+)('
.
implode
(
'|'
,
$quotes_possible_exp
)
.
')'
;
$itil_mappings
=
[
'Change'
=>
[
...
...
install/update_941_942.php
View file @
981aa912
...
...
@@ -61,6 +61,86 @@ function update941to942() {
);
/* /Remove trailing slash from 'url_base' config */
/** Fix URL of images inside ITIL objects contents */
// This is an exact copy of the same process used in "update940to941()" which was working
// on MariaDB but not on MySQL due to usage of "\d" in a REGEXP expression.
// It has been fixed there for people who had not yet updated to 9.4.1 but have to
// be put back here for people already having updated to 9.4.1.
$migration
->
displayMessage
(
sprintf
(
__
(
'Fix URL of images in ITIL tasks, followups ans solutions.'
)));
// Search for contents that does not contains the itil object parameter after the docid parameter
// (i.e. having a quote that ends the href just after the docid param value).
// 1st capturing group is the end of href attribute value
// 2nd capturing group is the href attribute ending quote
$quotes_possible_exp
=
[
'\''
,
'''
,
'''
,
'''
,
'"'
,
'"'
,
'"'
,
'"'
];
$missing_param_pattern
=
'(document\.send\.php\?docid=[0-9]+)('
.
implode
(
'|'
,
$quotes_possible_exp
)
.
')'
;
$itil_mappings
=
[
'Change'
=>
[
'itil_table'
=>
'glpi_changes'
,
'itil_fkey'
=>
'changes_id'
,
'task_table'
=>
'glpi_changetasks'
,
],
'Problem'
=>
[
'itil_table'
=>
'glpi_problems'
,
'itil_fkey'
=>
'problems_id'
,
'task_table'
=>
'glpi_problemtasks'
,
],
'Ticket'
=>
[
'itil_table'
=>
'glpi_tickets'
,
'itil_fkey'
=>
'tickets_id'
,
'task_table'
=>
'glpi_tickettasks'
,
],
];
$fix_content_fct
=
function
(
$content
,
$itil_id
,
$itil_fkey
)
use
(
$missing_param_pattern
)
{
// Add itil object param between docid param ($1) and ending quote ($2)
return
preg_replace
(
'/'
.
$missing_param_pattern
.
'/'
,
'$1&'
.
http_build_query
([
$itil_fkey
=>
$itil_id
])
.
'$2'
,
$content
);
};
foreach
(
$itil_mappings
as
$itil_type
=>
$itil_specs
)
{
$itil_fkey
=
$itil_specs
[
'itil_fkey'
];
$task_table
=
$itil_specs
[
'task_table'
];
// Fix followups and solutions
foreach
([
'glpi_itilfollowups'
,
'glpi_itilsolutions'
]
as
$itil_element_table
)
{
$elements_to_fix
=
$DB
->
request
(
[
'SELECT'
=>
[
'id'
,
'items_id'
,
'content'
],
'FROM'
=>
$itil_element_table
,
'WHERE'
=>
[
'itemtype'
=>
$itil_type
,
'content'
=>
[
'REGEXP'
,
$DB
->
escape
(
$missing_param_pattern
)],
]
]
);
foreach
(
$elements_to_fix
as
$data
)
{
$data
[
'content'
]
=
$fix_content_fct
(
$data
[
'content'
],
$data
[
'items_id'
],
$itil_fkey
);
$DB
->
update
(
$itil_element_table
,
$data
,
[
'id'
=>
$data
[
'id'
]]);
}
}
// Fix tasks
$tasks_to_fix
=
$DB
->
request
(
[
'SELECT'
=>
[
'id'
,
$itil_fkey
,
'content'
],
'FROM'
=>
$task_table
,
'WHERE'
=>
[
'content'
=>
[
'REGEXP'
,
$DB
->
escape
(
$missing_param_pattern
)],
]
]
);
foreach
(
$tasks_to_fix
as
$data
)
{
$data
[
'content'
]
=
$fix_content_fct
(
$data
[
'content'
],
$data
[
$itil_fkey
],
$itil_fkey
);
$DB
->
update
(
$task_table
,
$data
,
[
'id'
=>
$data
[
'id'
]]);
}
}
/** /Fix URL of images inside ITIL objects contents */
// ************ Keep it at the end **************
$migration
->
executeMigration
();
...
...
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