Repository: pimcore/pimcore (language: php)

Issue:
[Bug]: Classification Store - NULL value allowed for property $sorter of KeyGroupRelation and CollectionGroupRelation
### Pimcore version

11.1.5

### Steps to reproduce

The bug is due to the fact that `NULL` value is allowed for `$sorter` property in the database.
So when we open a group/group-collection from Pimcore interface, we will get an exception saying that we are trying to access a property not initialized.
You can reproduce the bug by implementing an import command, which creates a group/group-collection with existing keys, but without specifying the `$sorter` value.

### Actual Behavior

```
Timestamp: Tue Mar 05 2024 10:36:05 GMT+0100 (heure normale d’Europe centrale)
Status: 500 | Internal Server Error
URL: /admin/classificationstore/relations
Method: GET
Message: Typed property Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation::$sorter must not be accessed before initialization
Trace: 
in /var/www/html/vendor/pimcore/pimcore/models/DataObject/Classificationstore/KeyGroupRelation.php:131
#0 /var/www/html/vendor/pimcore/admin-ui-classic-bundle/src/Controller/Admin/DataObject/ClassificationstoreController.php(941): Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation->getSorter()
#1 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Pimcore\Bundle\AdminBundle\Controller\Admin\DataObject\ClassificationstoreController->relationsActionGet(Object(Symfony\Component\HttpFoundation\Request))
#2 /var/www/html/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#3 /var/www/html/vendor/symfony/http-kernel/Kernel.php(197): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#4 /var/www/html/public/index.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#5 {main}
```

### Expected Behavior

The bug could be resolved in either two ways:
1. In database, change the default value of `$sorter` from `NULL` to `0` (for an int).
2. When load **KeyGroupRelation/CollectionGroupRelation** objects, convert `NULL` to appropriate value of the property (which is already done for `$enabled` and `$mandatory` properties).
```php
/* Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation\Dao.php */

/**
     *
     * @throws NotFoundException
     */
    public function getById(int $keyId, int $groupId): void
    {
        $this->model->setKeyId($keyId);
        $this->model->setGroupId($groupId);

        $data = $this->db->fetchAssociative(
            sprintf(
                'SELECT * FROM `%1$s` LEFT JOIN `%2$s` ON `%1$s`.`keyId` = `%2$s`.`id` WHERE `%1$s`.`keyId` = ? AND `%1$s`.`groupId` = ?',
                self::TABLE_NAME_RELATIONS,
                Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS
            ),
            [$this->model->getKeyId(), $this->model->getGroupId()]
        );

        if (!empty($data['keyId'])) {
            $data['enabled'] = (bool)$data['enabled'];
            $data['mandatory'] = (bool)$data['mandatory'];
            $this->assignVariablesToModel($data);
        } else {
            throw new NotFoundException(sprintf(
                'KeyGroupRelation with keyId: %s and groupId: %s does not exist',
                $this->model->getKeyId(),
                $this->model->getGroupId()
            ));
        }
    }
```
[Bug]: Classification Store - NULL value allowed for property $sorter of KeyGroupRelation and CollectionGroupRelation
### Pimcore version

11.1.5

### Steps to reproduce

The bug is due to the fact that `NULL` value is allowed for `$sorter` property in the database.
So when we open a group/group-collection from Pimcore interface, we will get an exception saying that we are trying to access a property not initialized.
You can reproduce the bug by implementing an import command, which creates a group/group-collection with existing keys, but without specifying the `$sorter` value.

### Actual Behavior

```
Timestamp: Tue Mar 05 2024 10:36:05 GMT+0100 (heure normale d’Europe centrale)
Status: 500 | Internal Server Error
URL: /admin/classificationstore/relations
Method: GET
Message: Typed property Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation::$sorter must not be accessed before initialization
Trace: 
in /var/www/html/vendor/pimcore/pimcore/models/DataObject/Classificationstore/KeyGroupRelation.php:131
#0 /var/www/html/vendor/pimcore/admin-ui-classic-bundle/src/Controller/Admin/DataObject/ClassificationstoreController.php(941): Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation->getSorter()
#1 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Pimcore\Bundle\AdminBundle\Controller\Admin\DataObject\ClassificationstoreController->relationsActionGet(Object(Symfony\Component\HttpFoundation\Request))
#2 /var/www/html/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#3 /var/www/html/vendor/symfony/http-kernel/Kernel.php(197): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#4 /var/www/html/public/index.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#5 {main}
```

### Expected Behavior

The bug could be resolved in either two ways:
1. In database, change the default value of `$sorter` from `NULL` to `0` (for an int).
2. When load **KeyGroupRelation/CollectionGroupRelation** objects, convert `NULL` to appropriate value of the property (which is already done for `$enabled` and `$mandatory` properties).
```php
/* Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation\Dao.php */

/**
     *
     * @throws NotFoundException
     */
    public function getById(int $keyId, int $groupId): void
    {
        $this->model->setKeyId($keyId);
        $this->model->setGroupId($groupId);

        $data = $this->db->fetchAssociative(
            sprintf(
                'SELECT * FROM `%1$s` LEFT JOIN `%2$s` ON `%1$s`.`keyId` = `%2$s`.`id` WHERE `%1$s`.`keyId` = ? AND `%1$s`.`groupId` = ?',
                self::TABLE_NAME_RELATIONS,
                Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS
            ),
            [$this->model->getKeyId(), $this->model->getGroupId()]
        );

        if (!empty($data['keyId'])) {
            $data['enabled'] = (bool)$data['enabled'];
            $data['mandatory'] = (bool)$data['mandatory'];
            $this->assignVariablesToModel($data);
        } else {
            throw new NotFoundException(sprintf(
                'KeyGroupRelation with keyId: %s and groupId: %s does not exist',
                $this->model->getKeyId(),
                $this->model->getGroupId()
            ));
        }
    }
```


Discussion / hints:

Fix patch:
diff --git a/models/DataObject/Classificationstore/KeyGroupRelation.php b/models/DataObject/Classificationstore/KeyGroupRelation.php
index 0db1728cbc5..50154fe03a9 100644
--- a/models/DataObject/Classificationstore/KeyGroupRelation.php
+++ b/models/DataObject/Classificationstore/KeyGroupRelation.php
@@ -50,7 +50,7 @@ final class KeyGroupRelation extends Model\AbstractModel
      */
     protected string $type;
 
-    protected int $sorter;
+    protected int $sorter = 0;
 
     /**
      * The group name
@@ -59,7 +59,7 @@ final class KeyGroupRelation extends Model\AbstractModel
 
     protected bool $mandatory = false;
 
-    protected bool $enabled;
+    protected bool $enabled = true;
 
     public static function create(): self
     {


Test patch: