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

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



Revision: 6382
          http://sourceforge.net/p/ledger-smb/code/6382
Author:   einhverfr
Date:     2014-01-05 09:52:59 +0000 (Sun, 05 Jan 2014)
Log Message:
-----------
Adding method to get template from file

Modified Paths:
--------------
    trunk/LedgerSMB/Template/DB.pm
    trunk/tools/load_templates.pl

Modified: trunk/LedgerSMB/Template/DB.pm
===================================================================
--- trunk/LedgerSMB/Template/DB.pm	2014-01-05 09:26:49 UTC (rev 6381)
+++ trunk/LedgerSMB/Template/DB.pm	2014-01-05 09:52:59 UTC (rev 6382)
@@ -109,6 +109,38 @@
     return __PACKAGE__->new(%$temp);
 }
 
+=head2 get_from_file($path)
+
+Loads a template from a file path.  This should only be used during database
+setup because it could be used to access any file on the system that the web 
+server or fcgi process could.  It is highly recommended that other web app code 
+does not call this without carefully whitelisting values.
+
+=cut
+
+sub get_from_file {
+    my ($package, $path) = @_;
+    my $fname = $path;
+    if ($path =~ m|/.*:| ){
+       die 'Cannot run on NTFS alternate data stream!';
+    }
+    $path =~ m|(.*)/([^/]+)$|;
+    $fname = $2;
+    my ($template_name, $format) = split /\./, $fname;
+    my $content = '';
+    open TEMP, '<', $path;
+    $content .= $_ while <TEMP>;
+    my %args = (
+           template_name => $template_name,
+           format => $format,
+           template => $content,
+    );
+    $args{language_code} = $language_code if $language_code;
+    my $self = LedgerSMB::Template::DB->new(%args);
+    return $self;
+}
+    
+
 =head2 save
 
 Saves the current object

Modified: trunk/tools/load_templates.pl
===================================================================
--- trunk/tools/load_templates.pl	2014-01-05 09:26:49 UTC (rev 6381)
+++ trunk/tools/load_templates.pl	2014-01-05 09:52:59 UTC (rev 6382)
@@ -65,23 +65,7 @@
 
 sub load_template {
     my ($path) = @_;
-    my $fname = $path;
-    if ($path =~ m|/.*:| ){
-       die 'Cannot run on NTFS alternate data stream!';
-    }
-    $path =~ m|(.*)/([^/]+)$|;
-    $fname = $2;
-    my ($template_name, $format) = split /\./, $fname;
-    my $content = '';
-    open TEMP, '<', $path;
-    $content .= $_ while <TEMP>;
-    my %args = (
-           template_name => $template_name,
-           format => $format,
-           template => $content,
-    );
-    $args{language_code} = $language_code if $language_code;
-    my $dbtemp = LedgerSMB::Template::DB->new(%args);
+    my $dbtemp = LedgerSMB::Template::DB->get_from_file($path);
     $dbtemp->save;
 }
 

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