few updates
parent
f51559fa65
commit
823bd348d2
|
|
@ -29,11 +29,14 @@ class RegistryImportService {
|
|||
}
|
||||
|
||||
|
||||
public function download($url, $dir = null): ?Asset {
|
||||
public function download($url, $dir = null, $filename = null): ?Asset {
|
||||
$urlInfo = parse_url($url);
|
||||
if (empty($urlInfo['host'])) $url = str_replace('//', '/', "https://faufcc.ru/{$url}");
|
||||
$info = pathinfo($url);
|
||||
if ($info['extension']) {
|
||||
$path = "public/documents/registries";
|
||||
$path = $dir ? "{$path}/{$dir}/{$info['basename']}" : "{$path}/{$info['basename']}";
|
||||
$filename = $filename ? "{$filename}.{$info['extension']}" : $info['basename'];
|
||||
$path = $dir ? "{$path}/{$dir}/{$filename}" : "{$path}/{$filename}";
|
||||
$asset = Asset::query()->where(['path' => $path])->first();
|
||||
if (!$asset && Storage::put($path, Http::get($url)->body())) $asset = $this->makeAsset($path);
|
||||
elseif ($asset) var_dump($asset->path);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class RulesetImportService extends RegistryImportService {
|
|||
if (!$this->registry->entries()->where(['name' => $entryName])->exists()) {
|
||||
echo ("Importing {$entryName}\n");
|
||||
$link = $item->find('a', 0);
|
||||
$this->importItem("{$this->url}{$link->href}", $subcategory);
|
||||
$this->importItem("{$this->url}{$link->href}", $subcategory, $entryName);
|
||||
} else echo("Already imported {$entryName}\n");
|
||||
//if ($k >= 5) return;
|
||||
}
|
||||
|
|
@ -56,13 +56,12 @@ class RulesetImportService extends RegistryImportService {
|
|||
}
|
||||
}
|
||||
|
||||
public function importItem(string $url, Category $category) {
|
||||
public function importItem(string $url, Category $category, $name) {
|
||||
$dom = new Dom;
|
||||
$dom->loadFromUrl($url);
|
||||
$link = $dom->find('p.ACTUALNAME a', 0);
|
||||
list($number, $name) = explode('«', $link->text);
|
||||
list($number) = explode('«', $link->text);
|
||||
$number = trim($number);
|
||||
$name = trim($name, '» ');
|
||||
$entry = $category->entries()->firstOrCreate(['registry_id' => $category->registry_id, 'number' => $number]);
|
||||
$entry->update(['name' => $name]);
|
||||
$this->importOperations($entry, array_slice($dom->find('table.inc1 tr')->toArray(), 1));
|
||||
|
|
@ -100,7 +99,8 @@ class RulesetImportService extends RegistryImportService {
|
|||
list($orderName, $orderDate) = explode(' от ', $link->text);
|
||||
$data['order-name'] = $orderName;
|
||||
$data['order-date'] = $orderDate ? Date::create($orderDate) : null;
|
||||
$data['order-document'] = $this->download($link->href, 'ruleset');
|
||||
$filename = $orderName ? Str::slug("Приказ {$orderName} от {$orderDate}") : null;
|
||||
$data['order-document'] = $this->download($link->href, 'ruleset', $filename);
|
||||
} else $data['listings'][] = ['name' => Str::replace('Постановление правительства №', 'pp', $link->text)];
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue