Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 6 commits
  • 55 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 19, 2005
Marshall Roch Make a clean branch to work on ICs b/c I'm scared of letting it merge…
… all of those major changes on its own
d50bd02
Commits on Oct 28, 2005
Marshall Roch Merge 6812:6889 from trunk cf5a6ae
Commits on Oct 29, 2005
Marshall Roch Split story and media into versions and instances. No new features in…
… this commit, but it's the foundation necessary for everything else.
0cf2887
Commits on Nov 02, 2005
Marshall Roch More instance/version changes cbe0722
Commits on Nov 12, 2005
Marshall Roch Add input channel objects, an input channel manager/profile, associat…
…ions with element types, and the UI to manage them. Updated the tests to add ICs to new element types.
c0a7a6d
Commits on Nov 13, 2005
Marshall Roch Merge 6890:6918 from trunk c0aff53
Showing with 4,447 additions and 330 deletions.
  1. +5 −0 comp/admin/manager/dhandler
  2. +84 −3 comp/admin/profile/element_type/dhandler
  3. +147 −0 comp/admin/profile/input_channel/dhandler
  4. +3 −2 comp/widgets/wrappers/sharky/sideNav.mc
  5. +92 −8 lib/Bric/App/Callback/Profile/FormBuilder.pm
  6. +89 −0 lib/Bric/App/Callback/Profile/InputChannel.pm
  7. +2 −0 lib/Bric/App/Handler.pm
  8. +6 −2 lib/Bric/Biz/Asset.pm
  9. +9 −9 lib/Bric/Biz/Asset/Business.pm
  10. +175 −76 lib/Bric/Biz/Asset/Business/Media.pm
  11. +202 −89 lib/Bric/Biz/Asset/Business/Story.pm
  12. +349 −5 lib/Bric/Biz/ElementType.pm
  13. +1,222 −0 lib/Bric/Biz/InputChannel.pm
  14. +515 −0 lib/Bric/Biz/InputChannel/Element.pm
  15. +29 −0 lib/Bric/Changes.pod
  16. +259 −0 lib/Bric/Util/Coll/ICElement.pm
  17. +8 −5 lib/Bric/Util/Coll/Site.pm
  18. +2 −1 lib/Bric/Util/Grp/Grp.pm
  19. +284 −0 lib/Bric/Util/Grp/InputChannel.pm
  20. +23 −23 lib/Bric/Util/Job.pm
  21. +2 −2 lib/Bric/Util/Job/Dist.pm
  22. +2 −2 lib/Bric/Util/Job/Pub.pm
  23. +16 −9 sql/Pg/Bric/Biz/Asset/Business/Media.con
  24. +35 −14 sql/Pg/Bric/Biz/Asset/Business/Media.sql
  25. +12 −7 sql/Pg/Bric/Biz/Asset/Business/Story.con
  26. +34 −15 sql/Pg/Bric/Biz/Asset/Business/Story.sql
  27. +15 −0 sql/Pg/Bric/Biz/ElementType.con
  28. +31 −5 sql/Pg/Bric/Biz/ElementType.sql
  29. +36 −12 sql/Pg/Bric/Biz/ElementType.val
  30. +23 −0 sql/Pg/Bric/Biz/InputChannel.con
  31. +58 −0 sql/Pg/Bric/Biz/InputChannel.sql
  32. +19 −0 sql/Pg/Bric/Biz/InputChannel.val
  33. +6 −0 sql/Pg/Bric/Util/Class.val
  34. +15 −0 sql/Pg/Bric/Util/EventType.val
  35. +9 −0 sql/Pg/Bric/Util/Grp.val
  36. +6 −6 sql/Pg/Bric/Util/Job.con
  37. +6 −6 sql/Pg/Bric/Util/Job.sql
  38. +11 −1 t/Bric/Biz/Asset/Business/DevTest.pm
  39. +3 −3 t/Bric/Biz/Element/Container/DevTest.pm
  40. +7 −1 t/Bric/Biz/Element/DevTest.pm
  41. +2 −2 t/Bric/Biz/Element/Field/DevTest.pm
  42. +30 −3 t/Bric/Biz/ElementType/DevTest.pm
  43. +237 −0 t/Bric/Biz/InputChannel/DevTest.pm
  44. +199 −0 t/Bric/Biz/InputChannel/Element/DevTest.pm
  45. +36 −0 t/Bric/Biz/InputChannel/Element/Test.pm
  46. +61 −0 t/Bric/Biz/InputChannel/Test.pm
  47. +12 −1 t/Bric/Util/Burner/DevTest.pm
  48. +1 −1 t/Bric/Util/Burner/Mason/DevTest.pm
  49. +1 −1 t/Bric/Util/Burner/PHP/DevTest.pm
  50. +1 −1 t/Bric/Util/Burner/Template/DevTest.pm
  51. +1 −1 t/Bric/Util/Burner/TemplateToolkit/DevTest.pm
  52. +3 −3 t/Bric/Util/EventType/DevTest.pm
  53. +4 −4 t/Bric/Util/Grp/DevTest.pm
  54. +3 −2 t/Bric/Util/Grp/Test.pm
  55. +5 −5 t/Bric/Util/Job/Pub/DevTest.pm
