From 45b11e0a1a9cfe32a9bb348b21fdbd8d38e826fb Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 15 Apr 2006 02:55:12 +0000 Subject: [PATCH] added a few utility methods to the config system, and updated the upgrade to reflect that --- docs/upgrades/upgrade_6.8.8-6.99.0.pl | 15 +--- lib/WebGUI/Config.pm | 119 ++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 11 deletions(-) diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl index d2b2d001e..4523c5792 100644 --- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl @@ -32,8 +32,7 @@ changeCache(); templateParsers(); removeFiles(); addSearchEngine(); -addEMSTemplates(); -addEMSTables(); +addEMS(); updateTemplates(); updateDatabaseLinksAndSQLReport(); ipsToCIDR(); @@ -144,9 +143,7 @@ sub addAdManager { renderedAd text )"); $session->db->write("alter table advertisement add index adSpaceId_isActive (adSpaceId, isActive)"); - my $macros = $session->config->get("macros"); - $macros->{AdSpace} = "AdSpace"; - $session->config->set("macros",$macros); + my $macros = $session->config->addToHash("macros","AdSpace","AdSpace"); my $group = WebGUI::Group->new($session, "new", "pbgroup000000000000017"); $group->name("Ad Manager"); $group->description("These users will be able to manage advertisements."); @@ -600,7 +597,7 @@ sub updateTemplates { } #------------------------------------------------- -sub addEMSTemplates { +sub addEMS { print "\tAdding Event Management System Templates.\n" unless ($quiet); ## Display Template ## @@ -925,11 +922,6 @@ EOT4 }, "EventManagerTmpl000004" ); -} - -#------------------------------------------------- -sub addEMSTables { - print "\t Creating Event Management System tables.\n" unless ($quiet); my $sql1 = <db->write($sql6); $session->db->write($sql7); $session->db->write($sql8); + $session->config->addToArray("assets","WebGUI::Asset::Wobject::EventManagementSystem"); } #------------------------------------------------- diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm index 0cf6d72d8..f57104654 100644 --- a/lib/WebGUI/Config.pm +++ b/lib/WebGUI/Config.pm @@ -40,7 +40,13 @@ This package parses the WebGUI config file. my $value = $config->get($param); $config->set($param,$value); + $config->delete($param); + $config->deleteFromHash($name, $key); + $config->deleteFromArray($name, $value); + + $config->addToHash($name, $key, $value); + $config->addToArray($name, $value); my $configFileName = $config->getFilename; my $webguiRoot = $config->getWebguiRoot; @@ -52,6 +58,63 @@ These subroutines are available from this package: =cut +#------------------------------------------------------------------- + +=head2 addToArray ( property, value ) + +Adds a value to an array property in the config file. + +=head3 property + +The name of the array. + +=head3 value + +The value to add. + +=cut + +sub addToArray { + my $self = shift; + my $property = shift; + my $value = shift; + my $array = $self->get($property); + push(@{$array}, $value); + $self->set($property, $array); +} + + +#------------------------------------------------------------------- + +=head2 addToHash ( property, key, value ) + +Adds a value to a hash property in the config file. + +=head3 property + +The name of the hash. + +=head3 key + +The key to add. + +=head3 value + +The value to add. + +=cut + +sub addToHash { + my $self = shift; + my $property = shift; + my $key = shift; + my $value = shift; + my $hash = $self->get($property); + $hash->{$key} = $value; + $self->set($property, $hash); +} + + #------------------------------------------------------------------- =head2 delete ( param ) @@ -75,6 +138,62 @@ sub delete { #------------------------------------------------------------------- +=head2 deleteFromArray ( property, value ) + +Deletes a value from an array property in the config file. + +=head3 property + +The name of the array. + +=head3 value + +The value to delete. + +=cut + +sub deleteFromArray { + my $self = shift; + my $property = shift; + my $value = shift; + my $array = $self->get($property); + for (my $i = 0; $i < scalar(@{$array}); $i++) { + if ($array->[$i] eq $value) { + splice(@{$array}, $i, 1); + last; + } + } + $self->set($property, $array); +} + + +#------------------------------------------------------------------- + +=head2 deleteFromHash ( property, key ) + +Delete a key from a hash property in the config file. + +=head3 property + +The name of the hash. + +=head3 key + +The key to delete. + +=cut + +sub deleteFromHash { + my $self = shift; + my $property = shift; + my $key = shift; + my $hash = $self->get($property); + delete $hash->{$key}; + $self->set($property, $hash); +} + +#------------------------------------------------------------------- + =head2 DESTROY ( ) Deconstructor.