2014-05-14 13:24:20 +00:00
|
|
|
<?php namespace System\Models;
|
|
|
|
|
|
2014-08-05 07:41:59 +00:00
|
|
|
use Lang;
|
2014-05-14 13:24:20 +00:00
|
|
|
use Model;
|
2014-06-05 11:51:58 +00:00
|
|
|
use Config;
|
2014-05-14 13:24:20 +00:00
|
|
|
use System\Classes\PluginManager;
|
|
|
|
|
|
2014-10-03 08:00:21 +00:00
|
|
|
/**
|
|
|
|
|
* Stores information about current plugin versions.
|
|
|
|
|
*
|
|
|
|
|
* @package october\system
|
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
|
*/
|
2014-05-14 13:24:20 +00:00
|
|
|
class PluginVersion extends Model
|
|
|
|
|
{
|
|
|
|
|
public $table = 'system_plugin_versions';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array Guarded fields
|
|
|
|
|
*/
|
|
|
|
|
protected $guarded = ['*'];
|
|
|
|
|
|
2014-06-05 11:51:58 +00:00
|
|
|
/**
|
2017-03-30 23:03:02 +00:00
|
|
|
* @var bool Disable model timestamps.
|
2014-06-05 11:51:58 +00:00
|
|
|
*/
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
|
2017-03-30 23:03:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var array Cache store for version information
|
|
|
|
|
*/
|
2018-08-15 16:33:24 +00:00
|
|
|
protected static $versionCache;
|
2014-05-24 06:35:54 +00:00
|
|
|
|
2017-03-30 23:03:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var bool Plugin has been disabled by a missing dependency.
|
|
|
|
|
*/
|
2014-06-05 11:51:58 +00:00
|
|
|
public $disabledBySystem = false;
|
|
|
|
|
|
2017-03-30 23:03:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var bool Plugin has been disabled by the user or configuration.
|
|
|
|
|
*/
|
2014-06-05 11:51:58 +00:00
|
|
|
public $disabledByConfig = false;
|
|
|
|
|
|
2017-03-30 23:03:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var bool If true, plugin exists in the database but not the filesystem.
|
|
|
|
|
*/
|
2014-06-05 08:52:53 +00:00
|
|
|
public $orphaned = false;
|
|
|
|
|
|
2017-03-30 23:03:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var string Plugin name, sourced from plugin details
|
|
|
|
|
*/
|
|
|
|
|
public $name;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Plugin description, sourced from plugin details
|
|
|
|
|
*/
|
|
|
|
|
public $description;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Plugin author, sourced from plugin details
|
|
|
|
|
*/
|
|
|
|
|
public $author;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Plugin icon, sourced from plugin details
|
|
|
|
|
*/
|
|
|
|
|
public $icon;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Plugin homepage, sourced from plugin details
|
|
|
|
|
*/
|
|
|
|
|
public $homepage;
|
|
|
|
|
|
2015-07-13 21:42:21 +00:00
|
|
|
/**
|
|
|
|
|
* The accessors to append to the model's array form.
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $appends = ['slug'];
|
|
|
|
|
|
2014-05-14 13:24:20 +00: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);
|
|
|
|
|
|
|
|
|
|
if ($pluginObj) {
|
|
|
|
|
$pluginInfo = $pluginObj->pluginDetails();
|
|
|
|
|
foreach ($pluginInfo as $attribute => $info) {
|
2017-03-30 23:03:02 +00:00
|
|
|
if (property_exists($this, $attribute)) {
|
|
|
|
|
$this->{$attribute} = Lang::get($info);
|
|
|
|
|
}
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
2014-06-05 11:51:58 +00:00
|
|
|
|
2014-10-18 09:58:50 +00:00
|
|
|
if ($this->is_disabled) {
|
2014-06-05 11:51:58 +00:00
|
|
|
$manager->disablePlugin($this->code, true);
|
2014-11-01 01:00:45 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-06-05 11:51:58 +00:00
|
|
|
$manager->enablePlugin($this->code, true);
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|
2014-06-05 11:51:58 +00:00
|
|
|
|
|
|
|
|
$this->disabledBySystem = $pluginObj->disabled;
|
2014-06-08 01:20:18 +00:00
|
|
|
|
|
|
|
|
if (($configDisabled = Config::get('cms.disablePlugins')) && is_array($configDisabled)) {
|
|
|
|
|
$this->disabledByConfig = in_array($this->code, $configDisabled);
|
|
|
|
|
}
|
2014-11-01 01:00:45 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-06-05 08:52:53 +00:00
|
|
|
$this->name = $this->code;
|
2014-08-05 07:41:59 +00:00
|
|
|
$this->description = Lang::get('system::lang.plugins.unknown_plugin');
|
2014-06-05 08:52:53 +00:00
|
|
|
$this->orphaned = true;
|
|
|
|
|
}
|
2016-03-25 01:37:15 +00:00
|
|
|
}
|
2014-06-05 08:52:53 +00:00
|
|
|
|
2016-03-25 01:37:15 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if the plugin should be updated by the system.
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function getIsUpdatableAttribute()
|
|
|
|
|
{
|
|
|
|
|
return !$this->is_disabled && !$this->disabledBySystem && !$this->disabledByConfig;
|
2014-05-24 06:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-04 03:40:01 +00:00
|
|
|
/**
|
|
|
|
|
* Only include enabled plugins
|
|
|
|
|
* @param $query
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2015-07-21 10:46:35 +00:00
|
|
|
public function scopeApplyEnabled($query)
|
2015-02-04 03:40:01 +00:00
|
|
|
{
|
|
|
|
|
return $query->where('is_disabled', '!=', 1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-24 06:35:54 +00:00
|
|
|
/**
|
|
|
|
|
* 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 13:24:20 +00:00
|
|
|
|
2018-08-15 17:15:13 +00:00
|
|
|
return self::$versionCache[$pluginCode] ?? null;
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
2015-07-13 21:42:21 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides the slug attribute.
|
|
|
|
|
*/
|
|
|
|
|
public function getSlugAttribute()
|
|
|
|
|
{
|
|
|
|
|
return self::makeSlug($this->code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a slug for the plugin.
|
|
|
|
|
*/
|
|
|
|
|
public static function makeSlug($code)
|
|
|
|
|
{
|
|
|
|
|
return strtolower(str_replace('.', '-', $code));
|
|
|
|
|
}
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|