Removing plugins can now be purged from the db, orphaned plugins are visible, don't concat single list relations, add more events to Cms controller.

This commit is contained in:
Sam Georges 2014-06-05 18:52:53 +10:00
parent 40507f12f0
commit f44b203e44
6 changed files with 69 additions and 8 deletions

View File

@ -276,15 +276,20 @@ class Lists extends WidgetBase
$alias = Db::getQueryGrammar()->wrap($column->columnName);
$table = $this->model->makeRelation($column->relation)->getTable();
$relationType = $this->model->getRelationType($column->relation);
$sqlSelect = $this->parseTableName($column->sqlSelect, $table);
$selects[] = DbDongle::raw("group_concat(" . $sqlSelect . " separator ', ') as ". $alias);
if (in_array($relationType, ['hasMany', 'belongsToMany', 'morphToMany', 'morphedByMany', 'morphMany', 'attachMany', 'hasManyThrough']))
$selects[] = DbDongle::raw("group_concat(" . $sqlSelect . " separator ', ') as ". $alias);
else
$selects[] = DbDongle::raw($sqlSelect . ' as '. $alias);
$joins[] = $column->relation;
$tables[$column->relation] = $table;
}
if ($joins)
$query->joinWith(array_unique($joins));
$query->joinWith(array_unique($joins), false);
/*
* Custom select queries

View File

@ -31,6 +31,7 @@ use Illuminate\Http\RedirectResponse;
class Controller extends BaseController
{
use \System\Traits\AssetMaker;
use \October\Rain\Support\Traits\Emitter;
/**
* @var \Cms\Classes\Theme A reference to the CMS theme processed by the controller.
@ -111,7 +112,10 @@ class Controller extends BaseController
/*
* Extensibility
*/
if ($event = Event::fire('cms.beforeDisplay', [$this, $url, $page], true))
if ($event = Event::fire('cms.page.beforeDisplay', [$this, $url, $page], true))
return $event;
if ($event = $this->fireEvent('page.beforeDisplay', [$this, $url, $page], true))
return $event;
/*
@ -191,7 +195,10 @@ class Controller extends BaseController
/*
* Extensibility
*/
if ($event = Event::fire('cms.afterDisplay', [$this, $url, $page], true))
if ($event = Event::fire('cms.page.display', [$this, $url, $page], true))
return $event;
if ($event = $this->fireEvent('page.display', [$this, $url, $page], true))
return $event;
return $result;
@ -416,6 +423,15 @@ class Controller extends BaseController
*/
protected function execPageCycle()
{
/*
* Extensibility
*/
if ($event = Event::fire('cms.page.start', [$this], true))
return $event;
if ($event = $this->fireEvent('page.start', [$this], true))
return $event;
/*
* Run layout functions
*/
@ -449,6 +465,15 @@ class Controller extends BaseController
});
}
/*
* Extensibility
*/
if ($event = Event::fire('cms.page.end', [$this], true))
return $event;
if ($event = $this->fireEvent('page.end', [$this], true))
return $event;
return $response;
}

View File

@ -54,7 +54,7 @@ class SettingsModel extends ModelBehavior
*/
$this->model->bindEvent('model.afterFetch', [$this, 'afterModelFetch']);
$this->model->bindEvent('model.beforeSave', [$this, 'beforeModelSave']);
$this->model->bindEvent('model.afterSetAttribute', [$this, 'setModelAttribute']);
$this->model->bindEvent('model.setAttribute', [$this, 'setModelAttribute']);
/*
* Parse the config

View File

@ -392,13 +392,18 @@ class UpdateManager
* Remove the plugin database and version
*/
if (!($plugin = $this->pluginManager->findByIdentifier($name))) {
$this->note('<error>Unable to find:</error> ' . $name);
return;
if ($this->versionManager->purgePlugin($name)) {
$this->note('<info>Purged from database:</info> ' . $name);
return $this;
}
}
if ($this->versionManager->removePlugin($plugin))
if ($this->versionManager->removePlugin($plugin)) {
$this->note('<info>Rolled back:</info> ' . $name);
return $this;
}
$this->note('<error>Unable to find:</error> ' . $name);
return $this;
}

View File

@ -172,6 +172,24 @@ class VersionManager
return true;
}
/**
* Deletes all records from the version and history tables for a plugin.
* @param string $pluginCode Plugin code
* @return void
*/
public function purgePlugin($pluginCode)
{
$versions = Db::table('system_plugin_versions')->where('code', $pluginCode);
if ($countVersions = $versions->count())
$versions->delete();
$history = Db::table('system_plugin_history')->where('code', $pluginCode);
if ($countHistory = $history->count())
$history->delete();
return (($countHistory + $countVersions) > 0) ? true : false;
}
//
// File representation
//

View File

@ -15,6 +15,8 @@ class PluginVersion extends Model
protected static $versionCache = null;
public $orphaned = false;
/**
* After the model is populated
*/
@ -33,6 +35,12 @@ class PluginVersion extends Model
$this->{$attribute} = $info;
}
}
else {
$this->name = $this->code;
$this->description = 'Plugin has been removed from the file system.';
$this->orphaned = true;
}
}
/**