Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setInSafeMode example
$plugin
->
setRedirectToStore
(
(bool)
$data
[
'redirectToStore'
]
)
;
}
if
(
\
array_key_exists
(
'lowestPriceValue',
$data
)
)
{
$plugin
->
setLowestPrice
(
(float)
$data
[
'lowestPriceValue'
]
)
;
}
$plugin
->
setSource
(
$data
[
'source'
]
?? ''
)
;
$plugin
->
setFormId
(
$data
[
'form_id'
]
?? 0
)
;
$plugin
->
setLocalIcon
(
$data
[
'iconPath'
]
?? ''
)
;
$plugin
->
setLocalDescription
(
$data
[
'description'
]
?? ''
)
;
$plugin
->
setInSafeMode
(
(bool)
(
$data
[
'in_safe_mode'
]
?? false
)
)
;
if
(
isset
(
$data
[
'installation_date'
]
)
&& !
empty
(
$data
[
'installation_date'
]
)
)
{
$date
=
new
DateTime
(
$data
[
'installation_date'
]
)
;
$plugin
->
setInstallationDate
(
$date
)
;
}
if
(
isset
(
$data
[
'update_date'
]
)
&& !
empty
(
$data
[
'update_date'
]
)
)
{
$date
=
new
DateTime
(
$data
[
'update_date'
]
)
;
$plugin
->
setUpdateDate
(
$date
)
;
}
$bootstrap
=
$this
->
getPluginBootstrap
(
$plugin
)
;
$result
=
$bootstrap
->
enable
(
)
;
$result
= \
is_bool
(
$result
)
?
[
'success' =>
$result
]
:
$result
;
if
(
$result
[
'success'
]
== false
)
{
throw
new
Exception
(
sprintf
(
'Not allowed to enable plugin "%s".',
$plugin
->
getName
(
)
)
)
;
}
$plugin
->
setActive
(
true
)
;
$plugin
->
setInSafeMode
(
false
)
;
$this
->em->
flush
(
$plugin
)
;
return
$result
;
}
/** * @throws \Doctrine\ORM\OptimisticLockException * * @return array */
public
function
deactivatePlugin
(
Plugin
$plugin
)
{
public
function
toggleSafeModeAction
(
)
{
$plugins
=
$this
->
getThirdPartyPluginsQuery
(
)
->
getQuery
(
)
->
getResult
(
AbstractQuery::HYDRATE_OBJECT
)
;
$pluginsInSafeMode
=
$this
->
getPluginsInSafeMode
(
$plugins
)
;
$installer
=
$this
->container->
get
(
InstallerService::
class
)
;
if
(
$pluginsInSafeMode
)
{
foreach
(
$pluginsInSafeMode
as
$plugin
)
{
$plugin
->
setInSafeMode
(
false
)
;
if
(
!
$plugin
->
getActive
(
)
)
{
$installer
->
activatePlugin
(
$plugin
)
;
}
}
$this
->container->
get
(
ModelManager::
class
)
->
flush
(
)
;
$this
->
View
(
)
->
assign
(
[
'success' => true, 'inSafeMode' => false
]
)
;
return
;
}
$bootstrap
=
$this
->
getPluginByName
(
$plugin
->
getName
(
)
)
;
$this
->requirementValidator->
validate
(
$bootstrap
->
getPath
(
)
. '/plugin.xml',
$this
->release->
getVersion
(
)
)
;
$context
=
new
ActivateContext
(
$plugin
,
$this
->release->
getVersion
(
)
,
$plugin
->
getVersion
(
)
)
;
$this
->events->
notify
(
PluginEvent::PRE_ACTIVATE,
new
PrePluginActivateEvent
(
$context
,
$bootstrap
)
)
;
$bootstrap
->
activate
(
$context
)
;
$this
->events->
notify
(
PluginEvent::POST_ACTIVATE,
new
PostPluginActivateEvent
(
$context
,
$bootstrap
)
)
;
$plugin
->
setActive
(
true
)
;
$plugin
->
setInSafeMode
(
false
)
;
$this
->em->
flush
(
$plugin
)
;
return
$context
;
}
/** * @throws Exception * @throws \Doctrine\ORM\OptimisticLockException * * @return DeactivateContext */