Class: Hyrax::DataMaintenance

Inherits:
Object
  • Object
show all
Defined in:
app/utils/hyrax/data_maintenance.rb

Overview

Note:

WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive. Data can not be recovered.

These methods created for use in rake tasks and db/seeds.rb They can be used to:

  • clear repository metadata and related data and files

  • clear temporary files

  • clear logs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: Logger.new(STDOUT), allow_destruction_in_production: false) ⇒ DataMaintenance

Returns a new instance of DataMaintenance.


16
17
18
19
20
# File 'app/utils/hyrax/data_maintenance.rb', line 16

def initialize(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
  raise("Destruction of data is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
  @logger = logger
  @allow_destruction_in_production = allow_destruction_in_production
end

Instance Attribute Details

#allow_destruction_in_productionObject

Returns the value of attribute allow_destruction_in_production.


14
15
16
# File 'app/utils/hyrax/data_maintenance.rb', line 14

def allow_destruction_in_production
  @allow_destruction_in_production
end

#loggerObject

Returns the value of attribute logger.


14
15
16
# File 'app/utils/hyrax/data_maintenance.rb', line 14

def logger
  @logger
end

Instance Method Details

#destroy_log_filesObject

TODO:

write code to clear out log files


40
41
42
43
# File 'app/utils/hyrax/data_maintenance.rb', line 40

def destroy_log_files
  # Stubbed until LogFilesDestroyer is written
  # Hyrax::DataDestroyers::LogFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
end

Clear repository metadata and related data

  • clear repository metadata from the datastore (e.g. Fedora, Postgres) and from Solr

  • clear targeted application data that is tightly coupled to repository metadata

  • delete files that are tightly coupled to repository metadata


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/utils/hyrax/data_maintenance.rb', line 26

def 
  Hyrax::DataDestroyers::RepositoryMetadataDestroyer.(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::StatsDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::FeaturedWorksDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::PermissionTemplatesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::CollectionBrandingDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::DefaultAdminSetIdCacheDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
  Hyrax::DataDestroyers::CollectionTypesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)

  # TODO: Stubbed until RepositoryFilesDestroyer is written
  # Hyrax::DataDestroyers::RepositoryFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
end

#destroy_tmp_filesObject

TODO:

write code to delete tmp files


46
47
48
49
# File 'app/utils/hyrax/data_maintenance.rb', line 46

def destroy_tmp_files
  # Stubbed until TmpFilesDestroyer is written
  # Hyrax::DataDestroyers::TmpFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
end