winter/modules/system/models/PluginVersion.php

106 lines
2.6 KiB
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace System\Models;
2014-08-05 17:41:59 +10:00
use Lang;
2014-05-14 23:24:20 +10:00
use Model;
use Config;
2014-05-14 23:24:20 +10:00
use System\Classes\PluginManager;
2014-10-03 18:00:21 +10:00
/**
* Stores information about current plugin versions.
*
* @package october\system
* @author Alexey Bobkov, Samuel Georges
*/
2014-05-14 23:24:20 +10:00
class PluginVersion extends Model
{
use \October\Rain\Database\Traits\Purgeable;
2014-05-14 23:24:20 +10:00
public $table = 'system_plugin_versions';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array List of attribute names which should not be saved to the database.
*/
protected $purgeable = ['name', 'description', 'orphaned', 'author', 'icon', 'homepage'];
public $timestamps = false;
protected static $versionCache = null;
public $disabledBySystem = false;
public $disabledByConfig = false;
public $orphaned = false;
2014-05-14 23:24:20 +10:00
/**
* After the model is populated
*/
public function afterFetch()
{
/*
* Override the database columns with the plugin details
* found in the plugin registration file.
*/
$manager = PluginManager::instance();
$pluginObj = $manager->findByIdentifier($this->code);
2014-05-14 23:24:20 +10:00
if ($pluginObj) {
$pluginInfo = $pluginObj->pluginDetails();
foreach ($pluginInfo as $attribute => $info) {
2014-08-05 17:41:59 +10:00
$this->{$attribute} = Lang::get($info);
2014-05-14 23:24:20 +10:00
}
2014-10-18 11:58:50 +02:00
if ($this->is_disabled) {
$manager->disablePlugin($this->code, true);
}
else {
$manager->enablePlugin($this->code, true);
2014-10-18 11:58:50 +02:00
}
$this->disabledBySystem = $pluginObj->disabled;
2014-06-08 11:20:18 +10:00
if (($configDisabled = Config::get('cms.disablePlugins')) && is_array($configDisabled)) {
$this->disabledByConfig = in_array($this->code, $configDisabled);
}
}
else {
$this->name = $this->code;
2014-08-05 17:41:59 +10:00
$this->description = Lang::get('system::lang.plugins.unknown_plugin');
$this->orphaned = true;
}
}
/**
* Only include enabled plugins
* @param $query
* @return mixed
*/
2015-02-11 06:22:58 +10:00
public function scopeIsEnabled($query)
{
return $query->where('is_disabled', '!=', 1);
}
/**
* Returns the current version for a plugin
* @param string $pluginCode Plugin code. Eg: Acme.Blog
* @return string
*/
public static function getVersion($pluginCode)
{
if (self::$versionCache === null) {
self::$versionCache = self::lists('version', 'code');
}
2014-05-14 23:24:20 +10:00
return isset(self::$versionCache[$pluginCode])
? self::$versionCache[$pluginCode]
: null;
2014-05-14 23:24:20 +10:00
}
2014-10-18 11:58:50 +02:00
}