すべてのクラスの書き換えのリストを取得するにはどうすればよいですか?
-
16-10-2019 - |
質問
すべての構成ファイルを確認する以外に、すべての書き直しおよびその他の潜在的な競合をリストする方法はありますか?いくつかのプロジェクトを多くの拡張機能とカスタム修正で分析する必要があり、これについて可能な限り自動化したいと考えています。
最も重要なことは、同じクラスを書き直す拡張機能を検出することですが、概要を維持するために、すべての書き込みのリストも所有しています。現時点では、このリストをスプレッドシートで手動で維持しています。
私は見つけました この拡張機能(「拡張競合」) Magento Connectでは、レビューとリリースメモから判断すると、時代遅れのようです。
解決
を見てください N98-Magerunユーティリティ:
リストを書き直します
登録されたすべてのクラスの書き換えをリストします。
$ n98-magerun.phar dev:module:rewrite:list
競合を書き直します
すべての重複した書き換えをリストし、どのクラスがMagentoによってロードされているかを伝えます。コマンドは、モジュールの依存関係の順にクラスの継承をチェックします。
n98-magerun.phar dev:module:rewrite:conflicts [--log-junit="..."]
-log-junitオプションが設定されたファイル名の場合、ツールはXMLファイルを生成し、stdoutへの出力はありません。
また、競合をJunitスタイルXMLファイルにログに記録して、たとえば統合サーバーなどです。
免責事項:セミセルフリンク /私はそのプロジェクトに関与しています
他のヒント
ここに、すべてのアクティブな書き直しを与える小さなワンライナーが次のとおりです。
print_r(Mage::getConfig()->getNode()->xpath('//global//rewrite'));
オブジェクトタイプで制限するには、それぞれXpathにモデル、ブロック、またはヘルパーを追加します。
例えば:
Mage::getConfig()->getNode()->xpath('//global/models//rewrite')
これは、モデル、ブロック、またはヘルパーが上書きされているかどうかを確認するために使用する小さなスクリプトです。残念ながら、コントローラーでは機能せず、無効モジュールも考慮しています。しかし、私の観点からは、これは大したことではありません。
主なアイデアは、構成ファイルを解析し、 <rewrite>
鬼ごっこ。同じレベルでPHPファイルを作成します index.php
. 。それを呼びましょう rewrites.php
, 、このコンテンツで:
<?php
$folders = array('app/code/local/', 'app/code/community/');//folders to parse
$configFiles = array();
foreach ($folders as $folder){
$files = glob($folder.'*/*/etc/config.xml');//get all config.xml files in the specified folder
$configFiles = array_merge($configFiles, $files);//merge with the rest of the config files
}
$rewrites = array();//list of all rewrites
foreach ($configFiles as $file){
$dom = new DOMDocument;
$dom->loadXML(file_get_contents($file));
$xpath = new DOMXPath($dom);
$path = '//rewrite/*';//search for tags named 'rewrite'
$text = $xpath->query($path);
foreach ($text as $rewriteElement){
$type = $rewriteElement->parentNode->parentNode->parentNode->tagName;//what is overwritten (model, block, helper)
$parent = $rewriteElement->parentNode->parentNode->tagName;//module identifier that is being rewritten (core, catalog, sales, ...)
$name = $rewriteElement->tagName;//element that is rewritten (layout, product, category, order)
foreach ($rewriteElement->childNodes as $element){
$rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it
}
}
}
echo "<pre>";print_r($rewrites);
ブラウザでそれを呼び出すとき、あなたは次のようなものを見るはずです:
Array
(
[models] => Array
(
[core/layout] => Array
(
[0] => Namespace_Module_Model_Core_Layout
[1] => Namespace1_Module1_Model_Core_Layout //if the second element is present it means there is a possible conflict
)
[...] => ....
)
[blocks] => ...
[helpers] => ...
)
これは、モデルを意味します 'core/layout'
によって上書きされます Namespace_Module_Model_Core_Layout
配列に2つ以上の値がある場合[「コア/レイアウト」]、競合があることを意味します。
また、に基づいて何かを上書きするモジュールを簡単に識別できます Namespace
と Module
私は両方の答えを組み合わせて、素晴らしい解決策を得ました
$text = Mage::getConfig()->getNode()->xpath('//global//rewrite');
foreach ($text as $rewriteElement) {
if ($rewriteElement->getParent()->getParent()) {
# what is overwritten (model, block, helper)
$type = $rewriteElement->getParent()->getParent()->getName();
# module identifier that is being rewritten (core, catalog, sales, ...)
$parent = $rewriteElement->getParent()->getName();
# element that is rewritten (layout, product, category, order)
$name = $rewriteElement->getName();
foreach ($rewriteElement->children() as $element) {
# class that rewrites it
$rewrites[$type][$parent.'/'.$name][] = $element;
}
}
}
print_r($rewrites);
die;
たぶん少し頭上ですが、varienデータ収集で作業するのは素晴らしいことです...コードから https://github.com/firegento/firegento-debug
$collection = new Varien_Data_Collection();
$fileName = 'config.xml';
$modules = Mage::getConfig()->getNode('modules')->children();
$rewrites = array();
foreach ($modules as $modName => $module) {
if ($module->is('active')) {
$configFile = Mage::getConfig()->getModuleDir('etc', $modName) . DS . $fileName;
if (file_exists($configFile)) {
$xml = file_get_contents($configFile);
$xml = simplexml_load_string($xml);
if ($xml instanceof SimpleXMLElement) {
$rewrites[$modName] = $xml->xpath('//rewrite');
}
}
}
}
foreach ($rewrites as $rewriteNodes) {
foreach ($rewriteNodes as $n) {
$nParent = $n->xpath('..');
$module = (string)$nParent[0]->getName();
$nSubParent = $nParent[0]->xpath('..');
$component = (string)$nSubParent[0]->getName();
if (!in_array($component, array('blocks', 'helpers', 'models'))) {
continue;
}
$pathNodes = $n->children();
foreach ($pathNodes as $pathNode) {
$path = (string)$pathNode->getName();
$completePath = $module . '/' . $path;
$rewriteClassName = (string)$pathNode;
$instance = Mage::getConfig()->getGroupedClassName(
substr($component, 0, -1),
$completePath
);
$collection->addItem(
new Varien_Object(
array(
'path' => $completePath,
'rewrite_class' => $rewriteClassName,
'active_class' => $instance,
'status' => ($instance == $rewriteClassName)
)
)
);
}
}
}
出力については、使用できます...
foreach ($collection as $rewrite) {
var_dump($rewrite->getData());
}