[TYPO3-mvc] Repository does not remove

Jochen Rau jochen.rau at typo3.org
Tue Apr 3 17:22:27 CEST 2012


Hi Chris,

On Tue, Apr 03, 2012 at 04:15:50PM +0200, Christian Peters wrote:
> Thank you, that helped.

You're welcome.

> A last question to this:
> 
> When I remove like this:
> 
> $this->performances->removeAll($this->performances);
> 
> Not all of my performances (ObjectStorage) are removed.

That's because you try to alter a collection while you are iterating over it which gives you unexpected results. Unfortunately, PHP does not have immutable data structures (like Clojure for example). So you might want to just set

$this->performances = new Tx_Extbase_Persistence_ObjectStorage();

> This code does the trick, am I referencing the right bugfix or am I doing
> something wrong?
> 
>         /**
>          * Removes all performances associated with this this concert.
>          *
>          * @todo applied bugfix http://forge.typo3.org/issues/13621 ::
> Remove when fixed.
>          * @param array
>          * @return void
>          */
>         public function removeAllPerformances() {
> 
>             while($this->performances->count() > 0) {
>                 $this->performances->removeAll($this->performances);
>             }
>         }

You might not want to do this. This loops over faulty code an multiplies the unexpected behavior (although it solves your problem).

-Jochen
 
> 2012/4/3 Jochen Rau <jochen.rau at typo3.org>
> 
> > Hi Chris,
> >
> > On Tue, Apr 03, 2012 at 09:44:13AM +0200, Christian Peters wrote:
> > > With "are not respected", do you mean "they are not deleted" or
> > "deleted"?
> > > (Sorry for my bad english).
> >
> > They are physically deleted or marked as deleted (see below). There is
> > no reliable way for Extbase to determine whether an arbitrary object is
> > referenced by another object or not. TYPO3 has a reference index, but I
> > would not rely on it when it comes to delete a bank account of a
> > customer ;-).
> >
> > > I'm importing documents from an api and this api may request to delete
> > > documents on my t3. I then want to delete everything that is only
> > > referenced by the document (such as images, referenced documents etc.).
> > >
> > > How would you do this in Extbase?
> >
> > You can use @cascade remove for that if you control your domain (=know
> > what's related to what). You can also remove related objects within the
> > repository.
> >
> > > And 2nd: How would you delete records in terms of removing (not setting a
> > > delete flag, totally remove 'em)?
> >
> > Extbase uses the standard TYPO3 mechanism. If you define a deleted flag
> > column like
> >
> > 'delete'   => 'deleted',
> >
> > in your TCA, only a flag is set. If not, it gets physically deleted.
> >
> > -Jochen
> >
> > >
> > > Thank you very much.
> > >
> > > Chris
> > >
> > >
> > > 2012/4/2 Dennis Ahrens <dennis.ahrens at googlemail.com>
> > >
> > > > Hi Chris,
> > > >
> > > >
> > > > On 02.04.2012 18:06, Christian Peters wrote:
> > > >
> > > >>    1. *@cascade remove* only removes children that are *not*
> > referenced /
> > > >>    connected to other children
> > > >>    2. *@cascade remove *does not remove children of children if they
> > did
> > > >>    not annotate with *@cascade remove *themself?
> > > >>
> > > >
> > > > Post
> > > > |-Comments (with @cascade remove)
> > > >
> > > > $postRepo->remove($post);
> > > >
> > > > All comments associated with the post will be removed - AFAIK other
> > > > references of the comments will not be respected in this case [1].
> > > >
> > > > regards
> > > > Dennis
> > > >
> > > > [1] http://git.typo3.org/TYPO3v4/**CoreProjects/MVC/extbase.git?**
> > > > a=blob;f=Classes/Persistence/**Backend.php;h=**
> > > > 2e581c9af1f60da19991ac074a4ee0**0523c1e29f;hb=HEAD#l832<
> > http://git.typo3.org/TYPO3v4/CoreProjects/MVC/extbase.git?a=blob;f=Classes/Persistence/Backend.php;h=2e581c9af1f60da19991ac074a4ee00523c1e29f;hb=HEAD#l832
> > >
> > > >
> > > > ______________________________**_________________
> > > > TYPO3-project-typo3v4mvc mailing list
> > > > TYPO3-project-typo3v4mvc@**lists.typo3.org<
> > TYPO3-project-typo3v4mvc at lists.typo3.org>
> > > > http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
> > > > project-typo3v4mvc<
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
> > > >
> > > >
> > _______________________________________________
> > TYPO3-project-typo3v4mvc mailing list
> > TYPO3-project-typo3v4mvc at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> >
> >


More information about the TYPO3-project-typo3v4mvc mailing list