/** * Main Runner */ public function run() { try { $console = new Console(); $render = null; $destinationProcessedCount = 0; $destinationProcessedSuccessCount = 0; $taxonomyFilePath = $console->inputDir . DS . BatchProcessor::app()->config->get('taxonomy_file'); $destinationsFilePath = $console->inputDir . DS . BatchProcessor::app()->config->get('destinations_file'); if (!file_exists($console->outputDir)) { $console->close("`{$console->outputDir}` output directory does not exists.", Console::ERROR_OUT); } if (!is_writable($console->outputDir)) { $console->close("Specified output directory is not writable.", Console::ERROR_OUT); } $this->logger = new Logger($console->outputDir . DS . 'log'); $console->write(date('F j, Y, H:i:s') . " :: Starting file processing..."); $this->logger->notice('----------------------'); $this->logger->info('Started file processing'); $render = new HtmlRender(BatchProcessor::app()->config->get('template_dir_path'), $console->outputDir); $destinationHandler = new DestinationHandler($destinationsFilePath); $taxonomyHandler = new TaxonomyHandler($taxonomyFilePath); while ($destination = $destinationHandler->fetch()) { if (!$taxonomyHandler->hasNode($destination)) { $this->logger->alert('Destination with atlas id ' . $destination->id . ' node details not found in taxonomy.'); } $fileName = self::makeFileName($destination->id, $destination->title); $dataWritten = file_put_contents($console->outputDir . DS . $fileName, $render->render(['destination' => $destination, 'taxonomyHandler' => $taxonomyHandler])); $destinationProcessedCount++; if ($dataWritten !== false) { $this->logger->info('destination file created - ' . $fileName); $destinationProcessedSuccessCount++; } else { $this->logger->error('failed to create destination file - ' . $fileName); } } $console->write(date('F j, Y, H:i:s') . " :: Processing finished.\n"); $console->write("Memory Usage: " . self::convert(memory_get_usage())); $console->write("Total Files Written: {$destinationProcessedSuccessCount}"); $console->write("Total Failed: " . ($destinationProcessedCount - $destinationProcessedSuccessCount)); $this->logger->info('Processing finished.'); $this->logger->info('Memory Usage: ' . self::convert(memory_get_usage())); $this->logger->info("Total Files Written: {$destinationProcessedSuccessCount}"); $this->logger->info('Total Failed: ' . ($destinationProcessedCount - $destinationProcessedSuccessCount)); } catch (\Exception $ex) { $message = $ex->getMessage() . "\n" . $ex->getTraceAsString(); $this->logger->debug($message); $console->close($message, Console::ERROR_OUT); } }
use LP\App; /** * Use to create and return a single instance of the application. * Class BatchProcessor * @package LP */ class BatchProcessor { /** * @var string Specify the full path to the configuration file. */ public static $configFile = ''; /** * @var null Holds the single instance of the application */ private static $app = null; /** * @return App Return a single instance of App */ public static function app() { if (static::$app === null) { static::$app = new App(static::$configFile); } return static::$app; } } // Specify the configuration file BatchProcessor::$configFile = dirname(__FILE__) . DS . 'config.php'; BatchProcessor::app()->run();
echo $destination->title; ?> </li> <?php if ($taxonomyHandler->hasChildren($destination)) { $childrenIds = $taxonomyHandler->getChildrenIds($destination); ?> <?php foreach ($childrenIds as $id) { ?> <li class="indentation-<?php echo $indentation; ?> "> <a href="<?php echo \LP\BatchProcessor::app()->makeFileName($id, $taxonomyHandler->getNodeTitle($id)); ?> "> <?php echo $taxonomyHandler->getNodeTitle($id); ?> </a></li> <?php } ?> <?php } ?> <?php } else { ?>