[wellwell-devel] [wellwell/zoom] Switch to using Rose for plugin scanning.
Stefan Hornburg
wellwell-devel at rt.icdevgroup.org
Wed Nov 24 13:25:53 UTC 2010
commit 8b085fde041a24b15ec5089845c11589f70ea956
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date: Wed Nov 24 14:25:13 2010 +0100
Switch to using Rose for plugin scanning.
database/mysql/plugins.sql | 1 +
database/pgsql/plugins.sql | 1 +
lib/WellWell/Core.pm | 14 +++++++-------
lib/WellWell/Data.pm | 26 +++++++++++++++++++-------
lib/WellWell/Plugin.pm | 37 +++++++++++++++++++++++--------------
5 files changed, 51 insertions(+), 28 deletions(-)
---
diff --git a/database/mysql/plugins.sql b/database/mysql/plugins.sql
index 1cbac17..4f3d6d8 100644
--- a/database/mysql/plugins.sql
+++ b/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)
diff --git a/database/pgsql/plugins.sql b/database/pgsql/plugins.sql
index 1cbac17..4f3d6d8 100644
--- a/database/pgsql/plugins.sql
+++ b/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)
diff --git a/lib/WellWell/Core.pm b/lib/WellWell/Core.pm
index 908e2e3..55b3a1c 100644
--- a/lib/WellWell/Core.pm
+++ b/lib/WellWell/Core.pm
@@ -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");
diff --git a/lib/WellWell/Data.pm b/lib/WellWell/Data.pm
index 7048981..2177ccd 100644
--- a/lib/WellWell/Data.pm
+++ b/lib/WellWell/Data.pm
@@ -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);
@@ -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;
diff --git a/lib/WellWell/Plugin.pm b/lib/WellWell/Plugin.pm
index 5c5e78e..5c618b1 100644
--- a/lib/WellWell/Plugin.pm
+++ b/lib/WellWell/Plugin.pm
@@ -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) {
@@ -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;
@@ -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 {
More information about the wellwell-devel
mailing list