Skip to content

Commit

Permalink
Switch to using Rose for plugin scanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
racke committed Nov 24, 2010
1 parent ea9aec0 commit 8b085fd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
1 change: 1 addition & 0 deletions database/mysql/plugins.sql
@@ -1,6 +1,7 @@
CREATE TABLE plugins (
name varchar(32) not null default '',
label varchar(255) not null default '',
directory varchar(255) not null default '',
version varchar(16) not null default '',
active boolean,
PRIMARY KEY(name)
Expand Down
1 change: 1 addition & 0 deletions database/pgsql/plugins.sql
@@ -1,6 +1,7 @@
CREATE TABLE plugins (
name varchar(32) not null default '',
label varchar(255) not null default '',
directory varchar(255) not null default '',
version varchar(16) not null default '',
active boolean,
PRIMARY KEY(name)
Expand Down
14 changes: 7 additions & 7 deletions lib/WellWell/Core.pm
Expand Up @@ -60,26 +60,26 @@ sub plugins_from_var {
sub plugin_scan_sub {
my ($dbif, $plref, $active);

$dbif = WellWell::Data::easy_handle();
$plref = WellWell::Plugin::plugin_scan($dbif, 'plugins', 'local/plugins');
WellWell::Data::make_classes($Vend::Config::C->{CatalogName});

$plref = WellWell::Plugin::plugin_scan('plugins', 'local/plugins');

# first pass for enabling plugins in the database from PLUGINS variable
for my $plugin (plugins_from_var()) {
if (exists $plref->{$plugin}) {
if ($plref->{$plugin}->{active} eq 0) {
if ($plref->{$plugin}->active eq 0) {
Vend::Config::config_error("Plugin $plugin used in PLUGINS variable is explicitly disabled in plugins table.");
return;
}
elsif (! defined($plref->{$plugin}->{active})) {
elsif (! defined($plref->{$plugin}->active)) {
Vend::Config::config_warn("Enabling plugin $plugin in plugins table.");
plugin_enable($dbif, $plugin);
plugin_enable($plref->{$plugin});
}
}
}

for my $plugin (keys %$plref) {
if ($plref->{$plugin}->{active}) {
if ($plref->{$plugin}->active) {
# search path for components and pages
push(@{$Vend::Cfg->{TemplateDir}}, $plref->{$plugin}->{directory},
"$plref->{$plugin}->{directory}/pages");
Expand Down
26 changes: 19 additions & 7 deletions lib/WellWell/Data.pm
Expand Up @@ -22,8 +22,9 @@ package WellWell::Data;
use strict;
use warnings;

use Rose::DB::Object::Loader;

use Vend::Data;
use DBIx::Easy;

sub prepare_database {
my ($userdb_ref, $users_table, %dbif);
Expand Down Expand Up @@ -72,15 +73,26 @@ sub prepare_database {
return;
}

sub easy_handle {
my ($dbh, $dbif);
sub make_classes {
my ($catalog) = @_;
my (%args, $loader, @classes, @sqlparms);

@sqlparms = split(/\s+/, $::Variable->{SQLDSN});

$dbh = database_exists_ref('products')->dbh();
if (@sqlparms == 1) {
push (@sqlparms, $::Variable->{SQLUSER}, $::Variable->{SQLPASS});
}
else {
($args{db_dsn}, $args{db_username}, $args{db_password}) = @sqlparms;
}

$dbif = new DBIx::Easy ($dbh->{Driver}->{Name}, $dbh->{Name});
$dbif->{CONN} = $dbh->clone;
$args{class_prefix} = 'Catalog::Database::' . ucfirst($catalog);
$args{include_tables} = ['plugins'];
$loader = new Rose::DB::Object::Loader (%args);

@classes = $loader->make_classes();

return $dbif;
return @classes;
}

1;
37 changes: 23 additions & 14 deletions lib/WellWell/Plugin.pm
Expand Up @@ -29,17 +29,24 @@ our @ISA = qw(Exporter);
our @EXPORT_OK = qw/plugin_scan plugin_enable/;

sub plugin_scan {
my ($dbif, @dirs) = @_;
my (@plugins, $dirname, $infofile, $plugininfo, $dbref);
my (@dirs) = @_;
my (@plugins, $dirname, $infofile, $plugininfo, $dbref, $catname);
my ($plugin, $plugin_dir, $pluginrec);
my ($sth, $href);
my ($results, $sth, $href);
my (%plugins);

# read current plugins from database
$sth = $dbif->process('select * from plugins');
my $classname = 'Catalog::Database::' . ucfirst($Vend::Cfg->{CatalogName}) . '::Plugin::Manager';
eval "\$results = $classname->get_plugins();";

while ($href = $sth->fetchrow_hashref()) {
$plugins{$href->{name}} = $href;
if ($@) {
die "$@";
}

$classname = 'Catalog::Database::' . ucfirst($Vend::Cfg->{CatalogName}) . '::Plugin';

for $href (@$results) {
$plugins{$href->name} = $href;
}

for my $dir (@dirs) {
Expand All @@ -57,17 +64,17 @@ sub plugin_scan {

if (exists $plugins{$dirname}) {
# existing plugin
$plugins{$dirname}->{directory} = $plugin_dir;
$plugins{$dirname}->directory($plugin_dir);
}
else {
# new plugin
$pluginrec = {name => $dirname,
$pluginrec = $classname->new (name => $dirname,
directory => "plugins/$dirname",
version => $plugininfo->{version},
label => $plugininfo->{label} || $dirname,
active => undef};
active => undef);

$dbif->insert('plugins', %$pluginrec);
$pluginrec->save();

$pluginrec->{directory} = $plugin_dir;
$plugins{$dirname} = $pluginrec;
Expand All @@ -91,15 +98,17 @@ sub plugin_scan {
}

sub plugin_enable {
my ($dbif, $plugin) = @_;
my ($plugin) = @_;

$dbif->update('plugins', 'name = ' . $dbif->quote($plugin), active => 1);
$plugin->active(1);
$plugin->save();
}

sub plugin_disable {
my ($dbif, $plugin) = @_;
my ($plugin) = @_;

$dbif->update('plugins', 'name = ' . $dbif->quote($plugin), active => 0);
$plugin->active(0);
$plugin->save();
}

sub plugin_get_info {
Expand Down

0 comments on commit 8b085fd

Please sign in to comment.