View
5 comp/admin/manager/dhandler
@@ -360,6 +360,11 @@ my $def = {
constrain => { active => 1 },
select => $sel_sub,
},
+ input_channel => { list_fields => [qw(name site description)],
+ srch_field => 'name',
+ behavior => 'narrow',
+ constrain => {active => 1},
+ select => $sel_sub },
output_channel => { list_fields => [qw(name burner_name site description)],
srch_field => 'name',
behavior => 'narrow',
View
87 comp/admin/profile/element_type/dhandler
@@ -149,6 +149,79 @@ if (defined $id) {
$m->comp('/widgets/wrappers/sharky/table_bottom.mc');
}
+ # Manage Input Channels.
+ my %got_ics = map { $_->get_id => 1 } $comp->get_input_channels;
+ my @available_ics;
+ foreach my $site ($comp->get_sites) {
+ push @available_ics, grep {!$got_ics{$_->get_id}}
+ Bric::Biz::InputChannel->list({
+ site_id => $site->get_id,
+ active => 1
+ });
+ }
+
+ if (scalar keys %got_ics > 1 || @available_ics) {
+ my $ic_sub = sub {
+ my $icid = $_[0]->get_id;
+ if ($_[1] eq 'enabled') {
+ return 'Yes'
+ if $comp->get_primary_ic_id($_[0]->get_site_id) == $icid;
+ $m->scomp(
+ '/widgets/profile/checkbox.mc',
+ name => 'enabled',
+ value => $icid,
+ checked => $_[0]->is_enabled,
+ useTable => 0
+ );
+ }
+ };
+
+ my %pic_ids = map { $comp->get_primary_ic_id($_->get_id) => 1 }
+ $comp->get_sites;
+
+ my $ic_sel_sub = sub {
+ return if $pic_ids{$_[0]->get_id};
+ return ['Delete', 'rem_ic'];
+ };
+
+ $m->comp(
+ '/widgets/wrappers/sharky/table_top.mc',
+ caption => 'Input Channels',
+ number => ++$num,
+ );
+ $m->comp(
+ '/widgets/listManager/listManager.mc',
+ object => 'input_channel',
+ userSort => 0,
+ def_sort_field => 'name',
+ objs => scalar $comp->get_input_channels,
+ addition => undef,
+ fields => [qw(name description site enabled)],
+ field_titles => { enabled => 'Enabled' },
+ field_values => $ic_sub,
+ profile => undef,
+ select => $ic_sel_sub,
+ );
+
+ if (@available_ics) {
+ $m->print(qq{<div class="actions">\n});
+ $m->comp(
+ '/widgets/select_object/select_object.mc',
+ object => 'input_channel',
+ objs => \@available_ics,
+ field => 'name',
+ no_persist => 1,
+ getter => $ic_name_getter,
+ name => 'formBuilder|add_ic_id_cb',
+ default => ['' => 'Add Input Channel'],
+ js => "onChange='submit()'",
+ useTable => 0,
+ );
+ $m->print("</div>\n");
+ }
+ $m->comp('/widgets/wrappers/sharky/table_bottom.mc');
+ }
+
# Manage Output Channels.
my %got_ocs = map { $_->get_id => 1 } $comp->get_output_channels;
my @available_ocs;
@@ -367,12 +440,20 @@ my $sel_sub = sub {
return ['Delete', 'rem_site'];
};
-my $ng = Bric::Biz::OutputChannel->my_meths->{name}{get_meth};
-my $sg = Bric::Biz::OutputChannel->my_meths->{site}{get_meth};
+my $icng = Bric::Biz::InputChannel->my_meths->{name}{get_meth};
+my $icsg = Bric::Biz::InputChannel->my_meths->{site}{get_meth};
+
+my $ic_name_getter = sub {
+ my $i = shift;
+ return $icng->($i) . ' (' . $icsg->($i) . ')';
+};
+
+my $ocng = Bric::Biz::OutputChannel->my_meths->{name}{get_meth};
+my $ocsg = Bric::Biz::OutputChannel->my_meths->{site}{get_meth};
my $oc_name_getter = sub {
my $o = shift;
- return $ng->($o) . ' (' . $sg->($o) . ')';
+ return $ocng->($o) . ' (' . $ocsg->($o) . ')';
};
my $type_vals = { %{ $class->my_meths->{biz_class_id} } };
View
147 comp/admin/profile/input_channel/dhandler
@@ -0,0 +1,147 @@
+<%perl>;
+# Instantiate an object.
+my $ic = $ARGS{obj} ? $ARGS{obj} : defined $id ? $class->lookup({ id => $id})
+ : $class->new;
+$id ||= $ic->get_id;
+
+# Check authorization.
+chk_authz($ic, $id ? READ : CREATE);
+my $no_edit = !chk_authz($ic, ($id ? EDIT : CREATE), 1);
+my $no_del = !$id || $no_edit;
+
+# Get the name for the breadcrumb trail.
+my $crumb = $ic->get_name;
+$crumb = $crumb ? "&quot;$crumb&quot;" : 'New';
+
+# Assume we're going to need a "next" button.
+my $button = 'next_dkgreen';
+
+# Output the header and other necessities.
+$m->comp('/widgets/wrappers/sharky/header.mc',
+ title => "$disp Profile",
+ context => "Admin | Profile | $disp | $crumb"
+);
+$m->out(qq{<form method="post" name="ic_profile" action="} . $r->uri
+ . qq{" onsubmit="return confirmChanges(this)">\n});
+
+# Output a hidden field with the ID, if we have one.
+$m->comp('/widgets/profile/hidden.mc', value => $id, name => 'input_channel_id')
+ if defined $id;
+
+$m->comp("/widgets/wrappers/sharky/table_top.mc",
+ caption => "Properties",
+ number => 1
+);
+
+# Dump out the fields for display.
+$m->comp('/widgets/profile/dumpRemainingFields.mc',
+ readOnly => $no_edit,
+ objref => $ic,
+ fieldsUsed => {active => 1, burner => 1 }
+);
+if (defined $id || $no_edit) {
+ $m->comp(
+ '/widgets/profile/displayFormElement.mc',
+ objref => $ic,
+ key => 'burner_name',
+ readOnly => 1,
+ );
+} else {
+ $m->comp(
+ '/widgets/profile/displayFormElement.mc',
+ objref => $ic,
+ key => 'burner',
+ readOnly => 0,
+ );
+}
+my @sites = site_list(EDIT);
+if ($id || $no_edit) {
+ $m->comp('/widgets/profile/hidden.mc', value => $ic->get_site_id, name => 'site_id');
+ $m->comp('/widgets/profile/displayFormElement.mc',
+ objref => $ic,
+ key => 'site',
+ readOnly => 1) if @sites > 1;
+} elsif ((my $site_id = $ic->get_site_id) || @sites == 1) {
+ $m->comp('/widgets/profile/hidden.mc', value => ($site_id || $sites[0]->get_id), name => 'site_id');
+} else {
+ # Output a list of sites to choose from.
+ $m->comp('/widgets/select_object/select_object.mc',
+ readOnly => ($no_edit || $id),
+ object => 'site',
+ name => 'site_id',
+ field => 'name',
+ disp => 'Site',
+ constrain => { active => 1 },
+ exclude => sub { ! chk_authz($_[0], EDIT, 1) },
+ selected => scalar $c->get_user_cx(get_user_id),
+ reset_key => $id
+ );
+}
+
+$m->comp("/widgets/wrappers/sharky/table_bottom.mc");
+
+# Get the group's membership listed
+$m->comp("/widgets/grp_membership/grp_membership.mc",
+ grp_class => 'Bric::Util::Grp::InputChannel',
+ obj => $ic,
+ formName => 'ic_profile',
+ no_edit => $no_edit,
+ widget => $type,
+ num => 3
+);
+
+# Add the form buttons and other necessities.
+$m->comp("/widgets/profile/formButtons.mc",
+ type => $type,
+ section => $widget,
+ widget => $type,
+ val => $button,
+ no_del => $no_del,
+ no_save => $no_edit
+);
+$m->out("</form>\n");
+$m->comp('/widgets/wrappers/sharky/footer.mc', param => \%ARGS );
+</%perl>
+
+%#-- Once Section --#
+<%once>;
+my $class = "Bric::Biz::InputChannel";
+my $widget = 'profile';
+my $type = 'input_channel';
+my $disp = get_disp_name($type);
+my $ng = Bric::Biz::InputChannel->my_meths->{name}{get_meth};
+my $sg = Bric::Biz::InputChannel->my_meths->{site}{get_meth};
+my $ic_name_getter = sub {
+ my $o = shift;
+ return $ng->($o) . ' (' . $sg->($o) . ')';
+};
+</%once>
+
+%#-- Args Section --#
+<%args>
+$id => undef
+</%args>
+<%doc>
+###############################################################################
+
+=head1 NAME
+
+=head1 VERSION
+
+$LastChangedRevision$
+
+=head1 DATE
+
+$LastChangedDate$
+
+=head1 SYNOPSIS
+
+/admin/profile/input_channel/dhandler - display input channel object profile.
+
+=head1 DESCRIPTION
+
+This element displays input channel object profiles for editing.
+
+=cut
+
+</%doc>
View
5 comp/widgets/wrappers/sharky/sideNav.mc
@@ -8,8 +8,8 @@ my $disp = { map { $_ => get_disp_name($_) }
qw(story media template) };
my $pl_disp = {
map { $_ => get_class_info($_)->get_plural_name }
- qw(story media template pref user grp output_channel contrib
- contrib_type site workflow category element_type
+ qw(story media template pref user grp input_channel output_channel
+ contrib contrib_type site workflow category element_type
media_type source dest job alert_type keyword)
};
@@ -193,6 +193,7 @@ if ( $nav->{adminPublishing} ) { #open publishing submenu
$m->out(qq{<li>} . &$printLink('/admin/manager/contrib', $uri, $pl_disp->{contrib}) . qq{</li>});
$m->out(qq{<li>} . &$printLink('/admin/manager/keyword', $uri, $pl_disp->{keyword}) . qq{</li>});
$m->out(qq{<li>} . &$printLink('/admin/manager/media_type', $uri, $pl_disp->{media_type}) . qq{</li>});
+ $m->out(qq{<li>} . &$printLink('/admin/manager/input_channel', $uri, $pl_disp->{input_channel}) . qq{</li>});
$m->out(qq{<li>} . &$printLink('/admin/manager/output_channel', $uri, $pl_disp->{output_channel}) . qq{</li>});
$m->out(qq{<li>} . &$printLink('/admin/manager/workflow', $uri, $pl_disp->{workflow}) . qq{</li>});
$m->out(qq{<li>} . &$printLink('/admin/manager/source', $uri, $pl_disp->{source}) . qq{</li>});
View
100 lib/Bric/App/Callback/Profile/FormBuilder.pm
@@ -10,6 +10,8 @@ use Bric::App::Event qw(log_event);
use Bric::App::Session qw(:user);
use Bric::App::Util qw(:aref :msg :history :pkg :browser);
use Bric::Biz::ElementType::Parts::FieldType;
+use Bric::Biz::InputChannel;
+use Bric::Biz::InputChannel::Element;
use Bric::Biz::OutputChannel;
use Bric::Biz::OutputChannel::Element;
use Bric::Biz::Site;
@@ -40,10 +42,10 @@ my %conf = (
);
my ($base_handler, $do_contrib_type, $do_element_type, $clean_param,
- $delete_ocs, $delete_sites, $check_save_element_type, $get_obj,
+ $delete_ocs, $delete_ics, $delete_sites, $check_save_element_type, $get_obj,
$set_key_name, $update_element_type_attrs, $get_data_href,
- $delete_element_type_attrs, $set_primary_ocs, $add_new_attrs,
- $save_element_type_etc);
+ $delete_element_type_attrs, $set_primary_ocs, $set_primary_ics,
+ $add_new_attrs, $save_element_type_etc);
sub save : Callback {
@@ -62,6 +64,10 @@ sub addElementType : Callback {
return unless $_[0]->value; # already handled
&$base_handler;
}
+sub add_ic_id : Callback {
+ return unless $_[0]->value; # already handled
+ &$base_handler;
+}
sub add_oc_id : Callback {
return unless $_[0]->value; # already handled
&$base_handler;
@@ -292,9 +298,18 @@ $do_element_type = sub {
$add_new_attrs->($self, $obj, $key, $data_href, \$no_save);
$delete_element_type_attrs->($obj, $param, $key, $cb_key, \%del_attrs, $data_href);
+ $delete_ics->($obj, $param);
$delete_ocs->($obj, $param);
$delete_sites->($obj, $param, $self);
+ # Enable input channels.
+ foreach my $ic ($obj->get_input_channels) {
+ $enabled->{$ic->get_id} ? $ic->set_enabled_on : $ic->set_enabled_off;
+ }
+
+ # Add input channels.
+ $obj->add_input_channel($self->value) if $cb_key eq 'add_ic_id';
+
# Enable output channels.
foreach my $oc ($obj->get_output_channels) {
$enabled->{$oc->get_id} ? $oc->set_enabled_on : $oc->set_enabled_off;
@@ -306,16 +321,21 @@ $do_element_type = sub {
# Add sites, if it's a top-level element type.
if ($cb_key eq 'add_site_id' && $obj->is_top_level) {
my $site_id = $self->value;
- # Only add the site if it has associated output channels.
- if (my $oc_id =
- Bric::Biz::OutputChannel->list_ids({site_id => $site_id })->[0])
- {
+ # Only add the site if it has associated input and output channels.
+ my $ic_id =
+ Bric::Biz::InputChannel->list_ids({site_id => $site_id })->[0];
+ my $oc_id =
+ Bric::Biz::OutputChannel->list_ids({site_id => $site_id })->[0];
+ if ($ic_id && $oc_id) {
$obj->add_site($site_id);
$obj->set_primary_oc_id($oc_id, $site_id);
$obj->add_output_channels($oc_id);
+ $obj->set_primary_ic_id($ic_id, $site_id);
+ $obj->add_input_channels($ic_id);
} else {
add_msg 'Site "[_1]" cannot be associated because it has no ' .
- 'output channels',
+ (!$ic_id ? 'input' : '') . (!$ic_id && !$oc_id ? ' or ' : '') .
+ (!$oc_id ? 'output' : '') . ' channels',
Bric::Biz::Site->lookup({ id => $site_id })->get_name;
}
}
@@ -363,6 +383,16 @@ $clean_param = sub {
return $param;
};
+$delete_ics = sub {
+ my ($obj, $param) = @_;
+
+ # Delete output channels.
+ if ($param->{'rem_ic'}) {
+ my $del_ic_ids = mk_aref($param->{'rem_ic'});
+ $obj->delete_input_channels($del_ic_ids);
+ }
+};
+
$delete_ocs = sub {
my ($obj, $param) = @_;
@@ -463,6 +493,60 @@ $delete_element_type_attrs = sub {
}
};
+
+$set_primary_ics = sub {
+ my ($self, $obj, $no_save) = @_; # $no_save is a scalar ref
+ my $param = $self->params;
+ my $cb_key = $self->cb_key;
+
+ # Determine the enabled input channels.
+ my %enabled = map { $_ ? ( $_ => 1) : () } @{ mk_aref($param->{enabled}) },
+ map { $obj->get_primary_ic_id($_) } $obj->get_sites;
+
+ # Set the primary input channel ID per site
+ if (($cb_key eq 'save' || $cb_key eq 'save_n_stay') && $obj->is_top_level) {
+ # Load up the existing sites and input channels.
+ my %ic_ids = (
+ map { $_ => $obj->get_primary_ic_id($_) }
+ map { $_->get_id }
+ $obj->get_sites
+ );
+
+ foreach my $field (keys %$param) {
+ next unless $field =~ /^primary_ic_site_(\d+)$/;
+ my $siteid = $1;
+ $obj->set_primary_ic_id($param->{$field}, $siteid);
+ my ($ic) = $obj->get_input_channels($param->{$field});
+ unless ($ic) {
+ $obj->add_input_channel($param->{$field});
+ $ic = Bric::Biz::InputChannel->lookup({ id => $param->{$field} });
+ }
+
+ # Associate it with the site and make sure it's enabled.
+ $ic_ids{$siteid} = $param->{$field};
+ $enabled{$ic->get_id} = 1;
+ }
+
+ foreach my $siteid (keys %ic_ids) {
+ unless ($ic_ids{$siteid}) {
+ $$no_save = 1;
+ my $site = Bric::Biz::Site->lookup({id => $siteid});
+ add_msg('Site "[_1]" requires a primary input channel.',
+ $site->get_name);
+ }
+ }
+ } elsif ($cb_key eq 'add_ic_id') {
+ my $ic = Bric::Biz::InputChannel::Element->lookup({id => $self->value});
+ my $siteid = $ic->get_site_id;
+ unless ($obj->get_primary_ic_id($siteid)) {
+ # They're adding the first one. Make it the primary.
+ $obj->set_primary_ic_id($self->value, $siteid);
+ }
+ }
+
+ return \%enabled;
+};
+
$set_primary_ocs = sub {
my ($self, $obj, $no_save) = @_; # $no_save is a scalar ref
my $param = $self->params;
View
89 lib/Bric/App/Callback/Profile/InputChannel.pm
@@ -0,0 +1,89 @@
+package Bric::App::Callback::Profile::InputChannel;
+
+use base qw(Bric::App::Callback::Profile);
+__PACKAGE__->register_subclass;
+use constant CLASS_KEY => 'input_channel';
+
+use strict;
+use Bric::App::Event qw(log_event);
+use Bric::App::Util qw(:aref :msg);
+use Bric::Biz::InputChannel;
+
+my $type = CLASS_KEY;
+my $disp_name = 'Input Channel';
+my $class = 'Bric::Biz::InputChannel';
+
+my ($do_callback);
+
+
+sub save : Callback {
+ return unless $_[0]->has_perms;
+ &$do_callback;
+}
+
+sub include_ic_id : Callback {
+ return unless $_[0]->has_perms && $_[0]->value ne '';
+ &$do_callback;
+}
+
+
+###
+
+$do_callback = sub {
+ my $self = shift;
+ my $param = $self->params;
+ my $ic = $self->obj;
+
+ my $name = $param->{name};
+ my $used;
+
+ if ($param->{delete}) {
+ # Deactivate it.
+ $ic->deactivate;
+ log_event('input_channel_deact', $ic);
+ add_msg("$disp_name profile \"[_1]\" deleted.", $name);
+ $ic->save;
+ $self->set_redirect('/admin/manager/input_channel');
+ } else {
+ my $ic_id = $param->{"${type}_id"};
+ $ic->set_site_id($param->{site_id})
+ if $param->{site_id};
+ # Make sure the name isn't already in use.
+ my @ics = $class->list_ids({ name => $param->{name},
+ site_id => $ic->get_site_id });
+ if (@ics > 1) {
+ $used = 1;
+ } elsif (@ics == 1 && !defined $ic_id) {
+ $used = 1;
+ } elsif (@ics == 1 && defined $ic_id && $ics[0] != $ic_id) {
+ $used = 1;
+ }
+
+ add_msg("The name \"[_1]\" is already used by another $disp_name.", $name) if $used;
+
+ # Set the basic properties.
+ $ic->set_description( $param->{description} );
+ $ic->activate;
+
+ if ($used) {
+ $param->{'obj'} = $ic;
+ return;
+ }
+ $ic->set_name($param->{name});
+
+ $ic->save;
+
+ if ($ic_id) {
+ log_event('input_channel_save', $ic);
+ add_msg("$disp_name profile \"[_1]\" saved.", $name);
+ $self->set_redirect('/admin/manager/input_channel');
+ } else {
+ log_event('input_channel_new', $ic);
+ $param->{'obj'} = $ic;
+ return;
+ }
+ }
+};
+
+
+1;
View
2 lib/Bric/App/Handler.pm
@@ -96,6 +96,7 @@ use Bric::App::Callback::Profile::ElementType;
use Bric::App::Callback::Profile::FieldType;
use Bric::App::Callback::Profile::FormBuilder;
use Bric::App::Callback::Profile::Grp;
+use Bric::App::Callback::Profile::InputChannel;
use Bric::App::Callback::Profile::Job;
use Bric::App::Callback::Profile::Keyword;
use Bric::App::Callback::Profile::Media;
@@ -134,6 +135,7 @@ use MasonX::Interp::WithCallbacks;
use Bric::Biz::Keyword;
use Bric::Biz::Org::Person;
use Bric::Biz::Org::Source;
+ use Bric::Biz::InputChannel;
use Bric::Biz::OutputChannel;
use Bric::Biz::Person;
use Bric::Biz::Person::User;
View
8 lib/Bric/Biz/Asset.pm
@@ -262,7 +262,9 @@ sub lookup {
my $sql = build_query($pkg, $pkg->COLUMNS . $pkg->RO_COLUMNS
. join (', ', '', $pkg->GROUP_COLS), $grp_by,
$tables, $where, $order, @{$param}{qw(Limit Offset)});
- my $fields = [ 'id', $pkg->FIELDS, 'version_id', $pkg->VERSION_FIELDS,
+ my $fields = [ 'id', $pkg->FIELDS,
+ 'version_id', $pkg->VERSION_FIELDS,
+ ($pkg->key_name ne 'template' ? ('instance_id', $pkg->INSTANCE_FIELDS) : ()),
$pkg->RO_FIELDS, 'grp_ids' ];
my @obj = fetch_objects($pkg, $sql, $fields, scalar $pkg->GROUP_COLS, $args);
return unless $obj[0];
@@ -304,7 +306,9 @@ sub list {
my $sql = build_query($pkg, $pkg->COLUMNS . $pkg->RO_COLUMNS
. join (', ', '', $pkg->GROUP_COLS), $grp_by,
$tables, $where, $order, @{$param}{qw(Limit Offset)});
- my $fields = [ 'id', $pkg->FIELDS, 'version_id', $pkg->VERSION_FIELDS,
+ my $fields = [ 'id', $pkg->FIELDS,
+ 'version_id', $pkg->VERSION_FIELDS,
+ ($pkg->key_name ne 'template' ? ('instance_id', $pkg->INSTANCE_FIELDS) : ()),
$pkg->RO_FIELDS, 'grp_ids' ];
my @objs = fetch_objects($pkg, $sql, $fields, scalar $pkg->GROUP_COLS, $args);
return (wantarray ? @objs : \@objs);
View
18 lib/Bric/Biz/Asset/Business.pm
@@ -507,7 +507,7 @@ sub my_meths {
if ($ord) {
return wantarray ? @{$meths}{@ord} : [@{$meths}{@ord}];
} elsif ($ident) {
- return wantarray ? $meths->{version_id} : [$meths->{version_id}];
+ return wantarray ? $meths->{instance_id} : [$meths->{instance_id}];
} else {
return $meths;
}
@@ -2029,8 +2029,8 @@ sub checkout {
$oc_coll->del_objs(@ocs);
$oc_coll->add_new_objs(@ocs);
- $self->_set([qw(user__id modifier version_id checked_out)] =>
- [$param->{user__id}, $param->{user__id}, undef, 1]);
+ $self->_set([qw(user__id modifier version_id instance_id checked_out)] =>
+ [$param->{user__id}, $param->{user__id}, undef, undef, 1]);
$self->_set(['_update_contributors'] => [1]) if $contribs;
}
@@ -2057,9 +2057,9 @@ NONE
sub save {
my $self = shift;
- my ($related_obj, $element, $oc_coll, $ci, $co, $vid, $kw_coll) =
+ my ($related_obj, $element, $oc_coll, $ci, $co, $vid, $iid, $kw_coll) =
$self->_get(qw(_related_grp_obj _element _oc_coll _checkin _checkout
- version_id _kw_coll));
+ version_id instance_id _kw_coll));
if ($co) {
$element->prepare_clone;
@@ -2070,13 +2070,13 @@ sub save {
$self->_set(['_checkin'], []) if $ci;
if ($element) {
- $element->set_object_instance_id($vid);
+ $element->set_object_instance_id($iid);
$element->save;
}
$related_obj->save if $related_obj;
$self->_sync_contributors;
- $oc_coll->save($self->key_name => $vid) if $oc_coll;
+ $oc_coll->save($self->key_name => $iid) if $oc_coll;
$kw_coll->save($self) if $kw_coll;
$self->SUPER::save;
}
@@ -2472,7 +2472,7 @@ sub _sync_contributors {
return $self unless $self->_get('_update_contributors');
my $contribs = $self->_get_contributors();
- my ($del_contribs, $vid) = $self->_get(qw(_del_contrib version_id));
+ my ($del_contribs, $vid) = $self->_get(qw(_del_contrib instance_id));
foreach (keys %$del_contribs) {
$self->_delete_contributor($_);
@@ -2679,7 +2679,7 @@ B<Notes:> NONE.
$get_oc_coll = sub {
my $self = shift;
my $dirt = $self->_get__dirty;
- my ($id, $oc_coll) = $self->_get('version_id', '_oc_coll');
+ my ($id, $oc_coll) = $self->_get('instance_id', '_oc_coll');
return $oc_coll if $oc_coll;
$oc_coll = Bric::Util::Coll::OutputChannel->new
(defined $id ? {$self->key_name . '_instance_id' => $id} : undef);
View
251 lib/Bric/Biz/Asset/Business/Media.pm
@@ -80,7 +80,9 @@ use constant DEBUG => 0;
use constant TABLE => 'media';
-use constant VERSION_TABLE => 'media_instance';
+use constant VERSION_TABLE => 'media_version';
+
+use constant INSTANCE_TABLE => 'media_instance';
use constant ID_COL => 'mt.id';
@@ -101,21 +103,23 @@ use constant COLS => qw( uuid
site__id
alias_id);
-use constant VERSION_COLS => qw( name
- description
- media__id
+use constant VERSION_COLS => qw( media__id
usr__id
version
+ cover_date
+ note
+ checked_out
+ uri
+ category__id );
+
+use constant INSTANCE_COLS => qw( media_version__id
+ name
+ description
media_type__id
primary_oc__id
- category__id
file_size
file_name
- location
- uri
- cover_date
- note
- checked_out);
+ location );
use constant FIELDS => qw( uuid
element_type_id
@@ -134,21 +138,23 @@ use constant FIELDS => qw( uuid
site_id
alias_id);
-use constant VERSION_FIELDS => qw( name
- description
- id
+use constant VERSION_FIELDS => qw( id
modifier
version
+ cover_date
+ note
+ checked_out
+ uri
+ category__id );
+
+use constant INSTANCE_FIELDS => qw( version_id
+ name
+ description
media_type_id
primary_oc_id
- category__id
size
file_name
- location
- uri
- cover_date
- note
- checked_out);
+ location );
use constant RO_FIELDS => qw( class_id );
use constant RO_COLUMNS => ', e.biz_class__id';
@@ -167,21 +173,23 @@ use constant GROUP_COLS => ('id_list(DISTINCT m.grp__id) AS grp_id',
'id_list(DISTINCT w.asset_grp_id) AS wf_grp_id');
# the mapping for building up the where clause based on params
-use constant WHERE => 'mt.id = i.media__id '
+use constant WHERE => 'mt.id = v.media__id '
+ . 'AND v.id = i.media_version__id '
. 'AND mm.object_id = mt.id '
. 'AND m.id = mm.member__id '
. "AND m.active = '1' "
- . 'AND c.id = i.category__id '
+ . 'AND c.id = v.category__id '
. 'AND e.id = mt.element_type__id '
. 'AND mt.workflow__id = w.id';
use constant COLUMNS => join(', mt.', 'mt.id', COLS) . ', '
- . join(', i.', 'i.id', VERSION_COLS);
+ . join(', v.', 'v.id', VERSION_COLS) . ', '
+ . join(', i.', 'i.id', INSTANCE_COLS);
use constant OBJECT_SELECT_COLUMN_NUMBER => scalar COLS + 1;
# param mappings for the big select statement
-use constant FROM => VERSION_TABLE . ' i';
+use constant FROM => VERSION_TABLE . ' v, ' . INSTANCE_TABLE . ' i';
use constant PARAM_FROM_MAP => {
keyword => 'media_keyword mk, keyword k',
@@ -194,7 +202,7 @@ use constant PARAM_FROM_MAP => {
related_story_id => 'media_element mctrs',
related_media_id => 'media_element mctrm',
contrib_id => 'media__contributor sic',
- note => 'media_instance mmi2',
+ note => 'media_version mmv2',
uri => 'media_uri uri',
};
@@ -215,7 +223,8 @@ use constant PARAM_WHERE_MAP => {
element_type_id => 'mt.element_type__id = ?',
element__id => 'mt.element_type__id = ?',
element_id => 'mt.element_type__id = ?',
- version_id => 'i.id = ?',
+ version_id => 'v.id = ?',
+ instance_id => 'i.id = ?',
element_key_name => 'mt.element_type__id = e.id AND LOWER(e.key_name) LIKE LOWER(?)',
source__id => 'mt.source__id = ?',
source_id => 'mt.source__id = ?',
@@ -225,8 +234,8 @@ use constant PARAM_WHERE_MAP => {
first_publish_date_end => 'mt.publish_date <= ?',
publish_date_start => 'mt.publish_date >= ?',
publish_date_end => 'mt.publish_date <= ?',
- cover_date_start => 'i.cover_date >= ?',
- cover_date_end => 'i.cover_date <= ?',
+ cover_date_start => 'v.cover_date >= ?',
+ cover_date_end => 'v.cover_date <= ?',
expire_date_start => 'mt.expire_date >= ?',
expire_date_end => 'mt.expire_date <= ?',
unexpired => '(mt.expire_date IS NULL OR mt.expire_date > CURRENT_TIMESTAMP)',
@@ -238,49 +247,50 @@ use constant PARAM_WHERE_MAP => {
data_text => 'LOWER(md.short_val) LIKE LOWER(?) AND md.object_instance_id = i.id',
title => 'LOWER(i.name) LIKE LOWER(?)',
description => 'LOWER(i.description) LIKE LOWER(?)',
- version => 'i.version = ?',
- published_version => "mt.published_version = i.version AND i.checked_out = '0'",
- user__id => 'i.usr__id = ?',
- user_id => 'i.usr__id = ?',
+ version => 'v.version = ?',
+ published_version => "mt.published_version = v.version AND v.checked_out = '0'",
+ user__id => 'v.usr__id = ?',
+ user_id => 'v.usr__id = ?',
uri => 'mt.id = uri.media__id AND LOWER(uri.uri) LIKE LOWER(?)',
file_name => 'LOWER(i.file_name) LIKE LOWER(?)',
location => 'LOWER(i.location) LIKE LOWER(?)',
- _checked_in_or_out => 'i.checked_out = '
+ _checked_in_or_out => 'v.checked_out = '
. '( SELECT checked_out '
- . 'FROM media_instance '
- . 'WHERE version = i.version '
- . 'AND media__id = i.media__id '
+ . 'FROM media_version '
+ . 'WHERE version = v.version '
+ . 'AND media__id = v.media__id '
. 'ORDER BY checked_out DESC LIMIT 1 )',
- checked_in => 'i.checked_out = '
+ checked_in => 'v.checked_out = '
. '( SELECT checked_out '
- . 'FROM media_instance '
- . 'WHERE version = i.version '
- . 'AND media__id = i.media__id '
+ . 'FROM media_version '
+ . 'WHERE version = v.version '
+ . 'AND media__id = v.media__id '
. 'ORDER BY checked_out ASC LIMIT 1 )',
- _checked_out => 'i.checked_out = ?',
- checked_out => 'i.checked_out = ?',
- _not_checked_out => "i.checked_out = '0' AND mt.id not in "
- . '(SELECT media__id FROM media_instance '
- . 'WHERE mt.id = media_instance.media__id '
- . "AND media_instance.checked_out = '1')",
+ _checked_out => 'v.checked_out = ?',
+ checked_out => 'v.checked_out = ?',
+ _not_checked_out => "v.checked_out = '0' AND mt.id not in "
+ . '(SELECT media__id FROM media_version '
+ . 'WHERE mt.id = media_version.media__id '
+ . "AND media_version.checked_out = '1')",
primary_oc_id => 'i.primary_oc__id = ?',
output_channel_id => '(i.id = moc.media_instance__id AND '
. 'moc.output_channel__id = ?)',
- category__id => 'i.category__id = ?',
- category_id => 'i.category__id = ?',
- category_uri => 'i.category__id = c.id AND '
+ category__id => 'v.category__id = ?',
+ category_id => 'v.category__id = ?',
+ category_uri => 'v.category__id = c.id AND '
. 'LOWER(c.uri) LIKE LOWER(?)',
keyword => 'mk.media_id = mt.id AND '
. 'k.id = mk.keyword_id AND '
. 'LOWER(k.name) LIKE LOWER(?)',
- _no_return_versions => 'mt.current_version = i.version',
+ _no_return_versions => 'mt.current_version = v.version',
grp_id => 'm2.grp__id = ? AND '
. "m2.active = '1' AND "
. 'mm2.member__id = m2.id AND '
. 'mt.id = mm2.object_id',
simple => 'mt.id IN ('
. 'SELECT mmt.id FROM media mmt '
- . 'JOIN media_instance mi2 ON media__id = mmt.id '
+ . 'JOIN media_version mv2 ON media__id = mmt.id '
+ . 'JOIN media_instance mi2 ON media_version__id = mv2.id '
. 'WHERE LOWER(mi2.name) LIKE LOWER(?) '
. 'OR LOWER(mi2.description) LIKE LOWER(?) '
. 'OR LOWER(mi2.uri) LIKE LOWER(?) '
@@ -288,7 +298,7 @@ use constant PARAM_WHERE_MAP => {
. 'JOIN keyword kk ON (kk.id = keyword_id) '
. 'WHERE LOWER(kk.name) LIKE LOWER(?))',
contrib_id => 'i.id = sic.media_instance__id AND sic.member__id = ?',
- note => 'mmi2.media__id = mt.id AND LOWER(mmi2.note) LIKE LOWER(?)',
+ note => 'mmv2.media__id = mt.id AND LOWER(mmv2.note) LIKE LOWER(?)',
};
use constant PARAM_ANYWHERE_MAP => {
@@ -304,7 +314,7 @@ use constant PARAM_ANYWHERE_MAP => {
'LOWER(md.short_val) LIKE LOWER(?)' ],
output_channel_id => [ 'i.id = moc.media_instance__id',
'moc.output_channel__id = ?' ],
- category_uri => [ 'i.category__id = c.id',
+ category_uri => [ 'v.category__id = c.id',
'LOWER(c.uri) LIKE LOWER(?)' ],
keyword => [ 'mk.media_id = mt.id AND k.id = mk.keyword_id',
'LOWER(k.name) LIKE LOWER(?)' ],
@@ -312,8 +322,8 @@ use constant PARAM_ANYWHERE_MAP => {
'm2.grp__id = ?' ],
contrib_id => [ 'i.id = sic.media_instance__id',
'sic.member__id = ?' ],
- note => [ 'mmi2.media__id = mt.id',
- 'LOWER(mmi2.note) LIKE LOWER(?)'],
+ note => [ 'mmv2.media__id = mt.id',
+ 'LOWER(mmv2.note) LIKE LOWER(?)'],
uri => [ 'mt.id = uri.media__id',
'LOWER(uri.uri) LIKE LOWER(?)'],
@@ -337,23 +347,24 @@ use constant PARAM_ORDER_MAP => {
publish_status => 'mt.publish_status',
first_publish_date => 'mt.first_publish_date',
publish_date => 'mt.publish_date',
- cover_date => 'i.cover_date',
+ cover_date => 'v.cover_date',
expire_date => 'mt.expire_date',
name => 'LOWER(i.name)',
title => 'LOWER(i.name)',
file_name => 'LOWER(i.file_name)',
location => 'LOWER(i.location)',
- category_id => 'i.category__id',
- category__id => 'i.category__id',
+ category_id => 'v.category__id',
+ category__id => 'v.category__id',
description => 'LOWER(i.description)',
- version => 'i.version',
- version_id => 'i.id',
- user__id => 'i.usr__id',
- _checked_out => 'i.checked_out',
+ version => 'v.version',
+ version_id => 'v.id',
+ instance_id => 'i.id',
+ user__id => 'v.usr__id',
+ _checked_out => 'v.checked_out',
primary_oc_id => 'i.primary_oc__id',
- category_uri => 'LOWER(i.uri)',
+ category_uri => 'LOWER(v.uri)',
keyword => 'LOWER(k.name)',
- return_versions => 'i.version',
+ return_versions => 'v.version',
};
use constant DEFAULT_ORDER => 'cover_date';
@@ -555,6 +566,11 @@ The media document version number. May use C<ANY> for a list of possible values.
The ID of a version of a media document. May use C<ANY> for a list of possible
values.
+=item instance_id
+
+The ID of an instance of a media document. May use C<ANY> for a list of possible
+values.
+
=item file_name
The media document file name. May use C<ANY> for a list of possible values.
@@ -1790,6 +1806,7 @@ sub clone {
}
$self->_set( { version_id => undef,
+ instance_id => undef,
id => undef,
first_publish_date => undef,
publish_date => undef,
@@ -1830,7 +1847,7 @@ sub save {
if ($self->_get('version_id')) {
if ($self->_get('_cancel')) {
- $self->_delete_instance();
+ $self->_delete_version();
if ($self->_get('version') == 0) {
$self->_delete_media();
}
@@ -1838,9 +1855,11 @@ sub save {
commit();
return $self;
} else {
+ $self->_update_version();
$self->_update_instance();
}
} else {
+ $self->_insert_version();
$self->_insert_instance();
}
} else {
@@ -1850,6 +1869,7 @@ sub save {
return $self;
} else {
$self->_insert_media();
+ $self->_insert_version();
$self->_insert_instance();
}
}
@@ -1923,7 +1943,7 @@ sub _get_contributors {
'WHERE media_instance__id=? ';
my $sth = prepare_ca($sql, undef);
- execute($sth, $self->_get('version_id'));
+ execute($sth, $self->_get('instance_id'));
while (my $row = fetch($sth)) {
$contrib->{$row->[0]}->{'role'} = $row->[2];
$contrib->{$row->[0]}->{'place'} = $row->[1];
@@ -1959,7 +1979,7 @@ sub _insert_contributor {
" VALUES (${\next_key('media__contributor')},?,?,?,?) ";
my $sth = prepare_c($sql, undef);
- execute($sth, $self->_get('version_id'), $id, $place, $role);
+ execute($sth, $self->_get('instance_id'), $id, $place, $role);
return $self;
}
@@ -1985,7 +2005,7 @@ sub _update_contributor {
' AND member__id=? ';
my $sth = prepare_c($sql, undef);
- execute($sth, $role, $place, $self->_get('version_id'), $id);
+ execute($sth, $role, $place, $self->_get('instance_id'), $id);
return $self;
}
@@ -2011,7 +2031,7 @@ sub _delete_contributor {
' AND member__id=? ';
my $sth = prepare_c($sql, undef);
- execute($sth, $self->_get('version_id'), $id);
+ execute($sth, $self->_get('instance_id'), $id);
return $self;
}
@@ -2112,9 +2132,9 @@ sub _update_media {
################################################################################
-=item $self = $self->_insert_instance()
+=item $self = $self->_insert_version()
-Preforms the sql that inserts a record into the media instance table
+Preforms the sql that inserts a record into the media version table
B<Throws:> NONE.
@@ -2124,7 +2144,7 @@ B<Notes:> NONE.
=cut
-sub _insert_instance {
+sub _insert_version {
my $self = shift;
my $sql = 'INSERT INTO '. VERSION_TABLE .
@@ -2140,9 +2160,9 @@ sub _insert_instance {
################################################################################
-=item $self = $self->_update_instance()
+=item $self = $self->_insert_instance()
-Preforms the sql that updates the media_instance table
+Preforms the sql that inserts a record into the media instance table
B<Throws:> NONE.
@@ -2152,7 +2172,35 @@ B<Notes:> NONE.
=cut
-sub _update_instance {
+sub _insert_instance {
+ my $self = shift;
+
+ my $sql = 'INSERT INTO '. INSTANCE_TABLE .
+ ' (id, '.join(', ', INSTANCE_COLS) . ')' .
+ " VALUES (${\next_key(INSTANCE_TABLE)}, ".
+ join(', ', ('?') x INSTANCE_COLS) . ')';
+
+ my $sth = prepare_c($sql, undef);
+ execute($sth, $self->_get(INSTANCE_FIELDS));
+ $self->_set( { instance_id => last_key(INSTANCE_TABLE) });
+ return $self;
+}
+
+################################################################################
+
+=item $self = $self->_update_version()
+
+Preforms the sql that updates the media_version table
+
+B<Throws:> NONE.
+
+B<Side Effects:> NONE.
+
+B<Notes:> NONE.
+
+=cut
+
+sub _update_version {
my $self = shift;
my $sql = 'UPDATE ' . VERSION_TABLE .
@@ -2166,6 +2214,32 @@ sub _update_instance {
################################################################################
+=item $self = $self->_update_instance()
+
+Preforms the sql that updates the media_instance table
+
+B<Throws:> NONE.
+
+B<Side Effects:> NONE.
+
+B<Notes:> NONE.
+
+=cut
+
+sub _update_instance {
+ my $self = shift;
+
+ my $sql = 'UPDATE ' . INSTANCE_TABLE .
+ ' SET ' . join(', ', map {"$_=?" } INSTANCE_COLS) .
+ ' WHERE id=? ';
+
+ my $sth = prepare_c($sql, undef);
+ execute($sth, $self->_get(INSTANCE_FIELDS), $self->_get('instance_id'));
+ return $self;
+}
+
+################################################################################
+
=item $self = $self->_delete_media()
Removes the media row from the database
@@ -2191,6 +2265,31 @@ sub _delete_media {
################################################################################
+=item $self = $self->_delete_version()
+
+Removes the version row from the database
+
+B<Throws:> NONE.
+
+B<Side Effects:> NONE.
+
+B<Notes:> NONE.
+
+=cut
+
+sub _delete_version {
+ my $self = shift;
+
+ my $sql = 'DELETE FROM ' . VERSION_TABLE .
+ ' WHERE id=? ';
+
+ my $sth = prepare_c($sql, undef);
+ execute($sth, $self->_get('version_id'));
+ return $self;
+}
+
+################################################################################
+
=item $self = $self->_delete_instance()
Removes the instance row from the database
@@ -2206,11 +2305,11 @@ B<Notes:> NONE.
sub _delete_instance {
my $self = shift;
- my $sql = 'DELETE FROM ' . VERSION_TABLE .
+ my $sql = 'DELETE FROM ' . INSTANCE_TABLE .
' WHERE id=? ';
my $sth = prepare_c($sql, undef);
- execute($sth, $self->_get('version_id'));
+ execute($sth, $self->_get('instance_id'));
return $self;
}
View
291 lib/Bric/Biz/Asset/Business/Story.pm
@@ -32,7 +32,7 @@ $LastChangedDate$
# General information
$asset = $asset->get_id()
- $asset = $asset->set_description($description)
+ $asset = $asset->set_description($description)`
$description = $asset->get_description()
# User information
@@ -192,7 +192,9 @@ use constant DEBUG => 0;
use constant TABLE => 'story';
-use constant VERSION_TABLE => 'story_instance';
+use constant VERSION_TABLE => 'story_version';
+
+use constant INSTANCE_TABLE => 'story_instance';
use constant ID_COL => 's.id';
@@ -214,16 +216,18 @@ use constant COLS => qw( uuid
site__id
alias_id);
-use constant VERSION_COLS => qw( name
+use constant VERSION_COLS => qw( story__id
+ version
+ usr__id
+ note
+ checked_out
+ cover_date );
+
+use constant INSTANCE_COLS => qw( name
description
- story__id
- version
- usr__id
+ story_version__id
primary_oc__id
- slug
- cover_date
- note
- checked_out);
+ slug );
use constant FIELDS => qw( uuid
priority
@@ -243,16 +247,18 @@ use constant FIELDS => qw( uuid
site_id
alias_id);
-use constant VERSION_FIELDS => qw( name
+use constant VERSION_FIELDS => qw( id
+ version
+ modifier
+ note
+ checked_out
+ cover_date );
+
+use constant INSTANCE_FIELDS => qw( name
description
- id
- version
- modifier
+ version_id
primary_oc_id
- slug
- cover_date
- note
- checked_out);
+ slug );
use constant AD_PARAM => '_AD_PARAM';
use constant GROUP_PACKAGE => 'Bric::Util::Grp::Story';
@@ -267,21 +273,23 @@ use constant GROUP_COLS => ('id_list(DISTINCT m.grp__id) AS grp_id',
'id_list(DISTINCT w.asset_grp_id) AS wf_grp_id');
# the mapping for building up the where clause based on params
-use constant WHERE => 's.id = i.story__id '
+use constant WHERE => 's.id = v.story__id '
+ . 'AND v.id = i.story_version__id '
. 'AND sm.object_id = s.id '
. 'AND m.id = sm.member__id '
. "AND m.active = '1' "
- . 'AND sc.story_instance__id = i.id '
+ . 'AND sc.story_version__id = v.id '
. 'AND c.id = sc.category__id '
. 'AND s.workflow__id = w.id';
use constant COLUMNS => join(', s.', 's.id', COLS) . ', '
- . join(', i.', 'i.id', VERSION_COLS);
+ . join(', v.', 'v.id', VERSION_COLS) . ', '
+ . join(', i.', 'i.id', INSTANCE_COLS);
use constant OBJECT_SELECT_COLUMN_NUMBER => scalar COLS + 1;
# param mappings for the big select statement
-use constant FROM => VERSION_TABLE . ' i';
+use constant FROM => VERSION_TABLE . ' v, ' . INSTANCE_TABLE . ' i';
use constant PARAM_FROM_MAP => {
keyword => 'story_keyword sk, keyword k',
@@ -299,7 +307,7 @@ use constant PARAM_FROM_MAP => {
subelement_key_name => 'story_element sct',
related_story_id => 'story_element sctrs',
related_media_id => 'story_element sctrm',
- note => 'story_instance si2',
+ note => 'story_version sv2',
uri => 'story_uri uri',
};
@@ -314,7 +322,8 @@ use constant PARAM_WHERE_MAP => {
alias_id => 's.alias_id = ?',
site_id => 's.site__id = ?',
no_site_id => 's.site__id <> ?',
- version_id => 'i.id = ?',
+ version_id => 'v.id = ?',
+ instance_id => 'i.id = ?',
workflow__id => 's.workflow__id = ?',
workflow_id => 's.workflow__id = ?',
_null_workflow_id => 's.workflow__id IS NULL',
@@ -332,8 +341,8 @@ use constant PARAM_WHERE_MAP => {
first_publish_date_end => 's.first_publish_date <= ?',
publish_date_start => 's.publish_date >= ?',
publish_date_end => 's.publish_date <= ?',
- cover_date_start => 'i.cover_date >= ?',
- cover_date_end => 'i.cover_date <= ?',
+ cover_date_start => 'v.cover_date >= ?',
+ cover_date_end => 'v.cover_date <= ?',
expire_date_start => 's.expire_date >= ?',
expire_date_end => 's.expire_date <= ?',
unexpired => '(s.expire_date IS NULL OR s.expire_date > CURRENT_TIMESTAMP)',
@@ -345,66 +354,67 @@ use constant PARAM_WHERE_MAP => {
data_text => 'LOWER(sd.short_val) LIKE LOWER(?) AND sd.object_instance_id = i.id',
title => 'LOWER(i.name) LIKE LOWER(?)',
description => 'LOWER(i.description) LIKE LOWER(?)',
- version => 'i.version = ?',
- published_version => "s.published_version = i.version AND i.checked_out = '0'",
+ version => 'v.version = ?',
+ published_version => "s.published_version = v.version AND v.checked_out = '0'",
slug => 'LOWER(i.slug) LIKE LOWER(?)',
- user__id => 'i.usr__id = ?',
- user_id => 'i.usr__id = ?',
- _checked_in_or_out => 'i.checked_out = '
+ user__id => 'v.usr__id = ?',
+ user_id => 'v.usr__id = ?',
+ _checked_in_or_out => 'v.checked_out = '
. '( SELECT checked_out '
- . 'FROM story_instance '
- . 'WHERE version = i.version '
- . 'AND story__id = i.story__id '
+ . 'FROM story_version '
+ . 'WHERE version = v.version '
+ . 'AND story__id = v.story__id '
. 'ORDER BY checked_out DESC LIMIT 1 )',
- checked_in => 'i.checked_out = '
+ checked_in => 'v.checked_out = '
. '( SELECT checked_out '
- . 'FROM story_instance '
- . 'WHERE version = i.version '
- . 'AND story__id = i.story__id '
+ . 'FROM story_version '
+ . 'WHERE version = v.version '
+ . 'AND story__id = v.story__id '
. 'ORDER BY checked_out ASC LIMIT 1 )',
- _checked_out => 'i.checked_out = ?',
- checked_out => 'i.checked_out = ?',
- _not_checked_out => "i.checked_out = '0' AND s.id not in "
- . '(SELECT story__id FROM story_instance '
- . 'WHERE s.id = story_instance.story__id '
- . "AND story_instance.checked_out = '1')",
+ _checked_out => 'v.checked_out = ?',
+ checked_out => 'v.checked_out = ?',
+ _not_checked_out => "v.checked_out = '0' AND s.id not in "
+ . '(SELECT story__id FROM story_version '
+ . 'WHERE s.id = story_version.story__id '
+ . "AND story_version.checked_out = '1')",
primary_oc_id => 'i.primary_oc__id = ?',
output_channel_id => '(i.id = soc.story_instance__id AND '
. '(soc.output_channel__id = ? OR '
. 'i.primary_oc__id = ?))',
- category_id => 'i.id = sc2.story_instance__id AND '
+ category_id => 'v.id = sc2.story_version__id AND '
. 'sc2.category__id = ?',
- primary_category_id => 'i.id = sc2.story_instance__id AND '
+ primary_category_id => 'v.id = sc2.story_version__id AND '
. "sc2.category__id = ? AND sc2.main = '1'",
- category_uri => 'i.id = sc2.story_instance__id AND '
+ category_uri => 'v.id = sc2.story_version__id AND '
. 'sc2.category__id = c.id AND '
. 'LOWER(c.uri) LIKE LOWER(?)',
'story.category' => 's.id <> ? '
- . 'AND i.id = sc2.story_instance__id AND '
+ . 'AND v.id = sc2.story_version__id AND '
. 'sc2.category__id in ('
. 'SELECT sc3.category__id '
- . 'FROM story__category sc3, story s2, story_instance i2 '
- . 'WHERE i2.story__id = s2.id '
- . 'AND i2.version = s2.current_version '
- . 'AND i2.checked_out =('
+ . 'FROM story__category sc3, story s2, story_version v2 '
+ . 'WHERE v2.story__id = s2.id '
+ . 'AND v2.version = s2.current_version '
+ . 'AND v2.checked_out =('
. '( SELECT checked_out '
- . 'FROM story_instance '
- . 'WHERE version = i2.version '
+ . 'FROM story_version '
+ . 'WHERE version = v2.version '
. 'AND story__id = s2.id '
- . 'AND sc3.story_instance__id = i2.id '
+ . 'AND sc3.story_version__id = v2.id '
. 'AND s2.id = ? '
. 'ORDER BY checked_out DESC LIMIT 1 )',
keyword => 'sk.story_id = s.id AND '
. 'k.id = sk.keyword_id AND '
. 'LOWER(k.name) LIKE LOWER(?)',
- _no_return_versions => 's.current_version = i.version',
+ _no_return_versions => 's.current_version = v.version',
grp_id => 'm2.grp__id = ? AND '
. "m2.active = '1' AND "
. 'sm2.member__id = m2.id AND '
. 's.id = sm2.object_id',
simple => 's.id IN ('
. 'SELECT ss.id FROM story ss '
- . 'JOIN story_instance si2 ON story__id = ss.id '
+ . 'JOIN story_version sv2 ON story_id = ss.id '
+ . 'JOIN story_instance si2 ON story_version__id = sv2.id '
. 'WHERE LOWER(si2.name) LIKE LOWER(?) '
. 'OR LOWER(si2.description) LIKE LOWER(?) '
. 'OR LOWER(ss.primary_uri) LIKE LOWER(?) '
@@ -412,7 +422,7 @@ use constant PARAM_WHERE_MAP => {
. 'JOIN keyword kk ON (kk.id = keyword_id) '
. 'WHERE LOWER(kk.name) LIKE LOWER(?))',
contrib_id => 'i.id = sic.story_instance__id AND sic.member__id = ?',
- note => 'si2.story__id = s.id AND LOWER(si2.note) LIKE LOWER(?)',
+ note => 'sv2.story__id = s.id AND LOWER(sv2.note) LIKE LOWER(?)',
};
use constant PARAM_ANYWHERE_MAP => {
@@ -428,13 +438,13 @@ use constant PARAM_ANYWHERE_MAP => {
'LOWER(sd.short_val) LIKE LOWER(?)' ],
output_channel_id => [ 'i.id = soc.story_instance__id',
'soc.output_channel__id = ?' ],
- category_id => [ 'i.id = sc2.story_instance__id',
+ category_id => [ 'v.id = sc2.story_version__id',
'sc2.category__id = ?' ],
- primary_category_id => [ "i.id = sc2.story_instance__id AND sc2.main = '1'",
+ primary_category_id => [ "v.id = sc2.story_version__id AND sc2.main = '1'",
'sc2.category__id = ?' ],
uri => [ 's.id = uri.story__id',
'LOWER(uri.uri) LIKE LOWER(?)' ],
- category_uri => [ 'i.id = sc2.story_instance__id AND sc2.category__id = c.id',
+ category_uri => [ 'v.id = sc2.story_version__id AND sc2.category__id = c.id',
'LOWER(c.uri) LIKE LOWER(?)' ],
keyword => [ 'sk.story_id = s.id AND k.id = sk.keyword_id',
'LOWER(k.name) LIKE LOWER(?)' ],
@@ -442,8 +452,8 @@ use constant PARAM_ANYWHERE_MAP => {
'm2.grp__id = ?' ],
contrib_id => [ 'i.id = sic.story_instance__id',
'sic.member__id = ?' ],
- note => [ 'si2.story__id = s.id',
- 'LOWER(si2.note) LIKE LOWER(?)'],
+ note => [ 'sv2.story__id = s.id',
+ 'LOWER(sv2.note) LIKE LOWER(?)'],
};
use constant PARAM_ORDER_MAP => {
@@ -464,22 +474,23 @@ use constant PARAM_ORDER_MAP => {
publish_status => 's.publish_status',
first_publish_date => 's.first_publish_date',
publish_date => 's.publish_date',
- cover_date => 'i.cover_date',
+ cover_date => 'v.cover_date',
expire_date => 's.expire_date',
name => 'LOWER(i.name)',
title => 'LOWER(i.name)',
description => 'LOWER(i.description)',
- version => 'i.version',
- version_id => 'i.id',
+ version => 'v.version',
+ version_id => 'v.id',
+ instance_id => 'i.id',
slug => 'LOWER(i.slug)',
- user_id => 'i.usr__id',
- user__id => 'i.usr__id',
- _checked_out => 'i.checked_out',
+ user_id => 'v.usr__id',
+ user__id => 'v.usr__id',
+ _checked_out => 'v.checked_out',
primary_oc_id => 'i.primary_oc__id',
category_id => 'sc2.category_id',
category_uri => 'LOWER(c.uri)',
keyword => 'LOWER(k.name)',
- return_versions => 'i.version',
+ return_versions => 'v.version',
};
use constant DEFAULT_ORDER => 'cover_date';
@@ -679,6 +690,10 @@ The story version number. May use C<ANY> for a list of possible values.
The ID of a version of a story. May use C<ANY> for a list of possible values.
+=item instance_id
+
+The ID of an instance of a story. May use C<ANY> for a list of possible values.
+
=item slug
The story slug. May use C<ANY> for a list of possible values.
@@ -1812,11 +1827,11 @@ sub clone {
# Reset properties. Note that if we start to make use of the attribute
# object other than for desks, we'll have to find a way to clone it, too.
- $self->_set([qw(version current_version version_id id publish_date
+ $self->_set([qw(version current_version version_id instance_id id publish_date
publish_status _update_contributors _queried_cats
_attribute_object _update_uri first_publish_date
published_version uuid)],
- [0, 0, undef, undef, undef, 0, 1, 0, undef, 1, undef, undef,
+ [0, 0, undef, undef, undef, undef, 0, 1, 0, undef, 1, undef, undef,
$ug->create_str
]);
@@ -1866,7 +1881,7 @@ sub save {
$self->_update_story();
if ($self->_get('version_id')) {
if ($self->_get('_cancel')) {
- $self->_delete_instance();
+ $self->_delete_version();
if ($self->_get('version') == 0) {
$self->_delete_story();
}
@@ -1874,9 +1889,11 @@ sub save {
commit();
return $self;
} else {
+ $self->_update_version();
$self->_update_instance();
}
} else {
+ $self->_insert_version();
$self->_insert_instance();
}
} else {
@@ -1886,6 +1903,7 @@ sub save {
} else {
# This is Brand new insert both Tables
$self->_insert_story();
+ $self->_insert_version();
$self->_insert_instance();
}
}
@@ -1960,7 +1978,7 @@ sub _get_contributors {
'WHERE story_instance__id=? ';
my $sth = prepare_ca($sql, undef);
- execute($sth, $self->_get('version_id'));
+ execute($sth, $self->_get('instance_id'));
while (my $row = fetch($sth)) {
$contrib->{$row->[0]}->{'role'} = $row->[2];
$contrib->{$row->[0]}->{'place'} = $row->[1];
@@ -2001,7 +2019,7 @@ sub _insert_contributor {
" VALUES (${\next_key('story__contributor')},?,?,?,?) ";
my $sth = prepare_c($sql, undef);
- execute($sth, $self->_get('version_id'), $id, $place, $role);
+ execute($sth, $self->_get('instance_id'), $id, $place, $role);
return $self;
}
@@ -2033,7 +2051,7 @@ sub _update_contributor {
' AND member__id=? ';
my $sth = prepare_c($sql, undef);
- execute($sth, $role, $place, $self->_get('version_id'), $id);
+ execute($sth, $role, $place, $self->_get('instance_id'), $id);
return $self;
}
@@ -2064,7 +2082,7 @@ sub _delete_contributor {
' AND member__id=? ';
my $sth = prepare_c($sql, undef);
- execute($sth, $self->_get('version_id'), $id);
+ execute($sth, $self->_get('instance_id'), $id);
return $self;
}
@@ -2096,7 +2114,7 @@ sub _get_categories {
my $dirty = $self->_get__dirty();
my $sql = 'SELECT category__id, main '.
"FROM story__category ".
- " WHERE story_instance__id=? ";
+ " WHERE story_version__id=? ";
my $sth = prepare_ca($sql, undef);
execute($sth, $self->_get('version_id'));
@@ -2181,7 +2199,7 @@ NONE
sub _insert_category {
my ($self, $category_id,$primary) = @_;
my $sql = "INSERT INTO story__category ".
- "(id, story_instance__id, category__id, main) ".
+ "(id, story_version__id, category__id, main) ".
"VALUES (${\next_key('story__category')},?,?,?)";
my $sth = prepare_c($sql, undef);
@@ -2212,7 +2230,7 @@ NONE
sub _delete_category {
my ($self, $category_id) = @_;
my $sql = "DELETE FROM story__category ".
- "WHERE story_instance__id=? AND category__id=? ";
+ "WHERE story_version__id=? AND category__id=? ";
my $sth = prepare_c($sql, undef);
execute($sth, $self->_get('version_id'), $category_id);
@@ -2243,7 +2261,7 @@ sub _update_category {
my ($self, $category_id,$primary) = @_;
my $sql = "UPDATE story__category ".
"SET main=? ".
- "WHERE story_instance__id=? AND category__id=? ";
+ "WHERE story_version__id=? AND category__id=? ";
my $sth = prepare_c($sql, undef);
execute($sth, $primary, $self->_get('version_id'), $category_id);
@@ -2323,9 +2341,9 @@ sub _insert_story {
################################################################################
-=item $self = $self->_insert_instance()
+=item $self = $self->_insert_version()
-Inserts an instance record into the database
+Inserts a version record into the database
B<Throws:>
@@ -2341,7 +2359,7 @@ NONE
=cut
-sub _insert_instance {
+sub _insert_version {
my ($self) = @_;
my $sql = 'INSERT INTO '. VERSION_TABLE .
' (id, '.join(', ', VERSION_COLS) . ')'.
@@ -2356,6 +2374,39 @@ sub _insert_instance {
################################################################################
+=item $self = $self->_insert_instance()
+
+Inserts an instance record into the database
+
+B<Throws:>
+
+NONE
+
+B<Side Effects:>
+
+NONE
+
+B<Notes:>
+
+NONE
+
+=cut
+
+sub _insert_instance {
+ my ($self) = @_;
+ my $sql = 'INSERT INTO '. INSTANCE_TABLE .
+ ' (id, '.join(', ', INSTANCE_COLS) . ')'.
+ "VALUES (${\next_key(INSTANCE_TABLE)}, ".
+ join(', ', ('?') x INSTANCE_COLS) . ')';
+
+ my $sth = prepare_c($sql, undef);
+ execute($sth, $self->_get(INSTANCE_FIELDS));
+ $self->_set( { instance_id => last_key(INSTANCE_TABLE) });
+ return $self;
+}
+
+################################################################################
+
=item $self = $self->_update_story()
Updates the story record in the database
@@ -2387,9 +2438,9 @@ sub _update_story {
################################################################################
-=item $self = $self->_update_instance()
+=item $self = $self->_update_version()
-Updates the record for the story instance
+Updates the record for the story version
B<Throws:>
@@ -2405,7 +2456,7 @@ NONE
=cut
-sub _update_instance {
+sub _update_version {
my ($self) = @_;
return unless $self->_get__dirty();
my $sql = 'UPDATE ' . VERSION_TABLE .
@@ -2419,6 +2470,68 @@ sub _update_instance {
################################################################################
+=item $self = $self->_update_instance()
+
+Updates the record for the story instance
+
+B<Throws:>
+
+NONE
+
+B<Side Effects:>
+
+NONE
+
+B<Notes:>
+
+NONE
+