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

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



Revision: 3495
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3495&view=rev
Author:   einhverfr
Date:     2011-07-12 13:04:35 +0000 (Tue, 12 Jul 2011)

Log Message:
-----------
More work on file attachments
fixing bug 3363489
fixing bug 3363503

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Account.pm
    trunk/LedgerSMB/File.pm
    trunk/Makefile.PL
    trunk/scripts/account.pl
    trunk/sql/modules/Files.sql
    trunk/sql/modules/Roles.sql
    trunk/sql/upgrade/1.2-1.3.sql

Added Paths:
-----------
    trunk/sql/upgrade/3495_drop_mime_func.sql

Modified: trunk/LedgerSMB/DBObject/Account.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Account.pm	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/LedgerSMB/DBObject/Account.pm	2011-07-12 13:04:35 UTC (rev 3495)
@@ -59,8 +59,8 @@
     if ($self->{charttype} and $self->{charttype} eq 'H') {
         $func = 'account_heading_save';
     }
-    $self->exec_method(funcname => $func);
-
+    my ($id_ref) = $self->exec_method(funcname => $func);
+    $self->{id} = $id_ref->{$func};
     if (defined $self->{recon}){
         $self->call_procedure(procname => 'cr_coa_to_account_save', args =>[ $self->{accno}, $self->{description}]);
     }
@@ -87,7 +87,7 @@
         $ref->merge($self, keys => ['_user', '_locale', 'stylesheet', 'dbh', '_roles', '_request']);
         push (@{$self->{account_list}}, $ref);
     }
-    return @accounts;
+    return @{$self->{account_list}};
 }
 
 =item check_transactions()

Modified: trunk/LedgerSMB/File.pm
===================================================================
--- trunk/LedgerSMB/File.pm	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/LedgerSMB/File.pm	2011-07-12 13:04:35 UTC (rev 3495)
@@ -19,6 +19,8 @@
 package LedgerSMB::File;
 use Class::Struct;
 use LedgerSMB::DBObject;
+use File::MimeInfo;
+use IO::Scalar;
 use strict;
 
 =item  attached_by_id
@@ -118,7 +120,10 @@
 2:  No locale handle included
 4:  Invalid base.
 
+In most cases when working with new code it is simpler to just
 
+$file->dbobject(LedgerSMB::DBObject->new({base => $request});
+
 =cut
 
 sub new_dbobject{
@@ -166,11 +171,24 @@
     if ($self->mime_type_text){
        return $self->mime_type_text;
     } else {
-       my ($ref) = $self->exec_method({funcname => 'file__mime_type_text'});
+       my ($ref) = $self->exec_method(
+                      {funcname => 'file__mime_type_text',
+                       args     => [$self->mime_type_id, undef]},
+       );
        $self->mime_type_text($ref->{mime_type});
        return $self->mime_type_text;
     }
 }
+
+sub set_mime_type {
+    my ($self, $mime_type) = @_;
+    $self->mime_type_text($mime_type);
+    my ($ref) = $self->exec_method({funcname => 'file__mime_type_text', 
+         args => [undef, $self->mime_type_text]});
+    $self->mime_type_id($ref->{id});
+
+}
+
 =item get
 
 Retrives a file.  ID and file_class properties must be set.

Modified: trunk/Makefile.PL
===================================================================
--- trunk/Makefile.PL	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/Makefile.PL	2011-07-12 13:04:35 UTC (rev 3495)
@@ -22,6 +22,7 @@
 requires 'DBD::Pg';
 requires 'Math::BigFloat';
 requires 'IO::File';
+requires 'IO::Scalar';
 requires 'Encode';
 requires 'Locale::Country';
 requires 'Locale::Language';
@@ -32,6 +33,7 @@
 requires 'Template' => '2.14';
 requires 'Error';
 requires 'CGI::Simple';
+requires 'File::MimeInfo';
 
 recommends 'perl-Math-BigInt-GMP';
 

Modified: trunk/scripts/account.pl
===================================================================
--- trunk/scripts/account.pl	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/scripts/account.pl	2011-07-12 13:04:35 UTC (rev 3495)
@@ -45,19 +45,27 @@
 
 Retrieves account information and then displays the screen.  
 
-Requires the id variable in the request to be set.
+Requires the id and charttype variables in the request to be set.
 
 =cut
 
 sub edit {
     my ($request) = @_;
+    if (!defined $request->{id}){
+        $request->error('No ID provided');
+    } elsif (!defined $request->{charttype}){
+        $request->error('No Chart Type Provided');
+    }
     $request->{chart_id} = $request->{id};
     my $account = LedgerSMB::DBObject::Account->new(base => $request);
     my @accounts = $account->get();
-    my $a = shift @accounts;
-    $a->{title} = $request->{_locale}->text('Edit Account');
-    $a->{_locale} = $request->{_locale};
-    _display_account_screen($a);
+    my $acc = shift @accounts;
+    if (!$acc){  # This should never happen.  Any occurance of this is a bug.
+         $request->error($request->{_locale}->text('Bug: No such account'));
+    }
+    $acc->{title} = $request->{_locale}->text('Edit Account');
+    $acc->{_locale} = $request->{_locale};
+    _display_account_screen($acc);
 }
 
 =item save
@@ -85,7 +93,7 @@
             delete $account->{heading};
     }
     $account->save;
