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),
$_[0],
App::IdiotBox::Inflator::Bucket->new({
all_columns => [ qw(slug name) ],
+ body_columns => [ qw(slug name) ],
spec_columns => [ qw(slug) ],
class => 'App::IdiotBox::Bucket',
raw => $_[0],
FROM buckets
WHERE slug = ?
},
+ insert_one => q{
+ INSERT INTO buckets
+ (slug, name)
+ VALUES
+ (?, ?)
+ }
+
}
)
}