<?php
namespace Entity; class Validator_FluxInstance extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); $model = new \Modules\Admin\FluxInstances\Model(); $system = $model->getSystem($fields['assignedSystem']); if ($fields['name']) { $list = new \App\EntityList\FluxInstances(); $list->setFilter('instance.name', '=', $fields['name']); $list->setLimit(1); if ($list->exportRecords()) { $currentMessages->addWarningCode('insert_nameNotUnique'); } } if ($fields['appToken']) { $list = new \App\EntityList\FluxInstances(); $list->setFilter('instance.appToken', '=', $fields['appToken']); $list->setLimit(1); if ($list->exportRecords()) { $currentMessages->addWarningCode('insert_appTokenNotUnique'); } } if ($system->isImporter and !$fields['confirmedPath']) { $currentMessages->addWarningCode('insert_confirmedPathMandatory'); } if (($system->isExporter || $system->isImporter) and !$fields['basePath']) { $currentMessages->addWarningCode('insert_basePathMandatory'); } if ($system->isImporter and !$fields['behaviourOnInvalidFile']) { $currentMessages->addWarningCode('insert_behaviourOnInvalidFileMandatory'); } if (($system->isExporter || $system->isImporter) and !$fields['createMonthBasedFolders']) { $currentMessages->addWarningCode('insert_createMonthBasedFoldersMandatory'); } } protected function check_update() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); $currentEntityId = $this->entity->getId(); $model = new \Modules\Admin\FluxInstances\Model(); $system = $model->getSystem($fields['assignedSystem']); if ($fields['name']) { $list = new \App\EntityList\FluxInstances(); $list->setFilter('instance.name', '=', $fields['name']); $list->setFilter('instance.id', '!=', $currentEntityId); $list->setLimit(1); if ($list->exportRecords()) { $currentMessages->addWarningCode('insert_nameNotUnique'); } } if (array_key_exists('appToken', $fields)) { $currentMessages->addWarningCode('insert_appTokenDeniedUpdate'); } if ($system->isImporter and !$fields['confirmedPath']) { $currentMessages->addWarningCode('insert_confirmedPathMandatory'); } if ($system->isImporter and !$fields['behaviourOnInvalidFile']) { $currentMessages->addWarningCode('insert_behaviourOnInvalidFileMandatory'); } if (($system->isExporter || $system->isImporter) and !$fields['createMonthBasedFolders']) { $currentMessages->addWarningCode('insert_createMonthBasedFoldersMandatory'); } } protected function isAvailable_update() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $fluxInstance = \Entity\FluxInstance::selectForUpdate($currentIdEntity); if (!$fluxInstance->recordExists()) { $currMessages->addErrorCode('update_invalidId'); } } protected function isAvailable_delete() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $fluxInstance = \Entity\FluxInstance::selectForUpdate($currentIdEntity); if (!$fluxInstance->recordExists()) { $currMessages->addErrorCode('delete_invalidId'); } } }