[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.33,1.34

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

From: muttley
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.33,1.34
Date: 12:52 on 17 Oct 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv10970/lib/Siesta/Storage

Modified Files:
	DBI.pm 
Log Message:
Chnage to a new Preference based structure. This cleans up Storage 
and its derivatives. One less item on the todo list.


Index: DBI.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- DBI.pm	20 Sep 2002 20:32:06 -0000	1.33
+++ DBI.pm	17 Oct 2002 11:52:19 -0000	1.34
@@ -279,28 +279,77 @@
     return map { Siesta::List->new( $_->{list_id} ) } @results;
 }
 
-sub config {
-    my $self = shift;
 
-    my ( $namespace, $user_id, $list_id, $key, $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 true on sucess
+sub add_plugin_to_list {
+    my ( $self, $list, $plugin, $position ) = @_;
 
-    $user_id = UNIVERSAL::can( $user_id, 'id' ) ? $user_id->id : $user_id;
-    $list_id = UNIVERSAL::can( $list_id, 'id' ) ? $list_id->id : $list_id;
+    # make sure we've got a list object
+    unless ( ref $list ) {
+        $list = Siesta->storage->load_list($list)
+          or return;
+    }
 
-    # make suyre they're not undef
+    my @plugins = $list->plugins();
+
+    # if it looks hacky, then that's because it is
+    if ( defined $position ) {
+        push @plugins, ( $plugin, splice( @plugins, $position - 1 ) );
+    }
+    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)
+          or return;
+    }
+
+    # 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;
+}
+
+
+# sets a preference value 
+sub set_preference
+{
+    my ($self, $namespace, $user_id, $list_id, $key, $value ) = @_;
+
+    # make sure they're not undef
     $user_id ||= '';
     $list_id ||= '';
 
-    # if we haven't been passed a value then fetch and return it
-    return $self->get_config( $namespace, $user_id, $list_id, $key )
-      unless defined $value;
-
-    # otherwise we need to check to see if it's been defined 
-    # explicitly for this particular tuple and update or insert
-    # appropriately.
 
-    my $return =
-      $self->get_config_explicitly( $namespace, $user_id, $list_id, $key );
 
     $self->_update_or_insert(
                               table => 'config',
@@ -308,63 +357,25 @@
                                          namespace => $namespace,
                                          user_id   => $user_id,
                                          list_id   => $list_id,
-                                         key       => $key
+                                         key	   => $key
                               },
                               row => {
                                        namespace => $namespace,
                                        user_id   => $user_id,
                                        list_id   => $list_id,
-                                       key       => $key,
+                                       key	 => $key,
                                        value     => $value
                               },
                               );
-}
-
-# work out the first valid config value
-# the preferred order is
-#
-#         per user, per list
-#                 |
-#              per user
-#                 |
-#              per list
-#                 |
-#              default
-
-sub get_config {
-    my ( $self, $namespace, $user_id, $list_id, $key ) = @_;
-
-    $user_id ||= '';
-    $list_id ||= '';
 
-    unless ( $user_id eq '' || $list_id eq '' ) {
-        my $return =
-          $self->get_config_explicitly( $namespace, $user_id, $list_id, $key );
-        return $return
-          if defined $return;
-    }
+}
 
-    unless ( $user_id eq '' ) {
-        my $return =
-          $self->get_config_explicitly( $namespace, $user_id, '', $key );
-        return $return
-          if defined $return;
-    }
 
-    unless ( $list_id eq '' ) {
-        my $return =
-          $self->get_config_explicitly( $namespace, '', $list_id, $key );
-        return $return
-          if defined $return;
-    }
 
-    return $self->get_config_explicitly( $namespace, '', '', $key );
-}
+sub get_preference
+{
+    my ($self,  $namespace, $user_id, $list_id, $key) = @_;
 
-# explicitly look up a config value for a given
-# namespace, user, list, key tuple.
-sub get_config_explicitly {
-    my ( $self, $namespace, $user_id, $list_id, $key ) = @_;
 
     # just to be sure
     $user_id ||= '';
@@ -384,11 +395,12 @@
                                     );
 
     return $results[0]->{value};
-}
 
-sub delete_config {
-    my ( $self, $namespace, $user_id, $list_id, $key ) = @_;
+}
 
+sub delete_preference
+{
+    my ($self,  $namespace, $user_id, $list_id, $key) = @_;
     # just to be sure
     $user_id ||= '';
     $list_id ||= '';
@@ -406,66 +418,10 @@
 
     my @results = $self->_delete(%args);
 
-}
-
-# 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 true on sucess
-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)
-          or return;
-    }
-
-    my @plugins = $list->plugins();
 
-    # if it looks hacky, then that's because it is
-    if ( defined $position ) {
-        push @plugins, ( $plugin, splice( @plugins, $position - 1 ) );
-    }
-    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)
-          or return;
-    }
-
-    # 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