Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Inlay
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
Inlay
Commits
bfa7456a
Commit
bfa7456a
authored
1 year ago
by
Rich Lott / Artful Robot
Browse files
Options
Downloads
Patches
Plain Diff
Add a validateConfig parameter on Inlay.get API for upgrader scripts
parent
c08ba9f7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Civi/Api4/Action/Inlay/Get.php
+41
-17
41 additions, 17 deletions
Civi/Api4/Action/Inlay/Get.php
with
41 additions
and
17 deletions
Civi/Api4/Action/Inlay/Get.php
+
41
−
17
View file @
bfa7456a
...
...
@@ -5,7 +5,19 @@ use Civi\Api4\Generic\DAOGetAction;
use
Civi\Api4\Generic\Result
;
use
Civi\Inlay\Config
as
InlayConfig
;
class
Get
extends
DAOGetAction
{
/**
*
* @method Get setValidateConfig(bool $validateConfig)
*/
class
Get
extends
DAOGetAction
{
/**
* Whether to validate the config. For upgrader use only.
*
* @var bool
* @default TRUE;
*/
protected
$validateConfig
;
/**
* Override the _run method.
...
...
@@ -15,34 +27,46 @@ class Get extends DAOGetAction {
$select
=
$this
->
getSelect
();
$weCanAddBundleUrl
=
(
$select
===
[]
||
(
in_array
(
'public_id'
,
$select
)));
$weCanAddConfig
=
(
$select
===
[]
||
(
count
(
array_intersect
(
$select
,
[
'class'
,
'public_id'
,
'config'
,
'name'
]))
===
4
));
$configDataLoaded
=
(
$select
===
[]
||
(
in_array
(
'public_id'
,
$select
)));
$weCanValidateConfig
=
(
$select
===
[]
||
(
count
(
array_intersect
(
$select
,
[
'class'
,
'public_id'
,
'config'
,
'name'
]))
===
4
));
$inlayConfig
=
InlayConfig
::
singleton
();
foreach
(
$result
as
&
$item
)
{
if
(
$weCanAddBundleUrl
)
{
$item
[
'scriptUrl'
]
=
$inlayConfig
->
getBundleUrl
(
$item
[
'public_id'
]);
}
if
(
$weCanAddConfig
)
{
// Allow the class to validate the input.
$item
[
'config'
]
=
json_decode
(
$item
[
'config'
],
TRUE
);
try
{
$inlay
=
\Civi\Inlay\Type
::
fromArray
(
$item
);
$item
[
'config'
]
=
$inlay
->
config
;
$item
[
'scriptUrl'
]
=
$inlay
->
getBundleUrl
();
}
catch
(
\RuntimeException
$e
)
{
if
(
$e
->
getCode
()
===
\Civi\Inlay\Type
::
INVALID_SUBCLASS
)
{
$item
[
'error'
]
=
$e
->
getMessage
();
if
(
$this
->
validateConfig
)
{
// Normally we only allow access to 'config' if we can validate it.
if
(
$weCanValidateConfig
)
{
// Allow the class to validate the input.
$item
[
'config'
]
=
json_decode
(
$item
[
'config'
]
??
'[]'
,
TRUE
);
try
{
$inlay
=
\Civi\Inlay\Type
::
fromArray
(
$item
);
$item
[
'config'
]
=
$inlay
->
config
;
}
else
{
throw
$e
;
catch
(
\RuntimeException
$e
)
{
if
(
$e
->
getCode
()
===
\Civi\Inlay\Type
::
INVALID_SUBCLASS
)
{
$item
[
'error'
]
=
$e
->
getMessage
();
}
else
{
throw
$e
;
}
}
}
else
{
// Do not allow access to the config unless we have enough to validate it with the class.
unset
(
$item
[
'config'
]);
}
}
else
{
// Do not allow access to the config unless we have enough to validate it with the class.
unset
(
$item
[
'config'
]);
// Special case: do NOT validate the config. This can be used by
// Upgrader scripts that need to munge config; if they only ever
// got valid config they might lose access to deprecated values.
if
(
$configDataLoaded
)
{
$item
[
'config'
]
=
json_decode
(
$item
[
'config'
]
??
'[]'
,
TRUE
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment