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

发布于 2024-09-09 04:49:29 字数 506 浏览 3 评论 0原文

我检查了 IRC 的 redmine,但无法获得帮助。 我很矛盾,不知道该把这个问题放在 Superuser、ServerFault 还是这里,但由于我的问题是面向技术编程的,所以我决定在这里寻求帮助。

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

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

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

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

I checked IRC for redmine and was unable to get help.
I was conflicted on weather to stick this on Superuser, ServerFault or here, but as my problem is technically programming oriented I decided to look for help here.

We have a Mercurial repository system with a layout based on projects that addresses our needs. I wrote some shell scripts which work delightfully to manage the repository and put them in correct places etc. I am trying to call these scripts and pass them parameters from Redmine. I am editing the app/controllers/projects_controller.rb (lines 75 -> 87)

I have managed to pull the project parameters and current user, but I have two custom fields I added (using the custom fields in Redmine Administration) and I am trying to access the values of these custom fields. Does anyone have any idea how I can get these?

My current working test statement is below:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰雪之触 2024-09-16 04:49:29

使用 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 the CustomField model. For example,

  # 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

To figure this out, I just installed Redmine-1.0.0 and poked around in the source and the script/console.

但可醉心 2024-09-16 04:49:29
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];

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

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];

Calling the above script (instead of echoing in the original), and then passing in the project identifier which we already have, the custom parameter can be used in whatever way nessacary. This code it to grab a single custom field (i was only using one.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文