[Yapcom-commit] rev 366 - in yapcom/trunk: . bin lib/YAPC t/db t/web

svn at pti.co.il svn at pti.co.il
Wed Aug 9 10:13:46 IDT 2006


Author: gabor
Date: 2006-08-09 10:13:45 +0300 (Wed, 09 Aug 2006)
New Revision: 366

Added:
   yapcom/trunk/lib/YAPC/Tools.pm
Modified:
   yapcom/trunk/
   yapcom/trunk/MANIFEST
   yapcom/trunk/bin/upgrade_to_0_14.pl
   yapcom/trunk/lib/YAPC/Config.pm
   yapcom/trunk/lib/YAPC/Organizer.pm
   yapcom/trunk/t/db/02-login.t
   yapcom/trunk/t/web/33-web-adduser.t
   yapcom/trunk/t/web/41-web-admin.t
Log:
add YAPC::Tools module to hold no-database related helper subs
move the checking of db_closed rom Config to Tools (and file based)



Property changes on: yapcom/trunk
___________________________________________________________________
Name: svk:merge
   - 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/yapcom:10730
   + 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/yapcom:10731

Modified: yapcom/trunk/MANIFEST
===================================================================
--- yapcom/trunk/MANIFEST	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/MANIFEST	2006-08-09 07:13:45 UTC (rev 366)
@@ -25,6 +25,7 @@
 lib/YAPC/Person.pm
 lib/YAPC/Talk.pm
 lib/YAPC/Error.pm
+lib/YAPC/Tools.pm
 
 t/db/00-simple.t                  no
 t/db/01-adduser.t                 no

Modified: yapcom/trunk/bin/upgrade_to_0_14.pl
===================================================================
--- yapcom/trunk/bin/upgrade_to_0_14.pl	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/bin/upgrade_to_0_14.pl	2006-08-09 07:13:45 UTC (rev 366)
@@ -9,11 +9,14 @@
 #use YAPC::Config;
 use File::Copy qw(move copy);
 use DBI;
+use Cwd qw(cwd);
 
-#if (not $YAPC::Config::db_closed) {
-#	die "First close the database by setting db_closed to 1  in the db/config file\n";
-#}
+use YAPC::Tools;
 
+if (not YAPC::Tools->db_closed(cwd)) {
+	die "First close the database by creating the db_closed file\n";
+}
+
 my $time   = time;
 my $failed;
 my $db_file = 'db/yapc.db';
@@ -38,7 +41,7 @@
 	print "The datbase was upgraded successfully.\n";
 	
 }
-print "Please don't forget to set the db_closed value to 0 in the db/config file\n";
+print "Please don't forget to remove the db_closed file\n";
 
 __END__
 ALTER TABLE people ADD day      VARCHAR(1);

Modified: yapcom/trunk/lib/YAPC/Config.pm
===================================================================
--- yapcom/trunk/lib/YAPC/Config.pm	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/lib/YAPC/Config.pm	2006-08-09 07:13:45 UTC (rev 366)
@@ -54,7 +54,6 @@
 
 our $db_file          = "$dir/db/yapc.db";
 our $TIMEOUT          = $config{DB_TIMEOUT} || 100;
