Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rune Laenen committed Feb 9, 2019
0 parents commit 00064de
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Commands/PluginReset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace RunePluginReset\Commands;

use RunePluginReset\Services\PluginResetService;
use Shopware\Commands\ShopwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class PluginReset
* @package RunePluginReset\Commands
*/
class PluginReset extends ShopwareCommand
{
/**
* @var PluginResetService
*/
private $pluginResetService;

/**
* PluginReset constructor.
*/
public function __construct(
PluginResetService $pluginResetService
){

parent::__construct();
$this->pluginResetService = $pluginResetService;
}


/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('rune:pluginreset:resetplugins')
->setDescription('Disabled removed plugins automatically')
->setHelp(<<<EOF
The <info>%command.name%</info> implements a command.
EOF
);
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("*** Checking for removed but enabled plugins");

$disabled = $this->pluginResetService->resetPlugins();

if(count($disabled) == 0) {
$output->writeln("*** No plugins disabled");
return;
}
$output->writeln("*** " . count($disabled) . " plugin(s) disabled: " . implode(', ', $disabled));
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Rune Laenen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# RunePluginReset

[![](https://img.shields.io/packagist/dt/runelaenen/shopware-plugin-reset.svg)](https://packagist.org/packages/runelaenen/shopware-plugin-reset)

Automatically disable plugins if files are deleted

### Features

* No more errors due to switches git branches

## Requirements

- Shopware 5.5.4

# Installation

## Install with composer
* Change to your root Installation of shopware
* Run command `composer require runelaenen/shopware-plugin-reset` and install and active plugin with Plugin Manager

## Zip Installation package for the Shopware Plugin Manager
* Download the [latest plugin version](https://github.com/runelaenen/RunePluginReset/releases/latest/) (e.g. `RunePluginReset-1.0.0.zip`)
* Upload and install plugin using Plugin Manager

## Git Version
* Checkout Plugin in `/custom/plugins/RunePluginReset`
* Install the Plugin with the Plugin Manager

## Contributing

Feel free to fork and send pull requests!

## Licence

This project uses the [MIT License](LICENCE.md).
21 changes: 21 additions & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="rune_plugin_reset.services.plugin_reset_service" class="RunePluginReset\Services\PluginResetService">
<argument type="service" id="db"/>
</service>

<service id="rune_plugin_reset.commands.plugin_reset" class="RunePluginReset\Commands\PluginReset">
<argument type="service" id="rune_plugin_reset.services.plugin_reset_service"/>
<tag name="console.command" />
</service>

<service id="rune_plugin_reset.subscriber.clear_cache_subscriber" class="RunePluginReset\Subscriber\ClearCacheSubscriber">
<argument type="service" id="rune_plugin_reset.services.plugin_reset_service"/>
<tag name="shopware.event_subscriber"/>
</service>
</services>
</container>
25 changes: 25 additions & 0 deletions RunePluginReset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace RunePluginReset;

use Shopware\Components\Plugin;
use Shopware\Components\Console\Application;
use RunePluginReset\Commands\PluginReset;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Shopware-Plugin RunePluginReset.
*/
class RunePluginReset extends Plugin
{

/**
* @param ContainerBuilder $container
*/
public function build(ContainerBuilder $container)
{
$container->setParameter('rune_plugin_reset.plugin_dir', $this->getPath());
parent::build($container);
}

}
55 changes: 55 additions & 0 deletions Services/PluginResetService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace RunePluginReset\Services;

use Enlight_Components_Db_Adapter_Pdo_Mysql;

/**
* Class PluginResetService
* @package RunePluginReset\Services
*/
class PluginResetService
{
/**
* @var Enlight_Components_Db_Adapter_Pdo_Mysql
*/
private $db;

/**
* PluginResetService constructor.
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $db
*/
public function __construct(
Enlight_Components_Db_Adapter_Pdo_Mysql $db
){
$this->db = $db;
}

/**
* @return array
* @throws \Zend_Db_Adapter_Exception
* @throws \Zend_Db_Statement_Exception
*/
public function resetPlugins()
{
$query = $this->db->query("SELECT `id`, `name` FROM s_core_plugins WHERE active = 1 AND capability_secure_uninstall = 1");
$dbPlugins = $query->fetchAll();

/** @var Kernel $kernel */
$kernel = Shopware()->Container()->get('kernel');
$plugins = $kernel->getPlugins();

$disabled = [];

foreach ($dbPlugins as $dbPlugin) {
if(!isset($plugins[$dbPlugin['name']])) {
$this->db->query("UPDATE s_core_plugins SET active = 0 WHERE id = :pluginId", ['pluginId' => $dbPlugin['id']]);

$disabled[] = $dbPlugin['name'];
}
}

return $disabled;
}

}
52 changes: 52 additions & 0 deletions Subscriber/ClearCacheSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace RunePluginReset\Subscriber;

use Enlight\Event\SubscriberInterface;
use RunePluginReset\Services\PluginResetService;

/**
* Class ClearCacheSubscriber
* @package RunePluginReset\Subscriber
*/
class ClearCacheSubscriber implements SubscriberInterface
{
/**
* @var PluginResetService
*/
private $pluginResetService;

/**
* ClearCacheSubscriber constructor.
* @param PluginResetService $pluginResetService
*/
public function __construct(
PluginResetService $pluginResetService
) {

$this->pluginResetService = $pluginResetService;
}

/**
* @return array
*/
public static function getSubscribedEvents()
{
return array(
'Enlight_Bootstrap_AfterInitResource_shopware.commands.cache_clear_command' => 'onClearCache'
);
}

/**
* @param \Enlight_Event_EventArgs $args
* @throws \Zend_Db_Adapter_Exception
* @throws \Zend_Db_Statement_Exception
*/
public function onClearCache(\Enlight_Event_EventArgs $args)
{
$disabled = $this->pluginResetService->resetPlugins();
if(count($disabled)) {
printf("[RunePluginReset] %1 plugins disabled\n", count($disabled));
}
}
}
Binary file added plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../engine/Shopware/Components/Plugin/schema/plugin.xsd">
<label lang="en">RunePluginReset</label>
<version>0.0.1</version>
<copyright>(c) by Rune Laenen</copyright>
<license>proprietary</license>
<link>https://github.com/runelaenen/RunePluginReset</link>
<author>Rune Laenen</author>

<compatibility minVersion="5.5.4" />

</plugin>

0 comments on commit 00064de

Please sign in to comment.