From 2a794c1d0b0d230c517bb03ae2ee2ed45b7ef785 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 29 Apr 2010 12:00:00 +0000 Subject: check size if playlist before import git-svn-id: https://svn.helsinki.at/rhimport/trunk@59 7c65635b-ec39-4f67-a626-873dbafdd612 diff --git a/TODO b/TODO index bcc4fc3..4fc66b9 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ * multi-cart-show - upload a single file.. -* multi-cart/pool - check size of pool vs length of m3u * add "show log" button after import diff --git a/rhimport b/rhimport index 8b2b3f0..8d70c9e 100755 --- a/rhimport +++ b/rhimport @@ -267,7 +267,7 @@ sub start_import_gui() $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb); } my $import_log; - ($ret, $import_log) = rhimport::import_playlist($file, $dropbox, $user, $gui_progress_cb, $gui_error_cb); + ($ret, $import_log) = rhimport::import_playlist($file, $dropbox, $user, rhimport::get_num_carts($dbh, $group) ,$gui_progress_cb, $gui_error_cb); $log .= $import_log; } else { $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb); @@ -443,7 +443,7 @@ if($POOL) { } my $import_log; - ($ret, $import_log) = rhimport::import_playlist($FILE, $DROPBOX, $user, 0, $cl_error_cb); + ($ret, $import_log) = rhimport::import_playlist($FILE, $DROPBOX, $user, rhimport::get_num_carts($dbh, $group), 0, $cl_error_cb); $log .= $import_log; } else { $log = rhimport::clear_carts($dbh, $group, $to_cart); diff --git a/rhimport.pm b/rhimport.pm index 6597fb4..7ecc2fe 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -108,6 +108,14 @@ sub get_used_carts return @carts; } +sub get_num_carts +{ + my ($dbh, $group) = @_; + + my ($low_cart, $high_cart) = get_cart_range($dbh, $group); + return $high_cart - $low_cart + 1; +} + sub clear_carts { my ($dbh, $group, $to_cart, $progress_cb) = @_; @@ -150,7 +158,7 @@ sub clear_carts sub import_playlist { - my ($playlist, $dropbox, $user, $progress_cb, $error_cb) = @_; + my ($playlist, $dropbox, $user, $num_carts, $progress_cb, $error_cb) = @_; print "Starting import from playlist $playlist to $dropbox"; my @entries; @@ -165,10 +173,21 @@ sub import_playlist } close(FILE); my $num_entries = scalar(@entries); - print " ($num_entries Files in list)\n"; - + print " ($num_entries Files in list -> $num_carts available)\n"; + + if($num_carts < $num_entries) { + if($error_cb) { + my $ret = $error_cb->("Achtung!\nDie Playlist beinhaltet mehr als $num_carts Dateien. Es werden nur die ersten $num_carts Dateien importiert."); + if(!$ret) { + return 0, "too many files in playlist"; + } + + $#entries = $num_carts-1; + $num_entries = scalar(@entries); + } + } + print "will import $num_entries files\n"; - return (0, ""); my $cnt = 0; my $ret = 0; my $log = ""; -- cgit v0.10.2