Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony2][Doctrine]Usuwanie translacji gedmo
Forum PHP.pl > Forum > PHP > Frameworki
marcio
Witam mam maly problem potrzebuje usunac wszystkie tlumaczenia z gedmo gdy usuwam jakis rekord.
Problem polega na tym ze nie moge uzywa dotakowych repozytoriow ani encji.
Wiec takie rozwiazanie odpada:
  • https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#translation-entity
  • https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations

Poki co probowalem tak:
  1. /**
  2.   * Cleans texts of of the content with given ID
  3.   *
  4.   * @param integer $contentId ID of the content
  5.   * @return boolean
  6.   */
  7. public function cleanContent($contentId) {
  8. $content = $this->getContentById($contentId);
  9. if ($content !== null) {
  10. $translations = $this->getEntityManager()
  11. ->getRepository('Gedmo\Translatable\Entity\Translation')
  12. ->findBy(array(
  13. 'objectClass' => $this->getEntityClassName(),
  14. 'content' => $content->getContent()
  15. )
  16. );
  17.  
  18. foreach ($translations as $translation) {
  19. $this->getEntityManager()->remove($translation);
  20. }
  21. $content->setContent(null);
  22. $this->getEntityManager()->flush();
  23.  
  24. return true;
  25. }
  26.  
  27. return false;
  28. }

W translations znajduje sie:
Kod
Array ( [0] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 1 [locale:protected] => pl_PL [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [1] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 3 [locale:protected] => en_GB [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [2] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 5 [locale:protected] => de_DE [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [3] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 7 [locale:protected] => fr_FR [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [4] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 9 [locale:protected] => en_US [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) )

Czyli mamy encje Translation wiec dlaczego remove nie dziala?
Zero bledow kompletnie nic a w bazie tlumaczenia dalej sa.
Czy ktos wie jak rozwiazac problem?
ano
Skoro masz 'tłumaczalny' model to nie mów, że nie ma on powiązania do encji tłumaczeń mniej więcej takiego:

  1. /**
  2.   * @ORM\OneToMany(
  3.   * targetEntity="CategoryTranslation",
  4.   * mappedBy="object",
  5.   * cascade={"persist", "remove"}
  6.   * )
  7.   */
  8. private $translations;


jeśli tak to usunięcie tej encji (EntityManager::remove(...)) spowoduje usunięcie również powiązanych translations. (zakładając, że masz zdefiniowaną operację kaskadową cascade={"remove"}).

Jeżeli tak nie masz to pytanie - czemu?

Cytat
Problem polega na tym ze nie moge uzywa dotakowych repozytoriow ani encji.

Dlaczego?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.