George S. Baugh 4 роки тому
батько
коміт
c67af46f92
2 змінених файлів з 13 додано та 17 видалено
  1. 4 2
      bin/migrate3.pl
  2. 9 15
      lib/Trog/DataModule.pm

+ 4 - 2
bin/migrate3.pl

@@ -35,8 +35,10 @@ my @all = $search_info->get( raw => 1, limit => 0 );
 
 #TODO add in the various things we need to data
 foreach my $post (@all) {
-    next unless $post->{form} eq 'series.tx';
-    $post->{tiled} = scalar(grep { $_ eq $post->{local_href} } qw{/files /audio /video /image /series /about});
+    if ( $post->{form} eq 'series.tx' ) {
+        $post->{tiled} = scalar(grep { $_ eq $post->{local_href} } qw{/files /audio /video /image /series /about});
+    }
+    # Otherwise re-save the posts with is_video etc
     $search_info->add($post);
 }
 

+ 9 - 15
lib/Trog/DataModule.pm

@@ -91,8 +91,6 @@ sub get ($self, %request) {
 }
 
 sub _fixup ($self, @filtered) {
-    @filtered = _add_media_type(@filtered);
-
     # urlencode spaces in filenames
     @filtered = map {
         my $subj = $_;
@@ -208,18 +206,6 @@ sub _dedup_versions ($version=-1, @posts) {
     return @deduped;
 }
 
-sub _add_media_type (@posts) {
-    return map {
-        my $post = $_;
-        $post->{content_type} //= '';
-        $post->{is_video}   = 1 if $post->{content_type} =~ m/^video\//;
-        $post->{is_audio}   = 1 if $post->{content_type} =~ m/^audio\//;
-        $post->{is_image}   = 1 if $post->{content_type} =~ m/^image\//;
-        $post->{is_profile} = 1 if grep {$_ eq 'about' } @{$post->{tags}};
-        $post
-    } @posts;
-}
-
 =head2 count() = INT $num
 
 Returns the total number of posts.
@@ -240,6 +226,7 @@ You probably won't want to override this.
 
 sub add ($self, @posts) {
     my @to_write;
+
     foreach my $post (@posts) {
         $post->{id} //= UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V1, UUID::Tiny::UUID_NS_DNS);
         $post->{aliases} //= [];
@@ -269,6 +256,7 @@ sub add ($self, @posts) {
         $post->{version} //= 0;
 
         $post = _process($post);
+
         push @to_write, $post;
     }
     $self->write(\@to_write);
@@ -314,7 +302,8 @@ sub _process ($post) {
     }
 
     #Filter adding the same acl twice
-    @{$post->{tags}} = List::Util::uniq(@{$post->{tags}});
+    @{$post->{tags}}    = List::Util::uniq(@{$post->{tags}});
+    @{$post->{aliases}} = List::Util::uniq(@{$post->{aliases}});
 
     # Handle multimedia content types
     if ($post->{href}) {
@@ -334,6 +323,11 @@ sub _process ($post) {
     }
     $post->{content_type} ||= 'text/html';
 
+    $post->{is_video}   = 1 if $post->{content_type} =~ m/^video\//;
+    $post->{is_audio}   = 1 if $post->{content_type} =~ m/^audio\//;
+    $post->{is_image}   = 1 if $post->{content_type} =~ m/^image\//;
+    $post->{is_profile} = 1 if grep {$_ eq 'about' } @{$post->{tags}};
+
     return $post;
 }