Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
DeactivateContext example
$plugin
,
$dependantPlugins
)
;
if
(
\
count
(
$dependants
)
> 0
)
{
throw
new
PluginHasActiveDependantsException
(
$plugin
->
getName
(
)
,
$dependants
)
;
}
$pluginBaseClassString
=
$plugin
->
getBaseClass
(
)
;
$pluginBaseClass
=
$this
->
getPluginInstance
(
$pluginBaseClassString
)
;
$deactivateContext
=
new
DeactivateContext
(
$pluginBaseClass
,
$shopwareContext
,
$this
->shopwareVersion,
$plugin
->
getVersion
(
)
,
$this
->
createMigrationCollection
(
$pluginBaseClass
)
)
;
$deactivateContext
->
setAutoMigrate
(
false
)
;
$this
->eventDispatcher->
dispatch
(
new
PluginPreDeactivateEvent
(
$plugin
,
$deactivateContext
)
)
;
try
{
return
$context
;
}
/** * @throws Exception * * @return DeactivateContext */
public
function
deactivatePlugin
(
Plugin
$plugin
)
{
$context
=
new
DeactivateContext
(
$plugin
,
$this
->release->
getVersion
(
)
,
$plugin
->
getVersion
(
)
)
;
if
(
!
$plugin
->
getActive
(
)
)
{
return
$context
;
}
if
(
!
$plugin
->
isLegacyPlugin
(
)
)
{
return
$this
->pluginInstaller->
deactivatePlugin
(
$plugin
)
;
}
$result
=
$this
->legacyPluginInstaller->
deactivatePlugin
(
$plugin
)
;
$this
->
applyLegacyResultToContext
(
$result
,
$context
)
;
$collection
=
new
MigrationCollection
(
new
MigrationSource
(
'asd',
[
]
)
,
new
MigrationRuntime
(
new
NullConnection
(
)
,
new
NullLogger
(
)
)
,
new
NullConnection
(
)
)
;
return
[
[
new
PluginPostInstallEvent
(
$plugin
,
new
InstallContext
(
$rulePlugin
,
$context
, '', '',
$collection
)
)
]
,
[
new
PluginPostActivateEvent
(
$plugin
,
new
ActivateContext
(
$rulePlugin
,
$context
, '', '',
$collection
)
)
]
,
[
new
PluginPostUpdateEvent
(
$plugin
,
new
UpdateContext
(
$rulePlugin
,
$context
, '', '',
$collection
, ''
)
)
]
,
[
new
PluginPostDeactivateEvent
(
$plugin
,
new
DeactivateContext
(
$rulePlugin
,
$context
, '', '',
$collection
)
)
]
,
[
new
PluginPostUninstallEvent
(
$plugin
,
new
UninstallContext
(
$rulePlugin
,
$context
, '', '',
$collection
, true
)
)
]
,
]
;
}
}
/** * @internal */
#[Package('business-ops')]
class
RulePlugin
extends
Plugin
{
}
return
$context
;
}
/** * @throws Exception * @throws \Doctrine\ORM\OptimisticLockException * * @return DeactivateContext */
public
function
deactivatePlugin
(
Plugin
$plugin
)
{
$context
=
new
DeactivateContext
(
$plugin
,
$this
->release->
getVersion
(
)
,
$plugin
->
getVersion
(
)
)
;
$bootstrap
=
$this
->
getPluginByName
(
$plugin
->
getName
(
)
)
;
$this
->events->
notify
(
PluginEvent::PRE_DEACTIVATE,
new
PrePluginDeactivateEvent
(
$context
,
$bootstrap
)
)
;
$bootstrap
->
deactivate
(
$context
)
;
$plugin
->
setActive
(
false
)
;
$this
->events->
notify
(
PluginEvent::POST_DEACTIVATE,
new
PostPluginDeactivateEvent
(
$context
,
$bootstrap
)
)
;
$this
->em->
flush
(
$plugin
)
;