我想在不通过图形界面的情况下将文件添加到Redmine服务器。我通过一个单独的svn checkout
过程将文件提供给Redmine服务器,因此我只需要能够将文件添加到Redmine自己的数据库中即可。
理想情况下,我想要一个可以像这样运行的解决方案:
./redmine-register-file /path/to/my/file.ext "with optional description"
我相信该接口的相关部分可以在中找到redmine/apps/views/files/new.html.erb
。可通过访问它index.html.erb
,其中有一小部分与我有关:
<div class="contextual">
<%= link_to(l(:label_attachment_new), new_project_file_path(@project), :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %>
</div>
这是以下内容的完整内容new.html.erb
:
<h2><%=l(:label_attachment_new)%></h2>
<%= error_messages_for 'attachment' %>
<%= form_tag(project_files_path(@project), :multipart => true, :class => "tabular") do %>
<div class="box">
<% if @versions.any? %>
<p><label for="version_id"><%=l(:field_version)%></label>
<%= select_tag "version_id", content_tag('option', '') +
options_from_collection_for_select(@versions, "id", "name") %></p>
<% end %>
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %>
<% end %>
我不知道那红宝石以及在所有(任何超出print name.reverse
超出了我),但我知道,所有这些冒号表示选择。我可以从标准界面中收集哪些信息,这些信息将对我的任务有所帮助,以及完整的解决方案是什么样的?
Redmine使用MySQL数据库存储其文件注册。该数据库称为redmine_production
,并使用以下架构:
mysql> SHOW COLUMNS FROM redmine_production.attachments;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| container_id | int(11) | YES | MUL | NULL | |
| container_type | varchar(30) | YES | | NULL | |
| filename | varchar(255) | NO | | | |
| disk_filename | varchar(255) | NO | | | |
| filesize | int(11) | NO | | 0 | |
| content_type | varchar(255) | YES | | | |
| digest | varchar(40) | NO | | | |
| downloads | int(11) | NO | | 0 | |
| author_id | int(11) | NO | MUL | 0 | |
| created_on | datetime | YES | MUL | NULL | |
| description | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
12 rows in set (0.00 sec)
也许这将是有用的: attachment.rb
对于那些由我创建的Redmine线程来解决这个问题的人:我也尝试将解决方案发布到那里,但是SPAM筛选器不允许我对该线程进行跟进。可能是因为没有中间响应(* tear *)。
花了一些时间,但我想通了。(我做了一个Redmine的测试实例,以免弄乱我们的生产实例,因此这些值是默认值,并且对尝试这样做的任何人都适用。)
该过程的简短摘要:
实际上,没有进行数据库验证,因此,即使(2)是可选的。因此,我将不讨论如何获取该信息。(即使在该站点上,也有足够的资源来获取这些信息。)但是,其余的知识只需要一点点关于Redmine如何建立数据库的知识。
首先,连接到您的生产MySQL数据库。(通常,如果不总是这样,则redmine_production
可以使用。列出所有MySQL数据库SHOW DATABASES;
。)
现在,找到您要添加文件的项目的ID。在上面列出的列中,它将插入为container_id
。
mysql> SELECT * FROM projects;
+----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+
| id | name | description | homepage | is_public | parent_id | created_on | updated_on | identifier | status | lft | rgt |
+----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+
| 1 | git-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | git-helloworld | 1 | 1 | 2 |
| 2 | bzr-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | bzr-helloworld | 1 | 1 | 2 |
| 3 | hg-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | hg-helloworld | 1 | 1 | 2 |
| 4 | svn-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | svn-helloworld | 1 | 1 | 2 |
+----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+
4 rows in set (0.00 sec)
在此示例中,我们要将文件添加到git-helloworld
,因此我们的ID为1
。因此,要向数据库添加文件,我们将执行SQL命令:
INSERT INTO attachments (container_id, container_type,
filename, disk_filename, digest) VALUES (
1, 'Project',
'Some File Name', 'file-name-on-disk', '0123456789abcdef');
有关这些字段的一些注意事项:
container_id
:您希望在其中包含文件的项目的IDcontainer_type
:这是容器的类型;为此,它总是 Project
filename
:显示为文件名的字符串disk_filename
:文件的实际路径,相对于 /var/www/redmine/files/
digest
:表示文件的MD5校验和的字符串。一些不是必需的,但建议使用的字段:
filesize
:文件大小,为整数。我认为这是要以字节或千字节为单位的,但是我不知道这是否重要。author_id
:与文件关联的用户。就我的目的而言,我将使用admin
。请注意,您可以使用来获得Redmine用户的完整列表SELECT * FROM users;
。description
:文件说明。(这与界面中使用的可选描述相同。)content_type
:我认为这是MIME内容类型。created_on
:创建此文件的日期。有关所有这些类型的显式类型,请参阅原始文章中列出的列。
接下来,确保中的路径disk_filename
相对于您的redmine/files/
目录实际存在。(注意,这意味着你实际上可以安排吧!)你不必有这样做,但你显然会得到一个404,如果该文件不存在。
之后,您应该会好起来!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句