FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Help on object clone #599

Open disu opened 1 year ago

disu commented 1 year ago

Hello, I need to add to my software a function to clone an entity containing the upload behavour configured to save files on S3.

I use a code like this pseudo-code and it works well duplicating main entity (Ship) and absociated models (Ship documents, in this example):

  $ship = $this->Ships->get($id, ['contain' => ['ShipsDocs']]);

  $data = $ship->toArray();
  $data['name'] = $ship->name . " - copy";

  $newShip = $this->Ships->newEntity($data, [
     'associated' => ['ShipsDocs'],
  ]);

but how can I trigger the upload behaviour to clone also files on S3, absociated to the source entity, and absociate the new ones to the cloned entity? Give me some hint please.