[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.17,1.18

[prev] [thread] [next] [lurker] [Date index for 2002/09/10]

From: muttley
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.17,1.18
Date: 17:57 on 10 Sep 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv25753/lib/Siesta/Storage

Modified Files:
	DBI.pm 
Log Message:
Add in some plugin config stuff.


Index: DBI.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- DBI.pm	9 Sep 2002 13:02:21 -0000	1.17
+++ DBI.pm	10 Sep 2002 16:57:36 -0000	1.18
@@ -370,4 +370,71 @@
     return $results[0]->{value};
 }
 
+
+# add plugin into the processing queue for a list
+# providing a number will insert at that position.
+# otherwise it will be added at the end. Position 
+# is indexed from 1. Returns 1 on success or undef
+# on failure.
+sub add_plugin_to_list
+{
+	my ($self, $list, $plugin, $position) = @_;
+
+	# make sure we've got a list object
+	unless (ref $list) {	
+		$list = Siesta->storage->load_list($list) || return undef;
+	} 
+
+	my @plugins = $list->plugins();
+
+	# if it looks hacky, then that's because it is
+	if (defined $position) {
+		push @plugins, ($plugin, splice (@plugins, $position));
+	} else {
+		push @plugins, $plugin;
+	}
+
+	return $self->set_plugins ($list, @plugins);
+
+}
+
+
+# sets the order of the plugins for a list
+sub set_plugins 
+{
+	my $self = shift;
+	my $list = shift;
+	my @plugins = @_;
+
+	# make sure we've got a list object
+	unless (ref $list) {
+                $list = Siesta->storage->load_list($list) || return undef;
+        }
+
+
+	# get rid of the exisiting list.	
+	my $sql = sprintf "DELETE from list_plugins where list_id=%s", 
+			$self->_dbh->quote($list->id());
+	
+	$self->_dbh->do($sql) 
+ 		or die $self->_dbh->errstr;	
+
+
+	my $a = 1;
+	foreach my $plugin (@plugins) {
+		my $isql = sprintf "INSERT INTO list_plugins 
+				    ( id, plugin_id , list_id )
+        		 	    VALUES (%d, %s, %s )",
+				        $a++, 
+					$self->_dbh->quote($plugin), 
+					$self->_dbh->quote($list->id());
+
+		$self->_dbh->do($isql)
+			or die $self->_dbh->errstr;
+	}
+
+	return 1;
+}
+
+
 1;



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52