diff --git a/sources/Forms/IO/Converter/OqlToClassConverter.php b/sources/Forms/IO/Converter/OqlToClassConverter.php index 1ee291865..66e36d71b 100644 --- a/sources/Forms/IO/Converter/OqlToClassConverter.php +++ b/sources/Forms/IO/Converter/OqlToClassConverter.php @@ -7,6 +7,7 @@ namespace Combodo\iTop\Forms\IO\Converter; +use Combodo\iTop\Service\DependencyInjection\DIException; use Combodo\iTop\Service\DependencyInjection\DIService; use Combodo\iTop\Forms\IO\Format\ClassIOFormat; use Combodo\iTop\Forms\IO\FormBlockIOException; @@ -17,8 +18,8 @@ use Combodo\iTop\Forms\IO\FormBlockIOException; class OqlToClassConverter extends AbstractConverter { /** @inheritdoc - * @throws \Combodo\iTop\Forms\IO\FormBlockIOException - * @throws \Combodo\iTop\Service\DependencyInjection\DIException + * @throws DIException + * @throws FormBlockIOException */ public function Convert(mixed $oData): ?ClassIOFormat { @@ -26,22 +27,8 @@ class OqlToClassConverter extends AbstractConverter return null; } - // Extract OQL information - preg_match('/SELECT\s+(\w+)/', $oData, $aMatches); - - // Selected class - if (isset($aMatches[1])) { - $sSelectedClass = $aMatches[1]; - /** @var \ModelReflection $oModelReflection */ - $oModelReflection = DIService::GetInstance()->GetService('ModelReflection'); - if (!$oModelReflection->IsValidClass($sSelectedClass)) { - throw new FormBlockIOException('Class '.json_encode($sSelectedClass).' not found'); - } - - return new ClassIOFormat($aMatches[1]); - } else { - throw new FormBlockIOException('Incorrect OQL sentence '.json_encode($oData)); - } - + $oModelReflection = DIService::GetInstance()->GetService('ModelReflection'); + $oQuery = $oModelReflection->GetQuery($oData); + return new ClassIOFormat($oQuery->GetClass()); } }