- Миграция devices (name, type, ip, mac, hostname, vendor, os, location, importance, status) - Device model + DeviceRepository с полным CRUD - DeviceService для бизнес-логики - MergeSuggestionService для предложений объединения (MAC→90%, hostname→60%) - DeviceController: список, создание, редактирование, карточка, удаление, создание из discovered_host - Шаблоны: devices/index, devices/form, devices/show - Dashboard с реальными счётчиками (устройства, новые находки) - Кнопка «Создать устройство» в Discovery для новых хостов - DeviceRepository + DeviceService + DeviceController в DI
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domovoy\Services\Inventory;
|
|
|
|
use Domovoy\Models\Device;
|
|
use Domovoy\Repositories\DeviceRepository;
|
|
|
|
class DeviceService
|
|
{
|
|
private DeviceRepository $deviceRepository;
|
|
|
|
public function __construct(DeviceRepository $deviceRepository)
|
|
{
|
|
$this->deviceRepository = $deviceRepository;
|
|
}
|
|
|
|
public function createFromDiscoveredHost(
|
|
string $name,
|
|
string $ipAddress,
|
|
?string $macAddress = null,
|
|
?string $hostname = null,
|
|
?string $vendor = null
|
|
): Device {
|
|
$device = new Device();
|
|
$device->name = $name;
|
|
$device->primaryIp = $ipAddress;
|
|
$device->macAddress = $macAddress;
|
|
$device->hostname = $hostname;
|
|
$device->vendor = $vendor;
|
|
$device->type = 'unknown';
|
|
$device->status = 'active';
|
|
$device->importance = 'normal';
|
|
|
|
$this->deviceRepository->save($device);
|
|
return $device;
|
|
}
|
|
|
|
public function getAllDevices(): array
|
|
{
|
|
return $this->deviceRepository->findAll();
|
|
}
|
|
|
|
public function getDevice(int $id): ?Device
|
|
{
|
|
return $this->deviceRepository->findById($id);
|
|
}
|
|
|
|
public function updateDevice(Device $device): void
|
|
{
|
|
$this->deviceRepository->save($device);
|
|
}
|
|
|
|
public function deleteDevice(int $id): void
|
|
{
|
|
$this->deviceRepository->delete($id);
|
|
}
|
|
}
|