Redmine – Ruby – 寻找自定义字段的值

我检查了IRC的redmine并且无法获得帮助。 我在天气方面存在冲突,无法在超级用户,ServerFault或此处使用,但由于我的问题在技术上是面向编程的,所以我决定在这里寻求帮助。

我们有一个Mercurial存储库系统,其布局基于满足我们需求的项目。 我编写了一些shell脚本,可以很好地管理存储库并将它们放在正确的位置等。我试着调用这些脚本并从Redmine传递它们的参数。 我正在编辑app / controllers / projects_controller.rb(第75行 – > 87行)

我已设法提取项目参数和当前用户,但我添加了两个自定义字段(使用Redmine管理中的自定义字段),我试图访问这些自定义字段的值。 有谁知道我怎么能得到这些?

我目前的工作测试声明如下:

system "echo '#{@project.identifier}, #{User.current}' >> /tmp/rm.log" 

使用CustomField模型。 例如,

  # Find the first Custom Field cf = CustomField.first # Get the name puts cf.name # Find out if this Custom Field is for all projects cf.is_for_all? # If not, find out which projects are using it cf.projects 

为了解决这个问题,我刚安装了Redmine-1.0.0并在源代码和脚本/控制台中进行了调整。

 use DBI; $dbServer=''; $user=''; $pass=''; $ident=$ARGV[0]; my $dsn = "dbi:mysql:database=redmine;host=$dbServer;port=3306"; my $dbh = DBI->connect($dsn, "$user","$pass") or die "Can't connet to the Database: $DBI::errstr\n"; my $sth = $dbh->prepare("SELECT value FROM custom_values c INNER JOIN projects p ON c.customized_id=p.id WHERE p.identifier='$ident' LIMIT 1"); $sth -> execute(); my @row=$sth->fetchrow_array(); my $serverParams=@row[0]; 

调用上面的脚本(而不是在原始文件中回显),然后传入我们已经拥有的项目标识符,可以以任何方式使用自定义参数。 这个代码可以抓取一个自定义字段(我只使用一个。)