Skip to content

Commit

Permalink
plugins: don't fail on missing plugin files
Browse files Browse the repository at this point in the history
When the plugin is already registered in the database but not installed anymore
on the filesystem, don't error out, but silently keep the plugin hidden from
the list of installed & available plugins.

When the files are back on the filesystem, they will show up and work again as
they were.
  • Loading branch information
tenzap committed Oct 30, 2024
1 parent a1d3716 commit 27ac8b8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
13 changes: 11 additions & 2 deletions application/controllers/Pluginss.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function __construct()
function index($type = 'installed')
{
$this->load->helper('form');
$plugins_lib = $this->plugins_lib_kalkun;
$data['main'] = 'main/plugin/index';
$data['title'] = 'Plugins';
$data['plugins'] = array();
Expand All @@ -65,7 +66,11 @@ function index($type = 'installed')
$data['title'] .= ' - '.tr_raw('Installed', 'Plural');
foreach ($this->Plugins_kalkun_model->get_plugins() as $key => $plugin)
{
if (intval($plugin->status) === 1)
if ($plugin->status & $plugins_lib::P_STATUS_MISSING)
{
continue;
}
if ($plugin->status & $plugins_lib::P_STATUS_ENABLED)
{
$data['plugins'][$key] = $plugin;
$data['plugins'][$key]->controller_has_index = $this->_plugin_controller_has_index($plugin->system_name);
Expand All @@ -77,7 +82,11 @@ function index($type = 'installed')
$data['title'] .= ' - '.tr_raw('Available', 'Plural');
foreach ($this->Plugins_kalkun_model->get_plugins() as $key => $plugin)
{
if (intval($plugin->status) !== 1)
if ($plugin->status & $plugins_lib::P_STATUS_MISSING)
{
continue;
}
if (! ($plugin->status & $plugins_lib::P_STATUS_ENABLED))
{
$data['plugins'][$key] = $plugin;
}
Expand Down
70 changes: 67 additions & 3 deletions application/libraries/Plugins_lib_kalkun.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Plugins_lib_kalkun extends Plugins_lib {

// ------------------------------------------------------------------------

const P_STATUS_ENABLED = 1; // Bitflag: 0: disabled 1: enabled
const P_STATUS_MISSING = 2; // Bitflag: 0: files present 1: files missing

/**
* Plugin Constructor
*
Expand Down Expand Up @@ -196,8 +199,8 @@ public function insert_plugin_headers($plugin)
* Look in the plugin directory for any folders that do not have an associated entry
* in the plugins table
*
* Upstream bug here it that it doesn't check only for folders, but also for files.
* So we have to skip the loop for files.
* Upstream bug here is that it doesn't check only for folders, but also for files.
* So we have to skip the files in the loop.
*
* @access public
* @since 0.1.0
Expand Down Expand Up @@ -359,5 +362,66 @@ protected function plugin_class_name($system_name = '') {
return ucfirst($system_name).'_plugin';
}

/**
* Get Enabled Plugins
*
* Override upstream's method so that we can support an additional status
* being whether the files for the plugin are present on the filesystem.
*
* Retrieve the enabled plugins from the database and load them into the enabled_plugins
* array. This does not initiate the plugins, thats done in a different method
*
* @access private
*/
protected function get_plugins()
{
// Fetch all plugins
if ( ! $plugins = static::$PM->get_plugins())
{
return FALSE;
}

// Load the plugins
foreach ($plugins as $p)
{
// Update plugin status to current real state
$this->update_plugin_presence_status($p);

}
if ( ! isset(static::$plugins[$p->system_name]))
{
// If the pluging file is not missing, add it to the list of plugins.
if ( ! ($p->status & self::P_STATUS_MISSING))
{
$this->_debug("Adding plugin {$p->system_name}");

static::$plugins[$p->system_name] = array(
'data' => $p->data
);
// If its enabled, add it to $enabled_plugins referencing the plugin in $plugins
if ($p->status & self::P_STATUS_ENABLED)
{
$this->_debug("Enabling plugin {$p->system_name}");

static::$enabled_plugins[$p->system_name] = &static::$plugins[$p->system_name];
}
}
}
}
}

protected function update_plugin_presence_status($p)
{
$plugin_path = static::$plugin_path . "{$p->system_name}/{$p->system_name}.php";
if (file_exists($plugin_path))
{
// set plugin as present on the filesystem
$p->status = $p->status & ~self::P_STATUS_MISSING;
}
else
{
// set plugin as missing on the filesystem
$p->status = $p->status | self::P_STATUS_MISSING;
}
static::$PM->set_status($p->system_name, $p->status);
}
}

0 comments on commit 27ac8b8

Please sign in to comment.