我以为我会从上面发回代码,但稍作修改以使其正常工作。需要分配 $magento 以及用于 grep 的路径。只需将 /var/www/app 更改为您的 magento 目录即可。将此脚本复制到文件并执行它。您需要安装 ack-grep 才能正常工作。Ubuntu 用户可以输入“sudo apt-get ack-grep”我相信安装它,或者只是 google ack-grep。
这是一个外壳 PHP 脚本。如果您在浏览器中运行它,它看起来就像一团糟!但是,您可以执行“php whateveryoucallthescript.php >> output.txt”,然后在 VI 中打开该文件或对其进行编辑并搜索所需的结果。
这已经在 Enterprise 1.11.1.0 上进行了测试
<?php
$magento = "/var/www/app/";
$results = `ack-grep Mage::dispatchEvent $magento 2>/dev/null | grep -v "/var/www/app/code/local" | grep -v "/var/www/downloader/pearlib"`;
$results = explode("\n", $results);
print_error(sprintf("%-100s\t%-4s\t%s\n", "FILE", "LINE", "EVENT"));
foreach($results as $result) {
if(!strlen(trim($result))) { continue; }
$matches = array();
preg_match("/([^:]+):(\d+):\W+(.*)/", $result, $matches);
$file = str_replace($magento, "", $matches[1]);
$line = $matches[2];
$event = $matches[3];
$eventMatches = array();
if(preg_match("/Mage::dispatchEvent\('(\w+)'\);/", $event, $eventMatches)) {
$event = $eventMatches[1];
$matchType = 1;
} else if(preg_match("/Mage::dispatchEvent\('(\w+)',.*/", $event, $eventMatches)) {
$event = $eventMatches[1];
$matchType = 2;
} else if(preg_match("/Mage::dispatchEvent\($/", $event)) {
$event = get_next_line_event($file, $line+1, $magento);
$matchType = 3;
} else if(preg_match("/Mage::dispatchEvent\(\"?(['\$a-zA-Z._{}\-> ]+).*/", $event, $eventMatches)) {
$event = $eventMatches[1];
$matchType = 4;
} else {
print "Found unmatcheable event:\n";
var_dump($event);
}
printf("%-100s\t%-4s\t%s\n", $file, $line, $event);
}
function get_next_line_event($file, $line, $magento) {
$cnt = `cat -n $magento/$file | grep -e "^ *$line"`;
$cnt = preg_replace("/^\s*\d*\s*/", "", $cnt);
$matches = array();
if(preg_match("/^'?([\$a-z_>. -]*)'?,$/i", $cnt, $matches)) {
return $matches[1];
} else if(preg_match("/^([\$a-z_>. '\-\(\)]*),$/i", $cnt, $matches)) {
return $matches[1];
}
print "Found unmatcheable event:\n";
var_dump($cnt);exit;
}
function print_error($err) {
echo $err;
}
?>