<?php declare(strict_types=1);
namespace LoyxxSW6SeoFaqManager;
use Doctrine\DBAL\Connection;
use LoyxxSW6SeoFaqManager\Installer\LoyPluginInstaller;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class LoyxxSW6SeoFaqManager extends Plugin
{
const PRIVILEGES = [
'category' => [
'viewer' => ['faq_category:read', 'category:read'],
'creator' => ['faq_category:write', 'category:read'],
'editor' => ['faq_category:update', 'category:read'],
'deleter' => ['faq_category:delete', 'category:read']
],
'product' => [
'viewer' => ['faq_product:read', 'product:read'],
'creator' => ['faq_product:write', 'product:read'],
'editor' => ['faq_product:update', 'product:read'],
'deleter' => ['faq_product:delete', 'product:read']
],
'set' => [
'viewer' => ['faq_set:read'],
'creator' => ['faq_set:write'],
'editor' => ['faq_set:update'],
'deleter' => ['faq_set:delete']
]
];
const ENABLE_SEO_PRIVILEGE_TO_ROLES = false;
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if($uninstallContext->keepUserData()){
return;
}
(new LoyPluginInstaller($this->container))->uninstall($uninstallContext);
$this->removeMigrations();
}
public function activate(ActivateContext $activateContext): void
{
if (method_exists($this, 'addPrivileges') && static::ENABLE_SEO_PRIVILEGE_TO_ROLES) {
foreach (['viewer', 'creator', 'editor', 'deleter'] as $role) {
$this->addPrivileges("seoFaq.editor", static::PRIVILEGES['category'][$role]);
$this->addPrivileges("seoFaq.editor", static::PRIVILEGES['product'][$role]);
}
}
(new LoyPluginInstaller($this->container))->activate($activateContext);
parent::activate($activateContext);
}
public function deactivate(DeactivateContext $deactivateContext): void
{
if (method_exists($this, 'removePrivileges') && static::ENABLE_SEO_PRIVILEGE_TO_ROLES) {
$this->removePrivileges([
'faq_category:read',
'faq_category:write',
'faq_category:update',
'faq_category:delete',
'faq_product:read',
'faq_product:write',
'faq_product:update',
'faq_product:delete'
]);
}
(new LoyPluginInstaller($this->container))->deactivate($deactivateContext);
parent::deactivate($deactivateContext);
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
(new LoyPluginInstaller($this->container))->update($updateContext);
}
public function install(InstallContext $installContext): void
{
parent::install($installContext);
(new LoyPluginInstaller($this->container))->install($installContext);
}
public function postUpdate(UpdateContext $updateContext): void
{
parent::postUpdate($updateContext);
(new LoyPluginInstaller($this->container))->postUpdate($updateContext);
}
}