Skip to content

Commit 5ed06bd

Browse files
refs #6209
1 parent 1733b64 commit 5ed06bd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/build/migrate/migrate.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class Inventory_Migrate extends Core_Script_Populate
1414
*/
1515
private $em;
1616

17+
/**
18+
* @var \Gedmo\Translatable\Entity\Repository\TranslationRepository
19+
*/
20+
private $tr;
21+
1722
/**
1823
* @var PDO
1924
*/
@@ -164,6 +169,7 @@ protected function populateEnvironment($environment)
164169
];
165170
$this->em->getEventManager()->addEventListener($events, Orga_Service_ACLManager::getInstance());
166171

172+
$this->tr = $this->em->getRepository('Gedmo\Translatable\Entity\Translation');
167173

168174
echo "Début de la migration -->\n";
169175

@@ -252,6 +258,19 @@ protected function cleanUserBDD()
252258

253259
$count = $connection->exec("UPDATE User_Resource SET entityName = 'Orga_Model_Organization' WHERE entityName = 'Inventory_Model_Project'");
254260
echo "\t -> $count resources changées de 'Inventory_Model_Organization' à 'Orga_Model_Organization'\n";
261+
262+
$count = $connection->exec("DELETE FROM ext_translations WHERE (object_class = 'Inventory_Model_Project') OR (object_class = 'Orga_Model_Axis') OR (object_class = 'Orga_Model_Member')");
263+
echo "\t -> $count anciennes traductions supprimées\n";
264+
}
265+
266+
protected function migrateTranslationsForEntity(Core_Model_Entity $entity, $class, $id)
267+
{
268+
$selectTranslations = $this->connection->query(
269+
"SELECT * FROM ext_translations WHERE object_class='$class' AND foreign_key=$id"
270+
);
271+
while ($translationsRows = $selectTranslations->fetch()) {
272+
$this->tr->translate($entity, $translationsRows['field'], $translationsRows['locale'], $translationsRows['content']);
273+
}
255274
}
256275

257276
/**
@@ -276,6 +295,7 @@ protected function processOrganization($row)
276295
$organization = new Orga_Model_Organization();
277296
$organization->setLabel($row['label']);
278297
$organization->save();
298+
$this->migrateTranslationsForEntity($organization, 'Inventory_Model_Project', $row['id']);
279299

280300
$this->mapIdOrganization[$row['idOrgaCube']] = $organization;
281301
$this->flush();
@@ -336,6 +356,7 @@ protected function processAxis($row)
336356
$axis->setDirectNarrower($this->getAxis($row['idDirectNarrower']));
337357
}
338358
$axis->save();
359+
$this->migrateTranslationsForEntity($axis, 'Orga_Model_Axis', $row['id']);
339360

340361
echo "\t\t Axis : " . $row['ref'] . (($row['idDirectNarrower'] != null) ? " narrower of " . $this->getAxis(
341362
$row['idDirectNarrower']
@@ -371,6 +392,7 @@ protected function processMember($row)
371392
$member->setRef($row['ref']);
372393
$member->setLabel($row['label']);
373394
$member->save();
395+
$this->migrateTranslationsForEntity($member, 'Orga_Model_Member', $row['id']);
374396

375397
$this->mapIdMembers[$row['id']] = $member;
376398

0 commit comments

Comments
 (0)