108 lines
3.3 KiB
PHP
108 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
/**
|
|
* Импорт заболеваний из материализованного представления (Bitrix view).
|
|
*
|
|
* См. DiseaseController + CrudResponder для CRUD; этот сервис — только syncFromView*.
|
|
*/
|
|
final class DiseaseCrudService
|
|
{
|
|
public function __construct(
|
|
private EntityManagerInterface $em,
|
|
) {
|
|
}
|
|
|
|
public function syncFromViewDisease(string $viewName = 'public.view_disease'): int
|
|
{
|
|
if (!preg_match('/^[A-Za-z0-9_\.]+$/', $viewName)) {
|
|
throw new \InvalidArgumentException('Invalid view name');
|
|
}
|
|
|
|
$sql = sprintf(
|
|
'INSERT INTO disease (
|
|
id,
|
|
name,
|
|
preview_picture,
|
|
active,
|
|
region_id,
|
|
alias,
|
|
anons,
|
|
update_at,
|
|
hide_picture,
|
|
read_time,
|
|
diseases_name,
|
|
tags_important,
|
|
tags,
|
|
diseases_other_name,
|
|
symptom,
|
|
staff,
|
|
link_services,
|
|
staff_list,
|
|
staff_post,
|
|
staff_post_exclude,
|
|
link_faq,
|
|
bibliography,
|
|
staff_check,
|
|
content
|
|
)
|
|
SELECT
|
|
id,
|
|
name,
|
|
preview_picture,
|
|
active,
|
|
region_id,
|
|
alias,
|
|
anons,
|
|
update_at,
|
|
hide_picture,
|
|
read_time,
|
|
diseases_name,
|
|
tags_important,
|
|
tags,
|
|
diseases_other_name,
|
|
symptom,
|
|
staff,
|
|
link_services,
|
|
staff_list,
|
|
staff_post,
|
|
staff_post_exclude,
|
|
link_faq,
|
|
bibliography,
|
|
staff_check,
|
|
content
|
|
FROM %s
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
preview_picture = EXCLUDED.preview_picture,
|
|
active = EXCLUDED.active,
|
|
region_id = EXCLUDED.region_id,
|
|
alias = EXCLUDED.alias,
|
|
anons = EXCLUDED.anons,
|
|
update_at = EXCLUDED.update_at,
|
|
hide_picture = EXCLUDED.hide_picture,
|
|
read_time = EXCLUDED.read_time,
|
|
diseases_name = EXCLUDED.diseases_name,
|
|
tags_important = EXCLUDED.tags_important,
|
|
tags = EXCLUDED.tags,
|
|
diseases_other_name = EXCLUDED.diseases_other_name,
|
|
symptom = EXCLUDED.symptom,
|
|
staff = EXCLUDED.staff,
|
|
link_services = EXCLUDED.link_services,
|
|
staff_list = EXCLUDED.staff_list,
|
|
staff_post = EXCLUDED.staff_post,
|
|
staff_post_exclude = EXCLUDED.staff_post_exclude,
|
|
link_faq = EXCLUDED.link_faq,
|
|
bibliography = EXCLUDED.bibliography,
|
|
staff_check = EXCLUDED.staff_check,
|
|
content = EXCLUDED.content',
|
|
$viewName
|
|
);
|
|
|
|
return (int) $this->em->getConnection()->executeStatement($sql);
|
|
}
|
|
}
|