Symfony-条令-更改编码-所有实体和行

Symfony-条令-更改编码-所有实体和行,symfony,encoding,doctrine,Symfony,Encoding,Doctrine,我需要更改symfony中的编码。问题是有一个产品包含一些数据。有没有办法列出所有实体、所有行以及字符串/文本列更改编码的方法?我没有找到更好的解决方案,所以我在迁移中找到了: $entityManager = $this->container->get('doctrine.orm.entity_manager'); $entities = $entityManager->getConfiguration()->getMetadataDriverImpl(

我需要更改symfony中的编码。问题是有一个产品包含一些数据。有没有办法列出所有实体、所有行以及字符串/文本列更改编码的方法?

我没有找到更好的解决方案,所以我在迁移中找到了:

    $entityManager = $this->container->get('doctrine.orm.entity_manager');
    $entities = $entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();

    foreach ($entities as $className) {
        if ((strpos($className, "AppBundle") !== false) && (strpos($className, "Abstract") === false)) { //only my classes and no abstract class
            $records = $entityManager->getRepository($className)->findAll();
            $metadata = $entityManager->getClassMetadata($className);
            $entity_fields = $metadata->getFieldNames();
            foreach ($entity_fields as $field) {
                $type = $metadata->getTypeOfField($field);
                if ($type === "string") {
                    foreach ($records as $record) {
                        $oldValue = $metadata->getReflectionProperty($field)->getValue($record);
                        $metadata->getReflectionProperty($field)->setValue($record, " ");
                        $entityManager->persist($record);
                        $entityManager->flush();
                        $metadata->getReflectionProperty($field)->setValue($record, trim($oldValue));
                        $entityManager->persist($record);
                        $entityManager->flush();
                    }
                }
            }
        }
    }