Jump to content

Images get lost, when I remove a repeater


sekru
 Share

Recommended Posts

Hello,

it ist frustrating: if I remove an item of a repeater with help of the API, all images in my page get lost. I have absolutly no idea, why.

    $gruppe = (int) $input->get->gruppe;
    $mitarbeiter = (int) $input->get->mitarbeiter;
    $m = $pages->get($mitarbeiter);
    $m->of(false);
    $delGruppe = $m->gruppenzuordnung->get("gruppe=".$gruppe);
    $m->gruppenzuordnung->remove($delGruppe); // If I remove this line, no images are lost
    $m->save();

The lost image is in $m->image. It has nothing to do with the repeater $m->gruppenzuordnung. They remain on the server as file, but not in the database.

Has any one an idea?

thx,
sekru

Link to comment
Share on other sites

9 hours ago, sekru said:

if I remove an item of a repeater

Which one is the repeater? gruppe? You are trying  to remove the repeater form its own item, as far as I can see. $m is a Page object, not a (Repeater)PageArray if I'm correct:

$m->gruppenzuordnung->remove($delGruppe);

So incidentally it is probably the image this line removes because of a matching key of the image:

http://kongondo.github.io/ProcessWireAPIGen/devns/source-class-ProcessWire.WireData.html#333-351

You need to work on the RepeaterPageArray:

http://kongondo.github.io/ProcessWireAPIGen/devns/class-ProcessWire.PageArray.html#_remove

like this: $delGruppe->remove($m); // or $gruppe->remove($m); // depending on what you want to achieve

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...