|
@@ -0,0 +1,56 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace app\command;
|
|
|
|
+
|
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
+use support\Redis;
|
|
|
|
+use App\services\TrackService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class FixTrackLog extends Command
|
|
|
|
+{
|
|
|
|
+ protected static $defaultName = 'fix_track_log';
|
|
|
|
+ protected static $defaultDescription = '根据 /app/runtime/logs/tarck/ 下的文件修复日志';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ protected function configure()
|
|
|
|
+ {
|
|
|
|
+ //$this->addArgument('file', InputArgument::OPTIONAL, '文件路径及其名称');
|
|
|
|
+ $this->addOption('file', 'file', InputOption::VALUE_REQUIRED, '要解析的文件名称');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param InputInterface $input
|
|
|
|
+ * @param OutputInterface $output
|
|
|
|
+ * @return int
|
|
|
|
+ */
|
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
+ {
|
|
|
|
+ $file = $input->getOption('file');
|
|
|
|
+ $fileData = function($file) {
|
|
|
|
+ $content = fopen($file, 'r');
|
|
|
|
+ //if (!$file) die('file does not exist or cannot be opened');
|
|
|
|
+ while (($line = fgets($content)) !== false) {
|
|
|
|
+ yield $line;
|
|
|
|
+ }
|
|
|
|
+ fclose($content);
|
|
|
|
+ };
|
|
|
|
+ foreach ($fileData($file) as $line) {
|
|
|
|
+ $line = explode(": ", $line);
|
|
|
|
+ $paramsc = $line[count($line)-1];
|
|
|
|
+ $params = json_decode($paramsc,true);
|
|
|
|
+ if (!is_array($params)) {
|
|
|
|
+ $output->writeln('不是json:'.$params);
|
|
|
|
+ }
|
|
|
|
+ TrackService::push($params,1);
|
|
|
|
+ }
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|