relationship tagging data process script
Showing
5 changed files
with
151 additions
and
0 deletions
| 1 | <?php namespace App\Console\Commands; | ||
| 2 | |||
| 3 | use Illuminate\Console\Command; | ||
| 4 | |||
| 5 | use DB; | ||
| 6 | use App\Models\RelationshipService; | ||
| 7 | use App\Models\RelationshipCategory; | ||
| 8 | use App\Models\RelationshipSubCategory; | ||
| 9 | |||
| 10 | use Config; | ||
| 11 | use Schema; | ||
| 12 | use PDO; | ||
| 13 | |||
| 14 | use Illuminate\Database\Schema\Blueprint; | ||
| 15 | |||
| 16 | class relationship_tag extends Command { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * The console command name. | ||
| 20 | * | ||
| 21 | * @var string | ||
| 22 | */ | ||
| 23 | protected $signature = 'relationship_tag'; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * The console command description. | ||
| 27 | * | ||
| 28 | * @var string | ||
| 29 | */ | ||
| 30 | protected $description = 'relationship_tag'; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Execute the console command. | ||
| 34 | * | ||
| 35 | * @return mixed | ||
| 36 | */ | ||
| 37 | public function handle() | ||
| 38 | { | ||
| 39 | $nowts=time(); | ||
| 40 | |||
| 41 | echo date('Y-m-d H:i:s')."\n"; | ||
| 42 | |||
| 43 | $tcol=0;$fieldsarr=array();$extrahdrarr=array(); | ||
| 44 | $server_ip=env('app_ip'); | ||
| 45 | $central_ip=env('app_ip'); | ||
| 46 | |||
| 47 | $conn = array( | ||
| 48 | 'driver' => 'mysql', | ||
| 49 | 'host' => $central_ip, | ||
| 50 | 'database' => env('DB_DATABASE', 'kstych_flexydial'), | ||
| 51 | 'username' => env('DB_USERNAME', 'root'), | ||
| 52 | 'password' => env('DB_PASSWORD', ''), | ||
| 53 | 'charset' => 'utf8', | ||
| 54 | 'collation' => 'utf8_unicode_ci', | ||
| 55 | 'prefix' => '', | ||
| 56 | 'options' => array( | ||
| 57 | PDO::ATTR_TIMEOUT => 5, | ||
| 58 | ), | ||
| 59 | ); | ||
| 60 | |||
| 61 | Config::set("database.connections.conn", $conn); | ||
| 62 | |||
| 63 | if(DB::connection("conn")->getDatabaseName()) | ||
| 64 | { | ||
| 65 | $relationshipList = DB::connection("conn")->select(DB::raw("SELECT * FROM relationship_tagging")); | ||
| 66 | |||
| 67 | $relationshipData = 0; $newService = 0; $newCategory = 0; $newSubCategory = 0; | ||
| 68 | |||
| 69 | foreach ($relationshipList as $list) { | ||
| 70 | $service = RelationshipService::where('title','=',$list->service)->first(); | ||
| 71 | |||
| 72 | if(count($service)){ | ||
| 73 | $serviceId = $service->id; | ||
| 74 | }else{ | ||
| 75 | $addService = RelationshipService::create(['title'=>$list->service]); | ||
| 76 | $serviceId = $addService->id; | ||
| 77 | $newService++; | ||
| 78 | } | ||
| 79 | echo $list->service." : ".$serviceId." - "; | ||
| 80 | |||
| 81 | $category = RelationshipCategory::where('service_id','=',$serviceId)->where('title','=',$list->category)->first(); | ||
| 82 | |||
| 83 | if(count($category)){ | ||
| 84 | $categoryId = $category->id; | ||
| 85 | }else{ | ||
| 86 | $addCategory = RelationshipCategory::create(['service_id'=>$serviceId,'title'=>$list->category]); | ||
| 87 | $categoryId = $addCategory->id; | ||
| 88 | $newCategory++; | ||
| 89 | } | ||
| 90 | echo $list->category." : ".$categoryId." - "; | ||
| 91 | |||
| 92 | $subCategory = RelationshipSubCategory::where('category_id','=',$categoryId)->where('title','=',$list->sub_category)->first(); | ||
| 93 | |||
| 94 | if(count($subCategory)){ | ||
| 95 | $subCategoryId = $subCategory->id; | ||
| 96 | }else{ | ||
| 97 | $addSubCategory = RelationshipSubCategory::create(['category_id'=>$categoryId,'title'=>$list->sub_category]); | ||
| 98 | $subCategoryId = $addSubCategory->id; | ||
| 99 | $newSubCategory++; | ||
| 100 | } | ||
| 101 | echo $list->sub_category." : ".$subCategoryId."\n"; | ||
| 102 | |||
| 103 | //DB::table('relationship_tagging')->where('id', $list->id)->update(['status'=>'InActive']); | ||
| 104 | $relationshipData++; | ||
| 105 | } | ||
| 106 | echo "Total ".$relationshipData." data process and ". $newService." service, ".$newCategory." category, ".$newSubCategory." sub category added\n"; | ||
| 107 | |||
| 108 | DB::connection("conn")->disconnect(); | ||
| 109 | |||
| 110 | } | ||
| 111 | |||
| 112 | } | ||
| 113 | |||
| 114 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -35,6 +35,7 @@ protected $commands = [ | ... | @@ -35,6 +35,7 @@ protected $commands = [ |
| 35 | 'App\Console\Commands\dailyupload_calllog', | 35 | 'App\Console\Commands\dailyupload_calllog', |
| 36 | 'App\Console\Commands\dailyupload_questionaire', | 36 | 'App\Console\Commands\dailyupload_questionaire', |
| 37 | 'App\Console\Commands\relationship_data', | 37 | 'App\Console\Commands\relationship_data', |
| 38 | 'App\Console\Commands\relationship_tag', | ||
| 38 | ]; | 39 | ]; |
| 39 | 40 | ||
| 40 | /** | 41 | /** | ... | ... |
-
Please register or sign in to post a comment