Merge branch 'master' of github.com:octobercms/october

This commit is contained in:
alekseybobkov 2014-05-21 17:52:15 +11:00
commit 0577054493
6 changed files with 179 additions and 5 deletions

View File

@ -1,4 +1,6 @@
* **Build 86** (2014-05-21)
* **Build 87** (2014-05-21)
- Plugins can now be disabled manually by config (see config cms.disablePlugins).
- Plugins with missing dependancies are disabled by the system.
- Fixes an issue where paid plugins could not be downloaded.
* **Build 84** (2014-05-20)

View File

@ -23,6 +23,16 @@ return array(
*/
'loadModules' => ['System', 'Backend', 'Cms'],
/*
|--------------------------------------------------------------------------
| Sepcific plugins to disable
|--------------------------------------------------------------------------
|
| Specify plugin codes which will always be disabled in the application.
|
*/
'disablePlugins' => [],
/*
|--------------------------------------------------------------------------
| Back-end URI prefix

View File

@ -10,6 +10,15 @@ use Illuminate\Support\ServiceProvider as ServiceProviderBase;
*/
abstract class PluginBase extends ServiceProviderBase
{
/**
* @var array Plugin dependencies
*/
public $require = [];
/**
* @var boolean Determine if this plugin should be loaded (false) or not (true).
*/
public $disabled = false;
/**
* Returns information about this plugin, including plugin name and developer name.

View File

@ -45,13 +45,26 @@ class PluginManager
*/
protected $booted = false;
/**
* @var string Path to the disarm file.
*/
protected $metaPath;
/**
* @var array Collection of disabled plugins
*/
protected $disabledPlugins = [];
/**
* Initializes the plugin manager
*/
protected function init()
{
$this->app = App::make('app');
$this->metaPath = Config::get('app.manifest');
$this->loadDisabled();
$this->loadPlugins();
$this->loadDependencies();
}
/**
@ -78,6 +91,13 @@ class PluginManager
$classObj = new $pluginClassName($this->app);
$classId = $this->getIdentifier($classObj);
/*
* Check for disabled plugins
*/
if ($this->isDisabled($classId))
$classObj->disabled = true;
$this->plugins[$classId] = $classObj;
$this->pathMap[$classId] = $classPath;
}
@ -85,6 +105,34 @@ class PluginManager
return $this->plugins;
}
/**
* Cross checks all plugins and their dependancies, if not met plugins
* are disabled and vice versa.
*/
protected function loadDependencies()
{
foreach ($this->plugins as $id => $plugin) {
if (!isset($plugin->require) || !$plugin->require)
continue;
$required = is_array($plugin->require) ? $plugin->require : [$plugin->require];
$disable = false;
foreach ($required as $require) {
if (!$this->hasPlugin($require))
$disable = true;
elseif (($pluginObj = $this->findByIdentifier($require)) && $pluginObj->disabled)
$disable = true;
}
if ($disable)
$this->disablePlugin($id);
else
$this->enablePlugin($id);
}
}
/**
* Runs the register() method on all plugins. Can only be called once.
*/
@ -94,6 +142,9 @@ class PluginManager
return;
foreach ($this->plugins as $pluginId => $plugin) {
if ($plugin->disabled)
continue;
$plugin->register();
$pluginPath = $this->getPluginPath($plugin);
$pluginNamespace = strtolower($pluginId);
@ -145,8 +196,12 @@ class PluginManager
if ($this->booted)
return;
foreach ($this->plugins as $plugin)
foreach ($this->plugins as $plugin) {
if ($plugin->disabled)
continue;
$plugin->boot();
}
$this->booted = true;
}
@ -178,7 +233,7 @@ class PluginManager
*/
public function getPlugins()
{
return $this->plugins;
return array_diff_key($this->plugins, $this->disabledPlugins);
}
/**
@ -272,4 +327,95 @@ class PluginManager
$namespace = implode('.', $slice);
return $namespace;
}
//
// Disability
//
/**
* Loads all disables plugins from the meta file.
*/
protected function loadDisabled()
{
$path = $this->metaPath.'/disabled.json';
if (($configDisabled = Config::get('cms.disablePlugins')) && is_array($configDisabled)) {
foreach ($configDisabled as $disabled)
$this->disabledPlugins[$disabled] = true;
}
if (File::exists($path)) {
$disabled = json_decode(File::get($path), true);
$this->disabledPlugins = array_merge($this->disabledPlugins, $disabled);
}
else {
$this->writeDisabled();
}
}
/**
* Determines if a plugin is disabled by looking at the meta information
* or the application configuration.
* @return boolean
*/
public function isDisabled($id)
{
$code = $this->getIdentifier($id);
if (array_key_exists($code, $this->disabledPlugins))
return true;
}
/**
* Write the disabled plugins to a meta file.
*/
protected function writeDisabled()
{
$path = $this->metaPath.'/disabled.json';
File::put($path, json_encode($this->disabledPlugins));
}
/**
* Disables a single plugin in the system.
* @param string $id Plugin code/namespace
* @param bool $user Set to true if disabled by the user
*/
public function disablePlugin($id, $isUser = false)
{
$code = $this->getIdentifier($id);
if (array_key_exists($code, $this->disabledPlugins))
return false;
$this->disabledPlugins[$code] = $isUser;
$this->writeDisabled();
if ($pluginObj = $this->findByIdentifier($code))
$pluginObj->disabled = true;
return true;
}
/**
* Enables a single plugin in the system.
* @param string $id Plugin code/namespace
* @param bool $user Set to true if enabled by the user
*/
public function enablePlugin($id, $isUser = false)
{
$code = $this->getIdentifier($id);
if (!array_key_exists($code, $this->disabledPlugins))
return false;
// Prevent system from enabling plugins disabled by the user
if (!$isUser && $this->disabledPlugins[$code] === true)
return false;
unset($this->disabledPlugins[$code]);
$this->writeDisabled();
if ($pluginObj = $this->findByIdentifier($code))
$pluginObj->disabled = false;
return true;
}
}

View File

@ -37,6 +37,11 @@ class CacheClear extends ClearCommand
$this->info('Twig cache cleared!');
}
/*
* Meta
*/
$this->files->delete($this->laravel['config']['app.manifest'].'/disabled.json');
parent::fire();
}

View File

@ -25,8 +25,10 @@
<script type="text/template" id="executeFailed">
<div class="modal-body">
<div class="callout callout-danger">
<h4><?= e(trans('system::lang.updates.update_failed_label')) ?></h4>
<p>{{ reason }}</p>
<div class="header">
<h3><?= e(trans('system::lang.updates.update_failed_label')) ?></h3>
<p>{{ reason }}</p>
</div>
</div>
</div>
<div class="modal-footer">