Changeset 967
- Timestamp:
- 12/21/06 00:44:41 (2 years ago)
- Files:
-
- branches/wheeljack/lib/MT/App/CMS.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/wheeljack/lib/MT/App/CMS.pm
r962 r967 254 254 label => "Unpublish TrackBack(s)", 255 255 code => \&unapprove_item, 256 condition => sub { $_[0] ne 'junk'}, # param is tab name256 condition => sub { @_ && ($_[0] ne 'junk') }, # param is tab name 257 257 }, 1); 258 258 $app->add_itemset_action({type => 'comment', … … 260 260 label => "Unpublish Comment(s)", 261 261 code => \&unapprove_item, 262 condition => sub { $_[0] ne 'junk'},262 condition => sub { @_ && ($_[0] ne 'junk') }, 263 263 }, 1); 264 264 $app->add_itemset_action({type => 'comment', … … 936 936 $row->{file_size_formatted} = sprintf("%.1f MB", $size / 1024000); 937 937 } 938 my $ts = $obj->created_on;939 unless ($ts) {940 $ts = $stat[10];941 $ts = epoch2ts($blog, $ts);942 }943 if (my $by = $obj->created_by) {944 my $user = MT::Author->load($by, { cached_ok => 1 });945 $row->{created_by} = $user ? $user->name : '';946 }947 if ($ts) {948 $row->{created_on_formatted} =949 format_ts("%Y.%m.%d", $ts);950 $row->{created_on_time_formatted} =951 format_ts("%Y-%m-%d %H:%M:%S", $ts);952 $row->{created_on_relative} =953 relative_date($ts, time, $blog);954 }955 938 } else { 956 939 $row->{file_is_missing} = 1; 940 } 941 my $ts = $obj->created_on; 942 if (my $by = $obj->created_by) { 943 my $user = MT::Author->load($by, { cached_ok => 1 }); 944 $row->{created_by} = $user ? $user->name : ''; 945 } 946 if ($ts) { 947 $row->{created_on_formatted} = 948 format_ts("%Y.%m.%d", $ts); 949 $row->{created_on_time_formatted} = 950 format_ts("%Y-%m-%d %H:%M:%S", $ts); 951 $row->{created_on_relative} = 952 relative_date($ts, time, $blog); 957 953 } 958 954 $row->{metadata_json} = JSON::objToJson($meta); … … 5685 5681 $app->{goback} = "window.location='". $app->return_uri . "'"; 5686 5682 if ($type eq 'entry') { 5687 require MT::Entry; 5688 foreach (@ids) { 5689 my $entry = MT::Entry->load($_, {cached_ok=>1}); 5690 next unless $entry; 5691 if ($entry->status == MT::Entry::RELEASE()) { 5692 $app->rebuild_entry(Entry => $entry, BuildDependencies => 1) 5693 or return; 5694 } 5695 } 5683 my %ids = map { $_ => 1 } @ids; 5684 return $app->rebuild_these(\%ids); 5696 5685 } elsif ($type eq 'template') { 5697 5686 require MT::Template; … … 5706 5695 5707 5696 sub draft_entries { 5697 my $app = shift; 5708 5698 require MT::Entry; 5709 $ _[0]->update_entry_status(MT::Entry::HOLD(), $_[0]->param('id'));5699 $app->update_entry_status(MT::Entry::HOLD(), $_[0]->param('id')); 5710 5700 } 5711 5701 5712 5702 sub publish_entries { 5703 my $app = shift; 5713 5704 require MT::Entry; 5714 $ _[0]->update_entry_status(MT::Entry::RELEASE(), $_[0]->param('id'));5705 $app->update_entry_status(MT::Entry::RELEASE(), $_[0]->param('id')); 5715 5706 } 5716 5707 … … 5718 5709 my $app = shift; 5719 5710 my ($new_status, @ids) = @_; 5720 return $app->errtrans("Need a status to update entries") unless $new_status; 5721 return $app->errtrans("Need entries to update status") unless @ids; 5711 return $app->errtrans("Need a status to update entries") 5712 unless $new_status; 5713 return $app->errtrans("Need entries to update status") 5714 unless @ids; 5722 5715 my @bad_ids; 5723 5716 my @rebuild_list; 5717 my %rebuild_these; 5724 5718 require MT::Entry; 5725 5719 foreach my $id (@ids) { 5726 5720 my $entry = MT::Entry->load($id, {cached_ok=>1}) or return $app->errtrans("One of the entries ([_1]) did not actually exist", $id); 5727 push @rebuild_list, $entryif $entry->status != $new_status;5721 next if $entry->status != $new_status; 5728 5722 $entry->status($new_status); 5729 $entry->save() or (push @bad_ids, $id); 5730 } 5731 return $app->errtrans("Some entries failed to save") if (@bad_ids); # FIXME: we don't really want this 5732 $app->rebuild_entry(Entry => $_, BuildDependencies => 1) 5733 foreach @rebuild_list; # FIXME: optimize, phase out to another page. 5734 my $blog_id = $app->param('blog_id'); 5735 $app->add_return_arg('saved' => 1); 5736 $app->call_return; 5723 $entry->save() and $rebuild_these{$id} = 1; 5724 } 5725 $app->rebuild_these(\%rebuild_these, how => NEW_PHASE); 5737 5726 } 5738 5727 5739 5728 sub approve_item { 5740 $_[0]->param('approve', 1); 5741 $_[0]->set_item_visible; 5729 my $app = shift; 5730 $app->param('approve', 1); 5731 $app->set_item_visible; 5742 5732 } 5743 5733 5744 5734 sub unapprove_item { 5745 $_[0]->param('unapprove', 1); 5746 $_[0]->set_item_visible; 5735 my $app = shift; 5736 $app->param('unapprove', 1); 5737 $app->set_item_visible; 5747 5738 } 5748 5739 … … 9266 9257 my $ext = (File::Basename::fileparse($local_file, qr/[A-Za-z]+$/))[2]; 9267 9258 9268 # Does the file have dimensions with a recognized image extension?9269 require MT::Asset::Image;9270 my $is_image = defined($w) && defined($h) && MT::Asset::Image->can_handle($local_basename)9271 ? 1 : 0;9272 9273 9259 require MT::Asset; 9274 my $img_pkg = MT::Asset->class_handler($is_image ? 'image' : 'file'); 9275 my $asset = $img_pkg->new(); 9260 my $asset_pkg = MT::Asset->handler_for_file($local_basename); 9261 my $is_image = defined($w) && defined($h) 9262 && $asset_pkg->isa('MT::Asset::Image'); 9263 my $asset; 9264 if (!($asset = $asset_pkg->load({ file_path => $local_file, blog_id => $blog_id }))) { 9265 $asset = $asset_pkg->new(); 9266 $asset->file_path($local_file); 9267 $asset->file_name($local_basename); 9268 $asset->file_ext($ext); 9269 $asset->blog_id($blog_id); 9270 $asset->created_by($app->user->id); 9271 } else { 9272 $asset->modified_by($app->user->id); 9273 } 9276 9274 my $original = $asset->clone; 9277 $asset->blog_id($blog_id);9278 9275 $asset->url($url); 9279 $asset->file_path($local_file);9280 $asset->file_name($local_basename);9281 $asset->file_ext($ext);9282 9276 if ($is_image) { 9283 9277 $asset->image_width($w); 9284 9278 $asset->image_height($h); 9285 9279 } 9286 $asset->created_by($app->user->id);9287 9280 $asset->save; 9288 9281 MT->run_callbacks('CMSPostSave.asset', $app, $asset, $original); … … 10342 10335 # if there's nothing to rebuild, just return 10343 10336 if (!keys %$rebuild_set) { 10337 # now, rebuild indexes for affected blogs 10338 my @blogs = $app->param('blog_ids'); 10339 foreach my $blog_id (@blogs) { 10340 my $blog = MT::Blog->load($blog_id) or next; 10341 $app->rebuild_indexes( Blog => $blog ); 10342 } 10344 10343 return $app->call_return; 10345 10344 } 10346 10345 10347 if ( $options{how} eq NEW_PHASE) {10346 if (exists $options{how} && ($options{how} eq NEW_PHASE)) { 10348 10347 my $params = { 10349 10348 return_args => $app->return_args, 10349 blog_id => $app->param('blog_id') || 0, 10350 10350 id => [ keys %$rebuild_set ] 10351 10351 }; … … 10354 10354 args => $params)); 10355 10355 return $app->build_page('rebuilding.tmpl', \%param); 10356 10357 10356 } else { 10357 my @blogs = $app->param('blog_ids'); 10358 my %blogs = map { $_ => () } @blogs; 10359 my @set = keys %$rebuild_set; 10360 my @rest; 10361 my $entries_per_rebuild = $app->config('EntriesPerRebuild'); 10362 if (scalar @set > $entries_per_rebuild) { 10363 @rest = $set[$entries_per_rebuild..$#set]; 10364 @set = $set[0..$entries_per_rebuild-1]; 10365 } 10358 10366 require MT::Entry; 10359 for my $id (keys %$rebuild_set) { 10360 my $e = ref $rebuild_set->{$id} ? 10361 $rebuild_set->{$id} : MT::Entry->load($id, {cached_ok=>1}); 10362 $app->rebuild_entry(Entry => $e, BuildDependencies => 1); 10363 } 10367 for my $id (@set) { 10368 my $e = ref $id ? 10369 $id : MT::Entry->load($id, {cached_ok=>1}) or next; 10370 $blogs{$e->blog_id} = (); 10371 $app->rebuild_entry(Entry => $e, BuildDependencies => 1, 10372 BuildIndexes => 0); 10373 } 10374 if (@rest) { 10375 foreach (@rest) { 10376 $_ = $_->id if ref $_; 10377 } 10378 } 10379 my $params = { 10380 return_args => $app->param('return_args'), 10381 build_type_name => $app->translate("entry"), 10382 blog_id => $app->param('blog_id') || 0, 10383 blog_ids => [ keys %blogs ], 10384 id => \@rest, 10385 }; 10386 my %param = (is_full_screen => 1, 10387 redirect_target => $app->uri( mode => 'rebuild_phase', 10388 args => $params)); 10389 return $app->build_page('rebuilding.tmpl', \%param); 10364 10390 } 10365 10391 }
