Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fusiondirectory
fusiondirectory
Commits
93b8c263
Commit
93b8c263
authored
Oct 10, 2016
by
Côme Chilliet
Browse files
Fixes
#4840
Detecting recursive dependencies at template save
parent
14a3f111
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/class_templateHandling.inc
View file @
93b8c263
...
...
@@ -36,7 +36,8 @@ class templateHandling
$ldap
->
cat
(
$dn
);
$attrs
=
$ldap
->
fetch
();
$attrs
=
static
::
fieldsFromLDAP
(
$attrs
);
$depends
=
static
::
attributesDependencies
(
$attrs
);
list
(
$depends
,
$errors
)
=
static
::
attributesDependencies
(
$attrs
);
msg_dialog
::
displayChecks
(
$errors
);
$attrs
=
static
::
sortAttributes
(
$attrs
,
$depends
);
return
array
(
$attrs
,
$depends
);
}
...
...
@@ -103,6 +104,17 @@ class templateHandling
return
$template_attrs
;
}
/*! \brief Check template fields
*
* Returns errors if there are recursive dependencies.
* Might check more things later
*/
public
static
function
checkFields
(
$attrs
)
{
list
(
$depends
,
$errors
)
=
static
::
attributesDependencies
(
$attrs
);
return
$errors
;
}
/*! \brief Parse a mask (without surrounding %) using $attrs attributes, apply modifiers and returns an array containing possible results */
public
static
function
parseMask
(
$mask
,
array
$attrs
)
{
...
...
@@ -374,7 +386,7 @@ class templateHandling
}
/*! \brief Flattens dependencies (if a depends of b which depends of c then a depends of c) */
protected
static
function
flatDepends
(
&
$cache
,
$depends
,
$key
,
array
$forbidden
=
array
())
protected
static
function
flatDepends
(
&
$cache
,
&
$errors
,
$depends
,
$key
,
array
$forbidden
=
array
())
{
if
(
isset
(
$cache
[
$key
]))
{
return
$cache
[
$key
];
...
...
@@ -387,18 +399,14 @@ class templateHandling
function
(
$a
)
use
(
&
$cache
,
$depends
,
$forbidden
,
$key
)
{
if
(
in_array
(
$a
,
$forbidden
))
{
msg_dialog
::
display
(
_
(
'Error'
),
sprintf
(
_
(
'Recursive dependency in the template fields: "%1$s" cannot depend on "%2$s" as "%2$s" already depends on "%1$s"'
),
$key
,
$a
),
ERROR_DIALOG
$errors
[]
=
sprintf
(
_
(
'Recursive dependency in the template fields: "%1$s" cannot depend on "%2$s" as "%2$s" already depends on "%1$s"'
),
$key
,
$a
);
return
array
();
}
$deps
=
static
::
flatDepends
(
$cache
,
$depends
,
$a
,
$forbidden
);
$deps
=
static
::
flatDepends
(
$cache
,
$errors
,
$depends
,
$a
,
$forbidden
);
if
((
$askmeKey
=
array_search
(
'askme'
,
$deps
))
!==
FALSE
)
{
/* Do not flat special askme dependency */
unset
(
$deps
[
$askmeKey
]);
...
...
@@ -437,11 +445,12 @@ class templateHandling
}
}
/* Flattens dependencies */
$flatdepends
=
array
();
$flatdepends
=
array
();
$errors
=
array
();
foreach
(
$depends
as
$key
=>
$value
)
{
static
::
flatDepends
(
$flatdepends
,
$depends
,
$key
);
static
::
flatDepends
(
$flatdepends
,
$errors
,
$depends
,
$key
);
}
return
$flatdepends
;
return
array
(
$flatdepends
,
$errors
)
;
}
/*! \brief Sort attrs depending of dependencies */
...
...
include/simpleplugin/class_simplePlugin.inc
View file @
93b8c263
...
...
@@ -974,6 +974,10 @@ class simplePlugin extends plugin
@
DEBUG
(
DEBUG_TRACE
,
__LINE__
,
__FUNCTION__
,
__FILE__
,
$this
->
dn
,
"save"
);
$this
->
prepare_save
();
if
(
$this
->
is_template
&&
(
!
defined
(
'_OLD_TEMPLATES_'
)
||
!
_OLD_TEMPLATES_
))
{
$errors
=
templateHandling
::
checkFields
(
$this
->
attrs
);
if
(
!
empty
(
$errors
))
{
return
$errors
;
}
$this
->
attrs
=
$this
->
templateSaveAttrs
();
$this
->
saved_attributes
=
array
();
}
...
...
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