ContentImporterを使って、属性と属性セットを登録したいので、cifを作っています
の「 Grouping attributes in sets」に従って作ったのですが、
属性がその他に入るようなのです。
作ったcif↓
<concrete5-cif version="1.0">
<attributesets>
<attributeset name="会社評価" package="company_rating" handle="company_rate" category="collection">
<attributekey handle="company_rate1" />
<attributekey handle="company_rate2" />
<attributekey handle="company_rate3" />
<attributekey handle="company_rate4" />
<attributekey handle="company_rate5" />
<attributekey handle="company_rate6" />
<attributekey handle="company_rateall" />
</attributeset>
</attributesets>
<attributekeys>
<attributekey handle="company_rate1" name="評価項目1" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate2" name="評価項目2" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate3" name="評価項目3" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate4" name="評価項目4" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate5" name="評価項目5" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate6" name="評価項目6" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rateall" name="全体の評価" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
</attributekeys>
</concrete5-cif>
Concrete のサンプルコンテンツの該当箇所を見ると、
attributesets は attributekeys の後にあります。
なので、CIF の中の順番を反対にしてみてはいかがでしょうか・
以下のように、順番変えてみたけど、属性セットへの登録はされなかったです。
<?xml version="1.0"?>
<concrete5-cif version="1.0">
<attributekeys>
<attributekey handle="company_rate1" name="rate1" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate2" name="rate2" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate3" name="rate3" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate4" name="rate4" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate5" name="rate5" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rate6" name="rate6" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
<attributekey handle="company_rateall" name="all" package="company_rating" searchable="1" indexed="1" type="number" category="collection" />
</attributekeys>
<attributesets>
<attributeset name="rating" package="company_rating" handle="company_rate" category="collection">
<attributekey handle="company_rate1" />
<attributekey handle="company_rate2" />
<attributekey handle="company_rate3" />
<attributekey handle="company_rate4" />
<attributekey handle="company_rate5" />
<attributekey handle="company_rate6" />
<attributekey handle="company_rateall" />
</attributeset>
</attributesets>
</concrete5-cif>
いったん属性を作った後、
もう一個別のアドオンを作って属性セットへの登録cifを実行した場合は属性セットに登録されました。
<?xml version="1.0"?>
<concrete5-cif version="1.0">
<attributesets>
<attributeset name="rating" package="company_rating" handle="company_rate" category="collection">
<attributekey handle="company_rate1" />
<attributekey handle="company_rate2" />
<attributekey handle="company_rate3" />
<attributekey handle="company_rate4" />
<attributekey handle="company_rate5" />
<attributekey handle="company_rate6" />
<attributekey handle="company_rateall" />
</attributeset>
</attributesets>
</concrete5-cif>
@FumitoMIZUNO
うむ。おかしいですね。
ちなみに ContentImporter はどのようなケースで利用予定ですか?
パッケージでインストールできる様にということでしょうか?
別々に登録が可能そうであれば、install() の中で CIF を2回走らせるとかですかね。
「開発環境で属性を設定する→本番環境に属性を設定する」ときに
作業漏れやミスを防ぎたい、ですね。
なので、cifが2つに分かれる、は許容範囲ですね。
1 Like
gist にサンプルコード置いてみました。
↑cifが1つだと属性セットには登録されないっぽい
1 Like
@FumitoMIZUNO ありがとうございます!
では、cif を2つ書いて実行すると実装されそうっていうことですね。
ちなみにですが、
「開発環境で属性を設定する→本番環境に属性を設定する」ときに
作業漏れやミスを防ぎたい、ですね。
なるほど・・・。
ウチの場合であれば、CIF を書いて検証する時間的コストなどを考えて、
1回きりだけであれば、
手順書を書いて2人体制で本番での実施をすることで属性の登録ミスを防いだりしています。
hissy
8
@FumitoMIZUNO
キャッシュ無効にした方がいいですよ
$pkg = parent::install();
Cache::disableAll();
$ci = new ContentImporter();
$ci->importContentFile($pkg->getPackagePath() . '/import.xml');
キャッシュ無効にしたら、属性セットに追加されました。ありがとうございました
↑のほうに貼ったgistにもCache::disableAll()追加しました
1 Like
installContentFile()を使った方が良さそうですね。
キャッシュの無効化処理に対応している
1 Like
hissy
11
そうですね。ドキュメントでもそちらが記載されています。
弊社では installContentFile の方を使っています。
サンプルパッケージもご参考まで。