diff --git a/db/migrate/20251015130601_active_storage_migration.rb b/db/migrate/20251015130601_active_storage_migration.rb index a0cda595..277fdc30 100644 --- a/db/migrate/20251015130601_active_storage_migration.rb +++ b/db/migrate/20251015130601_active_storage_migration.rb @@ -22,6 +22,11 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0] # File system -> Active Storage def up $stdout.puts 'It could be a very long process. Be patient...' + # We need to keep updated_at column unchanged and due to the asynchronous file analysis there is probably no better + # way how to achieve that. + add_column :dmsf_file_revisions, :temp_updated_at, :datetime, default: nil, + null: true, if_not_exists: true + DmsfFileRevision.update_all 'temp_updated_at = updated_at' # Remove the Xapian database as it will be rebuilt from scratch during the migration if xapian_database_removed? $stdout.puts 'The Xapian database has been removed as it will be rebuilt from scratch during the migration' @@ -72,7 +77,10 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0] $stdout.puts "#{File.join(key[0..1], key[2..3], key)} (#{a.blob.filename}) => #{new_path}" end # Remove the original file - a.blob.purge + r.record_timestamps = false # Do not modify updated_at column + DmsfFileRevision.no_touching do + a.purge + end end # Remove the Xapian database as it is useless now and has to be rebuilt with xapian_indexer.rb if xapian_database_removed? diff --git a/db/migrate/20251017101001_restore_updated_at.rb b/db/migrate/20251017101001_restore_updated_at.rb new file mode 100644 index 00000000..d44b8790 --- /dev/null +++ b/db/migrate/20251017101001_restore_updated_at.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Redmine plugin for Document Management System "Features" +# +# Karel Pičman +# +# This file is part of Redmine DMSF plugin. +# +# Redmine DMSF plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General +# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Redmine DMSF plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even +# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with Redmine DMSF plugin. If not, see +# . + +# Restore DmsfFileRevision.updated_at from DmsfFileRevision.temp_updated_at column +class RestoreUpdatedAt < ActiveRecord::Migration[7.0] + # temp_updated_at => updated_at + def up + DmsfFileRevision.update_all 'updated_at = temp_updated_at' + remove_column :dmsf_file_revisions, :temp_updated_at + end +end diff --git a/lib/redmine_dmsf/xapian_analyzer.rb b/lib/redmine_dmsf/xapian_analyzer.rb index 34ed070d..04dea1bd 100644 --- a/lib/redmine_dmsf/xapian_analyzer.rb +++ b/lib/redmine_dmsf/xapian_analyzer.rb @@ -28,13 +28,12 @@ module RedmineDmsf end def metadata - index - {} + { xapian: indexed? } end private - def index + def indexed? stem_lang = RedmineDmsf.dmsf_stemming_lang db_path = File.join RedmineDmsf.dmsf_index_database, stem_lang url = File.join(@blob.key[0..1], @blob.key[2..3]) @@ -44,8 +43,10 @@ module RedmineDmsf FileUtils.mv file.path, File.join(dir, @blob.key) system "omindex -s \"#{stem_lang}\" -D \"#{db_path}\" --url=/#{url} \"#{dir}\" -p", exception: true end + true rescue StandardError => e Rails.logger.error e.message + false ensure FileUtils.rm_f dir end