|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Console\Commands; |
| 4 | +use Illuminate\Support\Facades\Log; |
| 5 | +use Illuminate\Console\Command; |
| 6 | +use Illuminate\Support\Facades\Process; |
| 7 | +class BuildLookupTree extends Command |
| 8 | +{ |
| 9 | + /** |
| 10 | + * The name and signature of the console command. |
| 11 | + * |
| 12 | + * @var string |
| 13 | + */ |
| 14 | + protected $signature = 'app:build-lookup-tree {folder} {file} {type}'; |
| 15 | + |
| 16 | + /** |
| 17 | + * The console command description. |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $description = 'Build database for new weakpass'; |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + public function handle() |
| 26 | + { |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + if(!file_exists($this->argument('folder')) || !is_dir($this->argument('folder'))) |
| 31 | + { |
| 32 | + $this->error($this->argument('folder')." not exist"); |
| 33 | + die(); |
| 34 | + } |
| 35 | + |
| 36 | + if(!file_exists($this->argument('file'))) |
| 37 | + { |
| 38 | + $this->error($this->argument('file')." not exist"); |
| 39 | + die(); |
| 40 | + } |
| 41 | + |
| 42 | + $type=$this->argument('type'); |
| 43 | + $handle = fopen($this->argument('file'), "r"); |
| 44 | + $folder=$this->argument('folder'); |
| 45 | + $prefix=""; |
| 46 | + $prefix_file=FALSE; |
| 47 | + $files=array(); |
| 48 | + if ($handle) { |
| 49 | + while (($line = fgets($handle)) !== false) { |
| 50 | + $tmp_prefix=substr($line, 0, 6); |
| 51 | + if($tmp_prefix!==$prefix) |
| 52 | + { |
| 53 | + |
| 54 | + if ($prefix_file) fclose($prefix_file); |
| 55 | + $folder1 = substr($tmp_prefix, 0, 2); |
| 56 | + $folder2 = substr($tmp_prefix, 2, 2); |
| 57 | + $file = substr($tmp_prefix, 4, 2); |
| 58 | + if(!file_exists($folder.$folder1))mkdir($folder.$folder1); |
| 59 | + if(!file_exists($folder.$folder1."/".$folder2))mkdir($folder.$folder1."/".$folder2); |
| 60 | + |
| 61 | + $path=$folder.$folder1."/".$folder2."/".$file."_".$type; |
| 62 | + $this->info($path); |
| 63 | + $prefix_file = fopen($path, 'a+w'); |
| 64 | + $prefix=$tmp_prefix; |
| 65 | + } |
| 66 | + fwrite($prefix_file,$line); |
| 67 | + } |
| 68 | + fclose($handle); |
| 69 | + } |
| 70 | + if ($prefix_file) fclose($prefix_file); |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + } |
| 76 | +} |
0 commit comments