-our $db_closed        = $config{DB_CLOSED};
 
 our @templates_dirs;
 if ($config{TEMPLATES_DIRS}) {

Modified: yapcom/trunk/lib/YAPC/Organizer.pm
===================================================================
--- yapcom/trunk/lib/YAPC/Organizer.pm	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/lib/YAPC/Organizer.pm	2006-08-09 07:13:45 UTC (rev 366)
@@ -4,44 +4,80 @@
 
 our $VERSION = '0.13_01';
 
+use Data::Dumper;
 use English '-no_match_vars';
-
-use CGI::Application;
-use YAPC::Config;    # Call Config first
-YAPC::Config->load;
-
-if (not $YAPC::Config::db_closed) {
-    require YAPC::Person;
-	require YAPC::Login;
-	require YAPC::Talk;
-}
-use YAPC::Conf;
 use Error qw(:try);
 use Mail::Sendmail;
 use HTML::Template;    # we use it explicitely hence we need it here.
 
-
 use base 'CGI::Application';
-use Data::Dumper;      # for playing with debugging
 use CGI::Application::Plugin::LogDispatch;
 
+
+use YAPC::Tools;
+use YAPC::Config;
+YAPC::Config->load;
+############# setup run modes
+
 # list pages that require valid login to access
-my @user_pages = qw(proposal personal_info change_password
-  user_account logout list_my_proposals edit_my_proposal);
+my @user_pages = qw(
+    proposal 
+    personal_info 
+    change_password
+    user_account 
+    logout 
+    list_my_proposals 
+    edit_my_proposal
+);
 
 # list of pages accessible to administrators only
 my @admin_pages  = qw(configuration);
 my @editor_pages = qw(admin_list_proposals);
 
 # other pages that can be directly access but which don't need any authentication
-my @other_pages = qw(list_people login registration validation lost_validation lost_password
-  person talk presentations missing_configuration speakers db_closed schedule);
+my @other_pages = qw(
+    list_people 
+    login 
+    registration 
+    validation 
+    lost_validation 
+    lost_password
+    person 
+    talk 
+    presentations 
+    missing_configuration 
+    speakers 
+    db_closed 
+    schedule
+);
 
-my @no_db_needed = qw(index milestones news pr organizers accessibility sponsors sponsorship location other_conferences); 
+my @no_db_needed = qw(
+    index 
+    milestones 
+    news 
+    pr 
+    organizers 
+    accessibility 
+    sponsors 
+    sponsorship 
+    location 
+    other_conferences
+); 
 my @run_modes = (@user_pages, @admin_pages, @editor_pages, @other_pages);
 
 sub cgiapp_init {
     my $self = shift;
+
+    $self->param( dir => $main::dir );
+
+    if (not YAPC::Tools->db_closed($self->param('dir'))) {
+        require YAPC::Person;
+	    require YAPC::Login;
+	    require YAPC::Talk;
+    }
+    require YAPC::Conf;
+
+
     # separate log file for each user so when running test we won't create a
     # file that is not writable by the user running the web server
     $self->log_config(
@@ -76,7 +112,8 @@
 	my $page = get_page();
     $self->log->debug("page: '$page'");
 
-	if ($YAPC::Config::db_closed and not grep /$page/, @no_db_needed) {
+	if (YAPC::Tools->db_closed( $self->param( 'dir' ))
+        and not grep /$page/, @no_db_needed) {
 		$self->prerun_mode('db_closed');
 		return;
 	}

Added: yapcom/trunk/lib/YAPC/Tools.pm
===================================================================
--- yapcom/trunk/lib/YAPC/Tools.pm	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/lib/YAPC/Tools.pm	2006-08-09 07:13:45 UTC (rev 366)
@@ -0,0 +1,19 @@
+package YAPC::Tools;
+use strict;
+use warnings;
+
+# various helper functions
+
+use Carp;
+
+sub db_closed {
+    my ($self, $dir) = @_;
+
+    croak "No directory given" if not defined $dir;
+    croak "Invalid directory given" if not -d $dir or not -d "$dir/db";
+    return -e "$dir/db/db_closed";
+}
+
+
+
+1;

Modified: yapcom/trunk/t/db/02-login.t
===================================================================
--- yapcom/trunk/t/db/02-login.t	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/t/db/02-login.t	2006-08-09 07:13:45 UTC (rev 366)
@@ -17,7 +17,6 @@
 }
 
 use YAPC::Conf;
-#BEGIN { YAPC::Conf->set_dir(cwd); }
 
 require_ok('YAPC::Config');
 require_ok('YAPC::Person');

Modified: yapcom/trunk/t/web/33-web-adduser.t
===================================================================
--- yapcom/trunk/t/web/33-web-adduser.t	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/t/web/33-web-adduser.t	2006-08-09 07:13:45 UTC (rev 366)
@@ -68,7 +68,11 @@
 }
 
 {
-    local $YAPC::Config::db_closed = 1;
+    if (open my $fh, ">", "db/db_closed") {
+        close $fh;
+    } else {
+        die "Could not create db/db_closed file";
+    }
    	local $ENV{REQUEST_URI} = '/list_people.html';
 	my $webapp = YAPC::Organizer->new;
 	$webapp->query(CGI->new());
@@ -76,6 +80,7 @@
 	unlike($result, qr/List Registered People/, 'empty ? list page is OK');
 	like($result, qr/The page is temporarily not available./, 'The page is temporarily not available.');
     like($result, qr/The database is being upgraded./, 'The database is being upgraded.');
+    unlink "db/db_closed" or die "Could not remove db/db_closed file";
     BEGIN { $tests += 3; }
 }
 

Modified: yapcom/trunk/t/web/41-web-admin.t
===================================================================
--- yapcom/trunk/t/web/41-web-admin.t	2006-08-09 07:13:30 UTC (rev 365)
+++ yapcom/trunk/t/web/41-web-admin.t	2006-08-09 07:13:45 UTC (rev 366)
@@ -28,8 +28,6 @@
 $ENV{YAPCOM_NOMAIL} = 1;
 $ENV{REQUEST_URI}     = '/';
 
-#use YAPC::Config;
-#YAPC::Config->load;
 require_ok('YAPC::Organizer');
 BEGIN { $tests += 1; }
 YAPC::Test::setup_test_config();



More information about the Yapcom-commit mailing list