-    edit($request); 
+    edit($account); 
 }
 
 =item save_as_new
@@ -96,7 +104,7 @@
 
 sub save_as_new {
     my ($request) = @_;
-    delete $request->{id};
+    $request->{id} = undef;
     save($request);
 }
 

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/sql/modules/Files.sql	2011-07-12 13:04:35 UTC (rev 3495)
@@ -1,7 +1,9 @@
-CREATE OR REPLACE FUNCTION file__get_mime_type(in_mime_type_id int)
+CREATE OR REPLACE FUNCTION file__get_mime_type
+ (in_mime_type_id int, in_mime_type text)
 RETURNS mime_type AS
 $$
-select * from mime_type where id = $1;
+select * from mime_type 
+ where ($1 IS NULL OR id = $1) AND ($2 IS NULL OR mime_type = $2);
 $$ language sql;
 
 COMMENT ON FUNCTION file__get_mime_type(in_mime_type_id int) IS

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/sql/modules/Roles.sql	2011-07-12 13:04:35 UTC (rev 3495)
@@ -154,7 +154,7 @@
 GRANT UPDATE ON person_to_contact TO "lsmb_<?lsmb dbname ?>__contact_edit";
 GRANT UPDATE ON person_to_contact TO "lsmb_<?lsmb dbname ?>__contact_edit";
 GRANT UPDATE ON person_to_location TO "lsmb_<?lsmb dbname ?>__contact_edit";
-GRANT UPDATE ON person_to_location TO "lsmb_<?lsmb dbname ?>__contact_edit";
+GRANT UPDATE ON eca_to_location TO "lsmb_<?lsmb dbname ?>__contact_edit";
 GRANT DELETE, INSERT  ON vendortax TO "lsmb_<?lsmb dbname ?>__contact_edit";
 GRANT DELETE, INSERT  ON entity_bank_account TO "lsmb_<?lsmb dbname ?>__contact_edit";
 GRANT ALL ON customertax TO"lsmb_<?lsmb dbname ?>__contact_edit";

Modified: trunk/sql/upgrade/1.2-1.3.sql
===================================================================
--- trunk/sql/upgrade/1.2-1.3.sql	2011-07-12 00:46:52 UTC (rev 3494)
+++ trunk/sql/upgrade/1.2-1.3.sql	2011-07-12 13:04:35 UTC (rev 3495)
@@ -1,3 +1,10 @@
+/*
+ALTER SCHEMA PUBLIC RENAME TO lsmb12;
+CREATE SCHEMA PUBLIC;
+
+\i sql/Pg-database.sql
+
+
 BEGIN;
 
 ALTER TABLE employee RENAME TO employees;
@@ -24,3 +31,4 @@
 DROP RULE employee_id_track_i ON employees; -- no longer needed
 
 COMMIT;
+*/

Added: trunk/sql/upgrade/3495_drop_mime_func.sql
===================================================================
--- trunk/sql/upgrade/3495_drop_mime_func.sql	                        (rev 0)
+++ trunk/sql/upgrade/3495_drop_mime_func.sql	2011-07-12 13:04:35 UTC (rev 3495)
@@ -0,0 +1 @@
+DROP FUNCTION file__get_mime_type(in_mime_type_id int);


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