migrate3.pl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. # Migrate early on tcms3 flatfile sites to 'all posts are series code' (august 2021) code
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use Trog::Config;
  8. use Trog::Data;
  9. use List::Util;
  10. use UUID::Tiny;
  11. use Trog::SQLite;
  12. use Trog::SQLite::TagIndex;
  13. # Kill the post index
  14. unlink "$FindBin::Bin/../data/posts.db";
  15. $ENV{NOHUP} = 1;
  16. sub uuid { return UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V1, UUID::Tiny::UUID_NS_DNS); }
  17. # Modify these variables to suit your installation.
  18. my $user = 'george';
  19. my @extra_series = (
  20. );
  21. my $conf = Trog::Config::get();
  22. my $search_info = Trog::Data->new($conf);
  23. my @all = $search_info->get( raw => 1, limit => 0 );
  24. #TODO add in the various things we need to data
  25. foreach my $post (@all) {
  26. if ( defined $post->{form} && $post->{form} eq 'series.tx' ) {
  27. $post->{tiled} = scalar(grep { $_ eq $post->{local_href} } qw{/files /audio /video /image /series /about});
  28. }
  29. if (!defined $post->{visibility}) {
  30. $post->{visibility} = 'public' if grep { $_ eq 'public' } @{$post->{tags}};
  31. $post->{visibility} = 'private' if grep { $_ eq 'private' } @{$post->{tags}};
  32. $post->{visibility} = 'unlisted' if grep { $_ eq 'unlisted' } @{$post->{tags}};
  33. }
  34. # Otherwise re-save the posts with is_video etc
  35. $search_info->add($post);
  36. }
  37. # Rebuild the index
  38. Trog::SQLite::TagIndex::build_index($search_info);
  39. Trog::SQLite::TagIndex::build_routes($search_info);
  40. # Add in the series
  41. my $series = [
  42. {
  43. "acls" => [],
  44. aliases => [],
  45. "callback" => "Trog::Routes::HTML::posts",
  46. method => 'GET',
  47. "data" => "All Posts",
  48. "href" => "/posts",
  49. "local_href" => "/posts",
  50. "preview" => "/img/sys/testpattern.jpg",
  51. "tags" => [qw{series}],
  52. visibility => 'unlisted',
  53. "title" => "All Posts",
  54. user => $user,
  55. form => 'series.tx',
  56. child_form => 'series.tx',
  57. aclname => 'posts',
  58. },
  59. ];
  60. #$search_info->add(@$series,@extra_series);