Attachments: Copy, Move, Rename
Attachments can be copied, moved, or renamed using built-in session methods.
All of those actions are executed when saveChanges
is called and take place on the server-side,
removing the need to transfer the entire attachment binary data over the network in order to perform the action.
Copy attachment
Attachment can be copied using one of the session.advanced.attachments.copy
methods:
Syntax
function copy(object|string $sourceIdOrEntity, ?string $sourceName, object|string $destinationIdOrEntity, ?string $destinationName): void;
Example
$employee1 = $session->load(Employee::class, "employees/1-A");
$employee2 = $session->load(Employee::class, "employees/2-A");
$session->advanced()->attachments()->copy($employee1, "photo.jpg", $employee2, "photo-copy.jpg");
$session->saveChanges();
Move attachment
Attachment can be moved using one of the session.advanced.attachments.move
methods:
Syntax
public function move(object|string $sourceIdOrEntity, ?string $sourceName, object|string $destinationIdOrEntity, ?string $destinationName): void;
Example
$employee1 = $session->load(Employee::class, "employees/1-A");
$employee2 = $session->load(Employee::class, "employees/2-A");
$session->advanced()->attachments()->move($employee1, "photo.jpg", $employee2, "photo.jpg");
$session->saveChanges();
Rename attachment
Attachment can be renamed using one of the session.advanced.attachments.rename
methods:
Syntax
function rename(string|object $idOrEntity, ?string $name, ?string $newName): void;
Example
$employee = $session->load(Employee::class, "employees/1-A");
$session->advanced()->attachments()->rename($employee, "photo.jpg", "photo-new.jpg");
$session->saveChanges();