Filter non compatible plugins
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace Kanboard\Console;
|
namespace Kanboard\Console;
|
||||||
|
|
||||||
use Kanboard\Core\Plugin\Base as BasePlugin;
|
use Kanboard\Core\Plugin\Base as BasePlugin;
|
||||||
|
use Kanboard\Core\Plugin\Directory;
|
||||||
use Kanboard\Core\Plugin\Installer;
|
use Kanboard\Core\Plugin\Installer;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@@ -24,7 +25,7 @@ class PluginUpgradeCommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
$installer = new Installer($this->container);
|
$installer = new Installer($this->container);
|
||||||
$availablePlugins = $this->httpClient->getJson(PLUGIN_API_URL);
|
$availablePlugins = Directory::getInstance($this->container)->getAvailablePlugins();
|
||||||
|
|
||||||
foreach ($this->pluginLoader->getPlugins() as $installedPlugin) {
|
foreach ($this->pluginLoader->getPlugins() as $installedPlugin) {
|
||||||
$pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin);
|
$pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Kanboard\Controller;
|
namespace Kanboard\Controller;
|
||||||
|
|
||||||
|
use Kanboard\Core\Plugin\Directory;
|
||||||
use Kanboard\Core\Plugin\Installer;
|
use Kanboard\Core\Plugin\Installer;
|
||||||
use Kanboard\Core\Plugin\PluginInstallerException;
|
use Kanboard\Core\Plugin\PluginInstallerException;
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ class PluginController extends BaseController
|
|||||||
|
|
||||||
$this->response->html($this->helper->layout->plugin('plugin/directory', array(
|
$this->response->html($this->helper->layout->plugin('plugin/directory', array(
|
||||||
'installed_plugins' => $installedPlugins,
|
'installed_plugins' => $installedPlugins,
|
||||||
'available_plugins' => $this->httpClient->getJson(PLUGIN_API_URL),
|
'available_plugins' => Directory::getInstance($this->container)->getAvailablePlugins(),
|
||||||
'title' => t('Plugin Directory'),
|
'title' => t('Plugin Directory'),
|
||||||
'is_configured' => Installer::isConfigured(),
|
'is_configured' => Installer::isConfigured(),
|
||||||
)));
|
)));
|
||||||
|
|||||||
56
app/Core/Plugin/Directory.php
Normal file
56
app/Core/Plugin/Directory.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kanboard\Core\Plugin;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base as BaseCore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Directory
|
||||||
|
*
|
||||||
|
* @package Kanboard\Core\Plugin
|
||||||
|
* @author Frederic Guillot
|
||||||
|
*/
|
||||||
|
class Directory extends BaseCore
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get all plugins available
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $url
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAvailablePlugins($url = PLUGIN_API_URL)
|
||||||
|
{
|
||||||
|
$plugins = $this->httpClient->getJson($url);
|
||||||
|
$plugins = array_filter($plugins, array($this, 'isCompatible'));
|
||||||
|
$plugins = array_filter($plugins, array($this, 'isInstallable'));
|
||||||
|
return $plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter plugins
|
||||||
|
*
|
||||||
|
* @param array $plugin
|
||||||
|
* @param string $appVersion
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isCompatible(array $plugin, $appVersion = APP_VERSION)
|
||||||
|
{
|
||||||
|
if (strpos($appVersion, 'master') !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plugin['compatible_version'] === $appVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter plugins
|
||||||
|
*
|
||||||
|
* @param array $plugin
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isInstallable(array $plugin)
|
||||||
|
{
|
||||||
|
return $plugin['remote_install'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"symfony/stopwatch" : "~2.6"
|
"symfony/stopwatch" : "~2.6",
|
||||||
|
"phpunit/phpunit": "4.8.*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
972
composer.lock
generated
972
composer.lock
generated
File diff suppressed because it is too large
Load Diff
44
tests/units/Core/Plugin/DirectoryTest.php
Normal file
44
tests/units/Core/Plugin/DirectoryTest.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Kanboard\Core\Plugin\Directory;
|
||||||
|
|
||||||
|
require_once __DIR__.'/../../Base.php';
|
||||||
|
|
||||||
|
class DirectoryTest extends Base
|
||||||
|
{
|
||||||
|
public function testIsCompatible()
|
||||||
|
{
|
||||||
|
$pluginDirectory = new Directory($this->container);
|
||||||
|
$this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28'));
|
||||||
|
$this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28'));
|
||||||
|
$this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAvailablePlugins()
|
||||||
|
{
|
||||||
|
$plugins = array(
|
||||||
|
array(
|
||||||
|
'title' => 'Plugin A',
|
||||||
|
'compatible_version' => '1.0.30',
|
||||||
|
'remote_install' => true,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'title' => 'Plugin B',
|
||||||
|
'compatible_version' => '1.0.29',
|
||||||
|
'remote_install' => false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->container['httpClient']
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getJson')
|
||||||
|
->with('api_url')
|
||||||
|
->will($this->returnValue($plugins));
|
||||||
|
|
||||||
|
$pluginDirectory = new Directory($this->container);
|
||||||
|
$availablePlugins = $pluginDirectory->getAvailablePlugins('api_url');
|
||||||
|
|
||||||
|
$this->assertCount(1, $availablePlugins);
|
||||||
|
$this->assertEquals('Plugin A', $availablePlugins[0]['title']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user