[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6395] trunk



Revision: 6395
          http://sourceforge.net/p/ledger-smb/code/6395
Author:   einhverfr
Date:     2014-01-06 03:41:38 +0000 (Mon, 06 Jan 2014)
Log Message:
-----------
Loading templates now works as part of the db setup process.  Now to add it to the console template

Modified Paths:
--------------
    trunk/LedgerSMB/Scripts/configuration.pm
    trunk/LedgerSMB/Scripts/setup.pm

Removed Paths:
-------------
    trunk/tools/load_templates.pl

Modified: trunk/LedgerSMB/Scripts/configuration.pm
===================================================================
--- trunk/LedgerSMB/Scripts/configuration.pm	2014-01-05 14:35:43 UTC (rev 6394)
+++ trunk/LedgerSMB/Scripts/configuration.pm	2014-01-06 03:41:38 UTC (rev 6395)
@@ -47,9 +47,6 @@
        { name => 'default_language',
         label => $locale->text('Default Language'),
          type => 'SELECT_ONE', },
-       { name => 'templates',
-         type => 'SELECT_ONE',
-        label => $locale->text('Template Set'), },
        { name => 'format',
          type => 'SELECT_ONE',
         label => $locale->text('Default Format'), },
@@ -211,12 +208,6 @@
 			     text_attr => 'description',
 			     value_attr => 'code',
 		},
-	'templates'        => {name => 'templates',
-                           options => _get_template_directories(),
-                         text_attr => 'text',
-                    default_values => [$request->{'templates'}],
-                        value_attr => 'value'
-               },
         'format'           => {name => 'format',
                            text_attr => 'text',
                           value_attr => 'value',
@@ -295,26 +286,12 @@
     defaults_screen($request);
 }
 
-=item _get_template_directories
+=item save_sequences
 
-Returns set of template directories available.
+Saves the items in the sequence screen
 
 =cut
 
-sub _get_template_directories {
-    my $subdircount = 0;
-    my @dirarray;
-    opendir ( DIR, $LedgerSMB::Sysconfig::templates) || die $locale->text("Error while opening directory: [_1]",  "./".$LedgerSMB::Sysconfig::templates);
-    while( my $name = readdir(DIR)){
-        next if ($name =~ /\./);
-        if (-d $LedgerSMB::Sysconfig::templates.'/'.$name) {
-            push @dirarray, {text => $name, value => $name};
-        }
-    }
-    closedir(DIR);
-    return \@dirarray;
-}
-
 sub save_sequences {
     my ($request) = @_;
     for my $count (1 .. $request->{count}){

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2014-01-05 14:35:43 UTC (rev 6394)
+++ trunk/LedgerSMB/Scripts/setup.pm	2014-01-06 03:41:38 UTC (rev 6395)
@@ -23,6 +23,8 @@
 use LedgerSMB::Database;
 use LedgerSMB::App_State;
 use LedgerSMB::Upgrade_Tests;
+use LedgerSMB::Sysconfig;
+use LedgerSMB::Template::DB;
 use strict;
 
 my $logger = Log::Log4perl->get_logger('LedgerSMB::Scripts::setup');
@@ -203,12 +205,7 @@
     my $database = _get_database($request);
     my $rc = $database->copy($request->{new_name}) 
            || die 'An error occurred. Please check your database logs.' ;
-    my $template = LedgerSMB::Template->new(
-            path => 'UI/setup',
-            template => 'complete',
-            format => 'HTML',
-    );
-    $template->render($request);
+    complete($request);
 }
 
 
@@ -317,7 +314,68 @@
  
 }
    
+=item _get_template_directories
 
+Returns set of template directories available.
+
+=cut
+
+sub _get_template_directories {
+    my $subdircount = 0;
+    my @dirarray;
+    my $locale = $LedgerSMB::App_State::Locale;
+    opendir ( DIR, $LedgerSMB::Sysconfig::templates) || die $locale->text("Error while opening directory: [_1]",  "./".$LedgerSMB::Sysconfig::templates);
+    while( my $name = readdir(DIR)){
+        next if ($name =~ /\./);
+        if (-d $LedgerSMB::Sysconfig::templates.'/'.$name) {
+            push @dirarray, {text => $name, value => $name};
+        }
+    }
+    closedir(DIR);
+    return \@dirarray;
+}
+
+=item template_screen
+
+Shows the screen for loading templates.  This should appear before loading
+the user.  $request->{only_templates} will be passed on to the saving routine
+so that further workflow can be aborted.
+
+=cut
+
+sub template_screen {
+    my ($request) = @_;
+    $request->{template_dirs} = _get_template_directories();
+    LedgerSMB::Template->new(
+           path => 'UI/setup',
+           template => 'template_info',
+           format => 'HTML',
+    )->render($request);
+}
+
+=item load_templates
+
+This bulk loads the templates.  Expectated inputs are template_dir and
+optionally only_templates (which if true returns to the confirmation screen 
+and not the user creation screen.
+
+=cut
+
+sub load_templates {
+    my ($request) = @_;
+    my $dir = $LedgerSMB::Sysconfig::templates . '/' . $request->{template_dir};
+    my $dbh = _get_database($request)->dbh;
+    opendir(DIR, $dir);
+    while (readdir(DIR)){
+       next unless -f "$dir/$_";
+       my $dbtemp = LedgerSMB::Template::DB->get_from_file("$dir/$_");
+       $dbtemp->save;
+    }
+    $dbh->commit;
+    return _render_new_user($request) unless $request->{only_templates};
+    return complete($request);
+}
+
 =item _get_linked_accounts
 
 Returns an array of hashrefs with keys ('id', 'accno', 'desc') identifying
@@ -549,7 +607,6 @@
 =cut
 
 sub create_db {
-    use LedgerSMB::Sysconfig;
     my ($request) = @_;
     my $rc=0;
 
@@ -597,7 +654,7 @@
     }
     if ($request->{coa_lc}){
         if ($request->{chart}){
-           _render_new_user($request);
+           template_screen($request);
         } else {
             opendir(COA, "sql/coa/$request->{coa_lc}/chart");
             my @coa = sort (grep !/^(\.|[Ss]ample.*)/, readdir(COA));
@@ -617,7 +674,7 @@
              push @{$request->{coa_lcs}}, {code => $lcs};
         } 
     }
-    _render_new_user($request);
+    template_screen($request);
 }
 
 
