remove unused inputfilter; add logging; fix schools schema

parent 75f92e2c
<?php
use GrEduLabs\Schools\InputFilter\Lab;
use GrEduLabs\Schools\InputFilter\School as SchoolInputFilter;
use GrEduLabs\Schools\Service\AssetServiceInterface;
use GrEduLabs\Schools\Service\LabServiceInterface;
......@@ -58,7 +57,6 @@ return function (App $app) {
$c->get('SchInventory\\Service'),
$c->get(SchoolServiceInterface::class),
$c->get('authentication_service'),
$c->get(Lab::class),
$c->get('logger')
);
};
......
......@@ -10,6 +10,7 @@
namespace SchSync\Middleware;
use Exception;
use GrEduLabs\Schools\Service\AssetServiceInterface;
use GrEduLabs\Schools\Service\LabServiceInterface;
use GrEduLabs\Schools\Service\SchoolServiceInterface;
......@@ -52,12 +53,6 @@ class CreateLabs
*/
protected $authService;
/**
*
* @var callable
*/
protected $inputFilter;
/**
* @var LoggerInterface
*/
......@@ -69,7 +64,6 @@ class CreateLabs
InventoryService $inventoryService,
SchoolServiceInterface $schoolService,
AuthenticationServiceInterface $authService,
callable $inputFilter,
LoggerInterface $logger
) {
$this->labService = $labService;
......@@ -77,7 +71,6 @@ class CreateLabs
$this->inventoryService = $inventoryService;
$this->schoolService = $schoolService;
$this->authService = $authService;
$this->inputFilter = $inputFilter;
$this->logger = $logger;
}
......@@ -100,8 +93,14 @@ class CreateLabs
if (0 < count($this->labService->getLabsBySchoolId($school_id))) {
return $res;
}
try {
$equipment = $this->inventoryService->getUnitEquipment($school['registry_no']);
} catch (Exception $e) {
$this->logger->error(sprintf('Problem retrieving assets from inventory for school %s', $school_id));
$this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
return $res;
}
$labTypes = array_reduce($this->labService->getLabTypes(), function ($map, $type) {
$map[trim($type['name'])] = $type['id'];
......@@ -113,7 +112,7 @@ class CreateLabs
return $map;
}, []);
try {
$locations = array_reduce($equipment, function ($uniq, $item) use ($school_id, $labTypes, $assetTypes) {
if (!isset($uniq[$item['location.id']])) {
$locationName = $item['location.name'];
......@@ -141,7 +140,7 @@ class CreateLabs
$type = ($type) ? $assetTypes[$type] : false;
if ($type !== false) {
if (!$uniq[$item['location.id']]->ownSchoolAsset[$type]) {
if (!isset($uniq[$item['location.id']]->ownSchoolAsset[$type])) {
$asset = R::dispense('schoolasset');
$asset->school_id = (int) $school_id;
$asset->itemcategory_id = (int) $type;
......@@ -153,6 +152,11 @@ class CreateLabs
return $uniq;
}, []);
R::storeAll($locations);
$this->logger->info(sprintf('Add assets from inventory for school %s', $school_id));
} catch (Exception $e) {
$this->logger->error(sprintf('Problem inserting assets for school %s in database', $school_id));
$this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
}
return $res;
}
......
......@@ -266,7 +266,7 @@ CREATE TABLE `lab` (
KEY `index_foreignkey_lab_labtype` (`labtype_id`),
KEY `index_foreignkey_lab_responsible` (`responsible_id`),
CONSTRAINT `c_fk_lab_labtype_id` FOREIGN KEY (`labtype_id`) REFERENCES `labtype` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `c_fk_lab_responsible_id` FOREIGN KEY (`responsible_id`) REFERENCES `teacher` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `c_fk_lab_responsible_id` FOREIGN KEY (`responsible_id`) REFERENCES `teacher` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `c_fk_lab_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
......@@ -358,7 +358,10 @@ CREATE TABLE `schoolasset` (
PRIMARY KEY (`id`),
KEY `index_foreignkey_schoolasset_itemcategory` (`itemcategory_id`),
KEY `index_foreignkey_schoolasset_school` (`school_id`),
KEY `index_foreignkey_schoolasset_lab` (`lab_id`)
KEY `index_foreignkey_schoolasset_lab` (`lab_id`),
CONSTRAINT `c_fk_schoolasset_itemcategory_id` FOREIGN KEY (`itemcategory_id`) REFERENCES `itemcategory` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `c_fk_schoolasset_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_schoolasset_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment