|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Irfa\RajaOngkir\Caching; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class DBImport |
|
8
|
|
|
{ |
|
9
|
|
|
protected static $table_DB; |
|
10
|
|
|
|
|
11
|
|
|
protected static function import($table, $result, $type = 'prov') |
|
12
|
|
|
{ |
|
13
|
|
|
self::$table_DB = $table; |
|
14
|
|
|
echo 'Creating cache... '.PHP_EOL; |
|
15
|
|
|
self::extractor($result, $type); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
private static function extractor($result, $type) |
|
19
|
|
|
{ |
|
20
|
|
|
try { |
|
21
|
|
|
foreach ($result as $r) { |
|
22
|
|
|
if ($type == 'prov') { |
|
23
|
|
|
$fill = ['province_id' => $r->province_id, 'province' => $r->province]; |
|
24
|
|
|
$where = ['province_id' => $r->province_id]; |
|
25
|
|
|
} elseif ($type == 'city') { |
|
26
|
|
|
$fill = ['city_id'=>$r->city_id, 'province_id'=>$r->province_id, 'province' => $r->province, 'type'=>$r->type, 'city_name'=>$r->city_name, 'postal_code'=>$r->postal_code]; |
|
27
|
|
|
$where = ['city_id' => $r->city_id]; |
|
28
|
|
|
} elseif ($type == 'subdistrict') { |
|
29
|
|
|
$fill = ['subdistrict_id'=>$r->subdistrict_id, 'province_id'=>$r->province_id, 'province' => $r->province, 'city_id'=>$r->city_id, 'city'=>$r->city, 'type'=>$r->type,'subdistrict_name'=>$r->subdistrict_name]; |
|
30
|
|
|
$where = ['subdistrict_id' => $r->subdistrict_id]; |
|
31
|
|
|
} |
|
32
|
|
|
if (DB::table(self::$table_DB)->where($where)->count() == 0) { |
|
|
|
|
|
|
33
|
|
|
DB::table(self::$table_DB)->insert($fill); |
|
|
|
|
|
|
34
|
|
|
} else { |
|
35
|
|
|
DB::table(self::$table_DB)->where($where)->update($fill); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
$count = DB::table(self::$table_DB)->count(); |
|
39
|
|
|
echo 'Cache has been created, '.$count.' row(s) affected.'; |
|
40
|
|
|
} catch (\Exception $e) { |
|
41
|
|
|
echo "\033[91mCan't creating cache. Error\033[0m : ".$e; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths