Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
56b17f79
Commit
56b17f79
authored
Jul 02, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) change base validation behavior to default only validate changes
parent
7f0709df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
BaseModel.php
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
+14
-9
BaseField.php
...nse/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
+22
-0
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
View file @
56b17f79
...
...
@@ -290,8 +290,10 @@ abstract class BaseModel
/**
* validate full model using all fields and data in a single (1 deep) array
* @param bool $validateFullModel validate full model or only changed fields
* @return \Phalcon\Validation\Message\Group
*/
public
function
performValidation
()
public
function
performValidation
(
$validateFullModel
=
false
)
{
// create a Phalcon validator and collect all model validations
$validation
=
new
\Phalcon\Validation
();
...
...
@@ -299,12 +301,14 @@ abstract class BaseModel
$all_nodes
=
$this
->
internalData
->
getFlatNodes
();
foreach
(
$all_nodes
as
$key
=>
$node
)
{
$node_validators
=
$node
->
getValidators
();
foreach
(
$node_validators
as
$item_validator
)
{
$validation
->
add
(
$key
,
$item_validator
);
}
if
(
count
(
$node_validators
)
>
0
)
{
$validation_data
[
$key
]
=
$node
->
__toString
();
if
(
$validateFullModel
||
$node
->
isFieldChanged
())
{
$node_validators
=
$node
->
getValidators
();
foreach
(
$node_validators
as
$item_validator
)
{
$validation
->
add
(
$key
,
$item_validator
);
}
if
(
count
(
$node_validators
)
>
0
)
{
$validation_data
[
$key
]
=
$node
->
__toString
();
}
}
}
...
...
@@ -390,10 +394,11 @@ abstract class BaseModel
/**
* validate model and serialize data to config singleton object.
*
* @param bool $validateFullModel by default we only validate the fields we have changed
* @param bool $disable_validation skip validation, be careful to use this!
* @throws \Phalcon\Validation\Exception validation errors
*/
public
function
serializeToConfig
(
$disable_validation
=
false
)
public
function
serializeToConfig
(
$
validateFullModel
=
false
,
$
disable_validation
=
false
)
{
// create logger to save possible consistency issues to
$logger
=
new
Syslog
(
"config"
,
array
(
...
...
@@ -404,7 +409,7 @@ abstract class BaseModel
// Perform validation, collect all messages and raise exception if validation is not disabled.
// If for some reason the developer chooses to ignore the errors, let's at least log there something
// wrong in this model.
$messages
=
$this
->
performValidation
();
$messages
=
$this
->
performValidation
(
$validateFullModel
);
if
(
$messages
->
count
()
>
0
)
{
$exception_msg
=
""
;
foreach
(
$messages
as
$msg
)
{
...
...
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
View file @
56b17f79
...
...
@@ -60,6 +60,11 @@ abstract class BaseField
*/
protected
$internalDefaultValue
=
""
;
/**
* @var null|string initial value of this field (first set)
*/
protected
$internalInitialValue
=
null
;
/**
* @var string direct reference to this field in the model object
*/
...
...
@@ -244,9 +249,26 @@ abstract class BaseField
*/
public
function
setValue
(
$value
)
{
// if first set, store initial value
if
(
$this
->
internalInitialValue
==
null
)
{
$this
->
internalInitialValue
=
$value
;
}
$this
->
internalValue
=
$value
;
}
/**
* check if field content has changed
* @return bool change indicator
*/
public
function
isFieldChanged
()
{
if
(
$this
->
internalInitialValue
!==
$this
->
internalValue
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* Set attribute on Field object
* @param $key attribute key
...
...
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