@@ -635,7 +692,7 @@
 sub skip_coa {
     my ($request) = @_;
 
-    _render_new_user($request);
+    template_screen($request);
 }
 
 
@@ -932,7 +989,6 @@
 	log     => $temp . "_stdout",
 	errlog  => $temp . "_stderr"
 			    });
-    $request->{lsmb_info} = $database->lsmb_info();
 
     my $dbh = $request->{dbh};
     my $sth = $dbh->prepare(
@@ -942,15 +998,30 @@
     $sth->finish;
     $dbh->commit;
     #$dbh->disconnect;#upper stack will disconnect
+    complete($request);
+
+}
+
+=item complete 
+
+Gets the info and adds shows the complete screen.
+
+=cut
+
+sub complete {
+    my ($request) = @_;
+    my $database = _init_db($request);
+    my $temp = $database->loader_log_filename();
+    $request->{lsmb_info} = $database->lsmb_info();
     my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'complete',
             format => 'HTML',
     );
     $template->render($request);
-
 }
 
+
 =back
 
 =head1 COPYRIGHT

Deleted: trunk/tools/load_templates.pl
===================================================================
--- trunk/tools/load_templates.pl	2014-01-05 14:35:43 UTC (rev 6394)
+++ trunk/tools/load_templates.pl	2014-01-06 03:41:38 UTC (rev 6395)
@@ -1,104 +0,0 @@
-#!/usr/bin/perl
-#
-# load_templates.pl
-use LedgerSMB::App_State;
-use LedgerSMB::Template::DB;
-use DBI;
-
-my $help_msg = "
-
-perl load_templates.pl file_or_directory [language] [database]
-
-This is a simple script to load templates into the database from the 
-filesystem.  It loads them into the database via the LedgerSMB::Template::DB
-module.
-
-This can be run either on a single file or on a directory which is given in the 
-first argument.  The arguments are as follows:
-
-file_or_directory:  the file or directory to be loaded.  This is not done 
-recursively.  If you want to load recursively, use with find.  This decision was
-made because it makes some sense to store language-specific templates in 
-subdirectories.
-
-language:  This is the language code (i.e. en or en_US) to attach to the 
-template.  If omitted the templates are assumed not to be language specific.  
-You would use this if you wanted to change the layout for a specific language.
-
-database:  The database to connect to.  If PGDATABASE is set this takes 
-precedence only in the 3 arg form.  Use '' to indicate a missing language code 
-in that case.
-
-Examples:
-
-PGDATABASE=lsmbdemo perl load_templates.pl templates/demo
-perl load_templates.pl templates/demo/en en lsmbdemo
-PGDATABASE=lsmbdemo perl load_templates.pl templates/demo/en en
-perl load_templates.pl file_or_directory templates/demo '' lsmbdemo
-
-";
-
-
-
-#### ARG HANDLING (before functions because it should be read first)
-#
-my ($to_load, $language, $database) = @ARGV;
-
-# handle 2-arg form:
-
-if (!$database){
-   $database = $ENV{PGDATABASE};
-   if (!$database){
-       $database = $language;
-       $language = undef;
-   }
-}
-
-$language  ||= undef; # false values used as placeholders only.
-
-if ($to_load eq '--help' or $to_load =~ /^-/ or !$to_load){
-    print $help_msg;
-    exit 0;
-}
-
-### FUNCTIONS
-
-sub load_template {
-    my ($path) = @_;
-    my $dbtemp = LedgerSMB::Template::DB->get_from_file($path, $language_code);
-    $dbtemp->save;
-}
-
-### SETUP
-
-# db connection
-
-my $dbh = DBI->connect("dbi:Pg:dbname=$database") 
-  or die "Unable to connect to database!"; # autocommit on, no need to turn off
-
-$LedgerSMB::App_State::DBH = $dbh;
-
-### LOADING LOGIC
-
-# is file or directory?
-
-my $type = undef;
-
-$type = 'file' if -f $to_load;
-$type = 'dir' if -d $to_load;
-
-die 'Bad file type: Must be a file or directory or file does not exist' 
-   unless defined $type;
-
-# load
-
-if ($type eq 'file'){
-   load_template($to_load);
-} else {
-   opendir(DIR, $to_load);
-   while (readdir(DIR)){
-      load_template("$to_load/$_") if -f "$to_load/$_";
-   }
-}
-
-exit 0;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits