X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FApp-IdiotBox.git;a=blobdiff_plain;f=lib%2FApp%2FIdiotBox%2FImporter.pm;fp=lib%2FApp%2FIdiotBox%2FImporter.pm;h=460077714dee15db558f13621cb795d4d1c739b1;hp=a19451c0961f6c510c93ad2e14b02fec9c989dbd;hb=8ee9b216399777fbcb5e307b28c8dcfcd3716dd3;hpb=625f105e80e46edfcae9732c6591842a87c91e1e diff --git a/lib/App/IdiotBox/Importer.pm b/lib/App/IdiotBox/Importer.pm index a19451c..4600777 100644 --- a/lib/App/IdiotBox/Importer.pm +++ b/lib/App/IdiotBox/Importer.pm @@ -18,30 +18,50 @@ sub run { my @buckets = $ib->buckets->flatten; my %bucket_by_slug; log_info { "Available buckets to import into:" }; - foreach my $idx (0 .. $#buckets) { - my $bucket = $buckets[$idx]; - $bucket_by_slug{$bucket->slug} = $bucket; - log_info { "(${idx}) ${\$bucket->slug} : ${\$bucket->name}" }; - } my $bucket; - CHOOSE: { - my $choice = prompt("Which bucket to import into (by number or slug) ?"); - if ($choice =~ /^\d+$/) { - $bucket = $buckets[$choice]; - } else { - $bucket = $bucket_by_slug{$choice}; + BUCKETS: { + foreach my $idx (0 .. $#buckets) { + my $bucket = $buckets[$idx]; + $bucket_by_slug{$bucket->slug} = $bucket; + log_info { "(${idx}) ${\$bucket->slug} : ${\$bucket->name}" }; } - unless ($bucket) { - log_info { - "No bucket for ${choice} - valid options are 0 to ${\$#buckets}" - ." or slug (e.g. ${\$buckets[0]->slug})" - }; - redo CHOOSE; + log_info { sprintf("(%d) new : Create new bucket\n", $#buckets + 1) }; + + CHOOSE: { + my $choice = prompt("Which bucket to import into (by number or slug) ?"); + if ($choice =~ /^\d+$/) { + $bucket = $buckets[$choice]; + } else { + $bucket = $bucket_by_slug{$choice}; + } + + if (!$bucket && ($choice eq 'new' || $choice eq $#buckets + 1)) { + my $sn = prompt("What's the new short name (url path) for the slug ?"); + my $ln = prompt("What's the new long name (description) for the slug ?"); + + $sn =~ s/ /-/g; + + my $nb = $ib->buckets->add(bless({ + slug => $sn, + name => $ln, + }, 'App::IdiotBox::Bucket')); + + log_info { "Created new bucket" }; + push @buckets, $nb; + redo BUCKETS; + } + + unless ($bucket) { + log_info { + "No bucket for ${choice} - valid options are 0 to ${\$#buckets + 1}" + ." or slug (e.g. ${\$buckets[0]->slug})" + }; + redo CHOOSE; + } } } - my $ann = $ib->recent_announcements->add(bless({ bucket => $bucket, made_at => strftime("%Y-%m-%d %H:%M:%S",localtime),