Automate custom field creation in Redmine

I want to write a plugin for redmine that will depend on several custom fields , so I would like to create custom fields automatically. Ideally, in the plugin code, or if not using a script, I can run when I install the plugin - I really do not want to create 10+ fields via the web interface when I install it, especially when there is one list with several values.

Can someone tell me if there are standard ways to do this?

Is there also a good way to export custom fields from an existing installation?

+3
source share
3 answers

. #{PLUGIN_ROOT}/db/migrate .create . Redmine .

, script : 001_populate_custom_fields.rb.

:

class PopulateCustomFields < ActiveRecord::Migration
    def self.up
        CustomField.create ...
    end
    def self.down
    end
end
+2

( custom_fields). , CustomField.create/new , . , find() . , , , . , , , .

0

, script #{PLUGIN_ROOT}/db/migrate , / .

:

rake redmine:plugins:migrate

:

rake redmine:plugins:migrate NAME=<your plugin name> VERSION=0

.

, script 001_populate_custom_fields.rb :

class PopulateCustomFields < ActiveRecord::Migration
  # method called when installing the plugin
  def self.up
    if CustomField.find_by_name('A New Custom Field').nil?
      CustomField.create(name: 'A New Custom Field', field_format: 'text')
    end
  end

  # method called when uninstalling the plugin
  def self.down
    CustomField.find_by_name('A New Custom Field').delete unless CustomField.find_by_name('A New Custom Field').nil?
  end
end

This will create / delete the custom field “New custom field” of type “text” after checking its existence from the table tables of the redmine database.

0
source

Source: https://habr.com/ru/post/1737545/


All Articles