4a9f4561 by Yashwant

relationship tagging data process script

1 parent 59b5c059
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use App\Models\RelationshipService;
use App\Models\RelationshipCategory;
use App\Models\RelationshipSubCategory;
use Config;
use Schema;
use PDO;
use Illuminate\Database\Schema\Blueprint;
class relationship_tag extends Command {
/**
* The console command name.
*
* @var string
*/
protected $signature = 'relationship_tag';
/**
* The console command description.
*
* @var string
*/
protected $description = 'relationship_tag';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nowts=time();
echo date('Y-m-d H:i:s')."\n";
$tcol=0;$fieldsarr=array();$extrahdrarr=array();
$server_ip=env('app_ip');
$central_ip=env('app_ip');
$conn = array(
'driver' => 'mysql',
'host' => $central_ip,
'database' => env('DB_DATABASE', 'kstych_flexydial'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_TIMEOUT => 5,
),
);
Config::set("database.connections.conn", $conn);
if(DB::connection("conn")->getDatabaseName())
{
$relationshipList = DB::connection("conn")->select(DB::raw("SELECT * FROM relationship_tagging"));
$relationshipData = 0; $newService = 0; $newCategory = 0; $newSubCategory = 0;
foreach ($relationshipList as $list) {
$service = RelationshipService::where('title','=',$list->service)->first();
if(count($service)){
$serviceId = $service->id;
}else{
$addService = RelationshipService::create(['title'=>$list->service]);
$serviceId = $addService->id;
$newService++;
}
echo $list->service." : ".$serviceId." - ";
$category = RelationshipCategory::where('service_id','=',$serviceId)->where('title','=',$list->category)->first();
if(count($category)){
$categoryId = $category->id;
}else{
$addCategory = RelationshipCategory::create(['service_id'=>$serviceId,'title'=>$list->category]);
$categoryId = $addCategory->id;
$newCategory++;
}
echo $list->category." : ".$categoryId." - ";
$subCategory = RelationshipSubCategory::where('category_id','=',$categoryId)->where('title','=',$list->sub_category)->first();
if(count($subCategory)){
$subCategoryId = $subCategory->id;
}else{
$addSubCategory = RelationshipSubCategory::create(['category_id'=>$categoryId,'title'=>$list->sub_category]);
$subCategoryId = $addSubCategory->id;
$newSubCategory++;
}
echo $list->sub_category." : ".$subCategoryId."\n";
//DB::table('relationship_tagging')->where('id', $list->id)->update(['status'=>'InActive']);
$relationshipData++;
}
echo "Total ".$relationshipData." data process and ". $newService." service, ".$newCategory." category, ".$newSubCategory." sub category added\n";
DB::connection("conn")->disconnect();
}
}
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ protected $commands = [
'App\Console\Commands\dailyupload_calllog',
'App\Console\Commands\dailyupload_questionaire',
'App\Console\Commands\relationship_data',
'App\Console\Commands\relationship_tag',
];
/**
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RelationshipCategory extends Model{
protected $table = 'relationship_category';
protected $fillable = ['service_id','title'];
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RelationshipService extends Model{
protected $table = 'relationship_service';
protected $fillable = ['title'];
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RelationshipSubCategory extends Model{
protected $table = 'relationship_sub_category';
protected $fillable = ['category_id','title'];
}
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!