/** * Execute command * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @throws \Exception * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->_input = $input; $this->_output = $output; $this->detectMagento($output, true); $pathToVanillaCore = $this->_input->getArgument('pathToVanillaCore'); if (!is_file($pathToVanillaCore . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php')) { throw new \Exception('Could not find vanilla Magento core in ' . $pathToVanillaCore); } $this->_output->writeln("<info>Comparing project files in '{$this->_magentoRootFolder}' to vanilla Magento code in '{$pathToVanillaCore}'...</info>"); $skipDirectories = $this->_input->getArgument('skipDirectories'); if (empty($skipDirectories)) { $skipDirectories = '.svn' . PATH_SEPARATOR . '.git'; } $compareUtil = new \Mpmd\Util\Compare(); $data = $compareUtil->compareDirectories($pathToVanillaCore, $this->_magentoRootFolder, '', explode(PATH_SEPARATOR, $skipDirectories)); $table = array(); foreach ($data as $type => $items) { $table[] = array('Type' => $type, 'Count' => count($items)); } $this->getHelper('table')->setHeaders(array('Type', 'Count'))->renderByFormat($output, $table, $input->getOption('format')); $htmlReportOutputPath = $this->_input->getArgument('htmlReportOutputPath'); if ($htmlReportOutputPath) { foreach (array(\Mpmd\Util\Compare::DIFFERENT_FILE_CONTENT, \Mpmd\Util\Compare::SAME_FILE_BUT_COMMENTS) as $section) { $diffs[$section] = $compareUtil->getDiffs($data[$section], $pathToVanillaCore, $this->_magentoRootFolder); } $this->_output->writeln("<info>Generating detailed HTML Report</info>"); $htmlReport = new \Mpmd\Util\Report(); $htmlReport->addHeadline('Magento Project Mess Detector: Core Hacks Report'); $htmlReport->addTag('p', "Comparing <strong>{$pathToVanillaCore}</strong> to <strong>{$this->_magentoRootFolder}</strong>"); $htmlTableRenderer = new \Mpmd\Util\HtmlTableRenderer(); foreach ($table as &$row) { $row['Type'] = '<a href="#' . $row['Type'] . '">' . $row['Type'] . '</a>'; } $htmlReport->addHeadline('Summary', 2); unset($data[\Mpmd\Util\Compare::IDENTICAL_FILES]); $htmlReport->addBody($htmlTableRenderer->render($table, array('Type', 'Count'))); $htmlReport->addDiffData($data, $diffs, 'vanilla core', 'project'); file_put_contents($htmlReportOutputPath, $htmlReport->render()); $this->_output->writeln("<info>Writing HTML report to: {$htmlReportOutputPath}</info>"); } // if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { }
/** * Execute command * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @throws \Exception * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->_input = $input; $this->_output = $output; $this->detectMagento($output, true); $this->initMagento(); $this->_output->writeln("<info>Comparing project files in '{$this->_magentoRootFolder}' to vanilla Magento code in '{$pathToVanillaCore}'...</info>"); $skipDirectories = $this->_input->getArgument('skipDirectories'); if (empty($skipDirectories)) { $skipDirectories = '.svn' . PATH_SEPARATOR . '.git'; } $compareUtil = new \Mpmd\Util\Compare(); $data = $compareUtil->compareDirectories($pathToVanillaCore, $this->_magentoRootFolder, '', explode(PATH_SEPARATOR, $skipDirectories)); $pools = array(0 => 'local', 1 => 'community', 2 => 'core', 3 => 'lib'); $data = array(); $diffs = array(); foreach ($pools as $sourcePoolKey => $sourcePoolName) { foreach ($pools as $targetPoolKey => $targetPoolName) { if ($targetPoolKey > $sourcePoolKey) { $this->_output->writeln("<info>Comparing {$sourcePoolName} to {$targetPoolName}</info>"); $tmp = $compareUtil->compareDirectories($this->getCodePoolPath($sourcePoolName), $this->getCodePoolPath($targetPoolName), '', explode(PATH_SEPARATOR, $skipDirectories)); if (isset($tmp[\Mpmd\Util\Compare::FILE_MISSING_IN_B])) { unset($tmp[\Mpmd\Util\Compare::FILE_MISSING_IN_B]); } if (isset($tmp[\Mpmd\Util\Compare::FILE_MISSING_IN_A])) { unset($tmp[\Mpmd\Util\Compare::FILE_MISSING_IN_A]); } // get diffs foreach (array(\Mpmd\Util\Compare::DIFFERENT_FILE_CONTENT, \Mpmd\Util\Compare::SAME_FILE_BUT_COMMENTS) as $section) { $diffs["{$sourcePoolName}-{$targetPoolName}"][$section] = $compareUtil->getDiffs($tmp[$section], $this->getCodePoolPath($sourcePoolName), $this->getCodePoolPath($targetPoolName)); } // Print table $table = array(); foreach ($tmp as $type => $items) { $table[] = array('Type' => $type, 'Count' => count($items)); } $this->getHelper('table')->setHeaders(array('Type', 'Count'))->renderByFormat($output, $table, $input->getOption('format')); $data["{$sourcePoolName}-{$targetPoolName}"] = $tmp; } } } $htmlReportOutputPath = $this->_input->getArgument('htmlReportOutputPath'); if ($htmlReportOutputPath) { $this->_output->writeln("<info>Generating detailed HTML Report</info>"); $htmlReport = new \Mpmd\Util\Report(); $htmlReport->addHeadline('Magento Project Mess Detector: Code Pool Override Report'); $table = '<table>'; $table .= '<tr>'; $table .= '<th></th>'; foreach ($pools as $targetPoolKey => $targetPoolName) { $table .= '<th>' . $targetPoolName . '</th>'; } $table .= '</tr>'; foreach ($pools as $sourcePoolKey => $sourcePoolName) { $table .= '<tr>'; $table .= '<th>' . $sourcePoolName . '</th>'; foreach ($pools as $targetPoolKey => $targetPoolName) { if ($targetPoolKey > $sourcePoolKey) { if (array_sum(array_map('count', $data["{$sourcePoolName}-{$targetPoolName}"])) > 0) { $id = "{$sourcePoolName}-{$targetPoolName}"; $tmp = array(); foreach ($data[$id] as $key => $d) { $c = count($d); if ($c > 0) { $tmp[] = '<a href="#' . $id . '-' . $key . '" title="' . $key . '">' . $c . '</a>'; } else { $tmp[] = '<span title="' . $key . '">' . $c . '</span>'; } } $table .= '<td>' . implode(' / ', $tmp) . '</td>'; } else { $table .= '<td class="ok">✔</td>'; } } else { $table .= '<td class="invalid"></td>'; } } $table .= '</tr>'; } $table .= '</table>'; $htmlReport->addBody($table); foreach ($pools as $sourcePoolKey => $sourcePoolName) { foreach ($pools as $targetPoolKey => $targetPoolName) { if ($targetPoolKey > $sourcePoolKey) { if (array_sum(array_map('count', $data["{$sourcePoolName}-{$targetPoolName}"])) > 0) { $id = "{$sourcePoolName}-{$targetPoolName}"; $htmlReport->addHeadline("Comparing {$sourcePoolName} and {$targetPoolName}", 2, array('id' => $id . '-')); $htmlReport->addDiffData($data["{$sourcePoolName}-{$targetPoolName}"], $diffs["{$sourcePoolName}-{$targetPoolName}"], $sourcePoolName, $targetPoolName, $id . '-'); } } } } file_put_contents($htmlReportOutputPath, $htmlReport->render()); $this->_output->writeln("<info>Writing HTML report to: {$htmlReportOutputPath}</info>"); } }