migrate3.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env perl
  2. use v5.36;
  3. use re '/aa';
  4. # Migrate early on tcms3 flatfile sites to store rather than compute much data (dec 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. =head1 SYNOPSIS
  14. Migrate early tCMS3 flatfile sites to store rather than compute much data
  15. (December 2021).
  16. Visibility used to be worked out from a post's tags on every read, and whether
  17. a series tiled its children from its href. This walks every post and writes
  18. those out as fields, so that the reading code doesn't have to derive them.
  19. =head2 USAGE
  20. Edit $user below to suit your installation, then:
  21. bin/migrate3.pl
  22. Run from the tCMS root. Assumes migrate2.pl has already been run.
  23. =head2 CAVEATS
  24. Historical. Posts are re-saved through the data model, so this creates a new
  25. revision of every post on the site.
  26. Posts with no visibility tag at all are left without one, as there's no safe
  27. guess between public and private.
  28. The 'All Posts' series at the end is left commented out; uncomment it if your
  29. instance wants /posts to be a series of its own.
  30. =cut
  31. # Kill the post index
  32. unlink "$FindBin::Bin/../data/posts.db";
  33. $ENV{NOHUP} = 1;
  34. sub uuid { return UUID::Tiny::create_uuid_as_string( UUID::Tiny::UUID_V1, UUID::Tiny::UUID_NS_DNS ); }
  35. # Modify these variables to suit your installation.
  36. my $user = 'george';
  37. my @extra_series;
  38. my $conf = Trog::Config::get();
  39. my $search_info = Trog::Data->new($conf);
  40. my @all = $search_info->get( raw => 1, limit => 0 );
  41. foreach my $post (@all) {
  42. if ( defined $post->{form} && $post->{form} eq 'series.tx' ) {
  43. $post->{tiled} = scalar( grep { $_ eq $post->{local_href} } qw{/files /audio /video /image /series /about} );
  44. }
  45. if ( !defined $post->{visibility} ) {
  46. $post->{visibility} = 'public' if grep { $_ eq 'public' } @{ $post->{tags} };
  47. $post->{visibility} = 'private' if grep { $_ eq 'private' } @{ $post->{tags} };
  48. $post->{visibility} = 'unlisted' if grep { $_ eq 'unlisted' } @{ $post->{tags} };
  49. }
  50. # Otherwise re-save the posts with is_video etc
  51. $search_info->add($post);
  52. }
  53. # Rebuild the index
  54. Trog::SQLite::TagIndex::build_index($search_info);
  55. Trog::SQLite::TagIndex::build_routes($search_info);
  56. # Add in the series
  57. my $series = [
  58. {
  59. "acls" => [],
  60. aliases => [],
  61. "callback" => "Trog::Routes::HTML::posts",
  62. method => 'GET',
  63. "data" => "All Posts",
  64. "href" => "/posts",
  65. "local_href" => "/posts",
  66. "preview" => "/img/sys/testpattern.jpg",
  67. "tags" => [qw{series}],
  68. visibility => 'unlisted',
  69. "title" => "All Posts",
  70. user => $user,
  71. form => 'series.tx',
  72. child_form => 'series.tx',
  73. aclname => 'posts',
  74. },
  75. ];
  76. #$search_info->add(@$series,@extra_series);