2

カスタムのインポートとエクスポートを作成します。現時点では、外部スクリプトとして(ブートストラップを介して)、後でより一般的な方法でモジュールを作成する予定です。

私はnagiosと、ホスト管理およびnagios構成のフロントエンドを構築しています。たぶんそれは他の環境(ネットワーク管理)に役立つかもしれません

タイプxのすべてのノードのリストを取得する方法を知る必要がありますか?

直接SQLは避けたい。

私が得た提案は、RSSを作成して解析することでしたが、drupal dbにアクセスしてさまざまなノードを抽出するため、1つのことに対してWebリクエストを実行するのは奇妙に感じます。

だから私が初心者のdrupaldevとして探しているのは、このタスクの基本的な検索モジュールAPIへの単なるポインターです

TIAフロリアン

4

5 に答える 5

5

Why do you want to avoid using SQL?

If you want to get info about what's in your db, like all the nodes of type x, the only way to get it, is through a SQL query, unless you have the data extracted already.

A query like

db_query("SELECT title, nid FROM {node} WHERE type = 'x';");

shouldn't be the thing that ruins your performance.

Edit:
The link you provided is a from Drupal 7, so you have to be be careful reading this. The reason is that in Drupal 7 it is not only possible to use db_query which basically is wrapper for the php functions mysql_query, pg_query. It's a bit different and using it, you wont have to use db_specific code. Anyways new in Drupal 7 is something that is a bit like an ORM. I haven't read about it in detail, but the idea is that you can build a query using commands on an object. This is probably what you are after. However, Drupal 7 is not ready at all for production sites. There are still a lot of critical issues and security issues. So this wont be a possibility for quite some time.

Edit 2:
If you want to get the node title and body, this is what you should do:

$type = 'x';
$query = db_query("SELECT r.nid, r.title, r.body FROM {node} AS n 
                  LEFT JOIN {node_revisions} AS r ON r.nid = n.nid
                  WHERE type = '%s';", array($type));
$nodes = array();
while ($node = db_fetch_object($query)) {
    $nodes[$node->nid] = $node;
}

You can use db_fetch_array instead of db_fetch_object` if you want to extract arrays instead of objects from the db.

于 2010-03-19T12:39:46.820 に答える
2

これはかなり古い質問ですが、このページに出くわした人にとって、Drupal 7.xのベストプラクティスは、動的クエリを使用することです。

したがって、タイプxのすべてのノードを選択する場合は、次のようにすることができます。

$articles = db_select('node')
->fields('node', array('nid', 'title'))
->condition('type', 'x', '=')
->execute()
->fetchAllKeyed();

$ articles変数は、すべてのxタイプのノードの配列であり、nidによってキー設定され、配列に対応する値がノードタイトルに設定されている必要があります。それがお役に立てば幸いです。

于 2013-01-10T08:08:40.183 に答える
1

ビューは通常、Drupalで記述せずにデータベースクエリを作成する方法ですが、このクエリは非常に単純なので、Drupalをブートストラップした後わずか5行で、ビューを学習するオーバーヘッドの価値があるかどうかはわかりません。

$nodes = array();
$results = db_query("SELECT nid FROM {node} WHERE type = '%s'", $type);
while ($result = db_fetch_object($result)) {
  $nodes[] = node_load($result->nid);
}
于 2010-03-19T13:50:35.467 に答える
0

移行モジュールに興味があるかもしれません。また、 drushもサポートしているため、かなり簡単にスクリプトを作成できます。

于 2010-03-22T07:22:10.857 に答える
0

これには SQL を使用する必要があります。

http://api.drupal.org/api/function/node_get_types/6

ノード数 =

$node_types = node_get_types();

$type_count = array();

foreach ($node_types as $type) {
   $result = db_fetch_object(db_query('SELECT count(nid) AS node_count FROM {node} WHERE type = "%s"'), $type);
   $type_count[$type] = $result['count(nid)'];
}

print_r($type_count);

ノードとそのタイプ:

$node_types = node_get_types();

$nodes = array();

foreach ($node_types as $type) {
   $result = db_query('SELECT nid, title FROM {node} WHERE type = "%s"'), $type);

   while ($node = db_fetch_object($result)) {
      $nodes[] = array('Type' => $type, 'Title' => $node->title);
   }
}

print_r($nodes);

そんな感じ。私は昼食を食べているのでテストしませんでしたが、以前にこれを行ったことがあるので、うまくいくはずです。ドルパル 6。

于 2010-03-19T16:08:56.420 に答える