Línea 1764... |
Línea 1764... |
1764 |
|
1764 |
|
1765 |
$request = $this->getRequest();
|
1765 |
$request = $this->getRequest();
|
1766 |
if ($request->isPost()) {
|
1766 |
if ($request->isPost()) {
|
1767 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
1767 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
- |
|
1768 |
$target_path = $storage->getPathUser(); // Base path for user-specific files
|
Línea 1768... |
Línea 1769... |
1768 |
$target_path = $storage->getPathUser(); // Base path for user-specific files
|
1769 |
$user_uuid = $currentUser->uuid;
|
1769 |
|
1770 |
|
1770 |
// Handle cover deletion operation
|
1771 |
// Handle cover deletion operation
|
1771 |
if ($operation == 'delete') {
|
1772 |
if ($operation == 'delete') {
|
1772 |
if ($userProfile->cover) {
|
1773 |
if ($userProfile->cover) {
|
1773 |
// Attempt to delete the existing cover file from storage
|
1774 |
// Attempt to delete the existing cover file from storage
|
1774 |
if (!$storage->deleteFile($target_path, $currentUser->uuid, $userProfile->cover)) {
|
1775 |
if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
|
1775 |
return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
|
1776 |
return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
|
1776 |
}
|
1777 |
}
|
1777 |
}
|
1778 |
}
|
Línea 1788... |
Línea 1789... |
1788 |
$form = new CoverForm($this->config);
|
1789 |
$form = new CoverForm($this->config);
|
1789 |
// Merge POST data and FILES data for the form
|
1790 |
// Merge POST data and FILES data for the form
|
1790 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
1791 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
1791 |
$form->setData($data);
|
1792 |
$form->setData($data);
|
Línea -... |
Línea 1793... |
- |
|
1793 |
|
1792 |
|
1794 |
|
1793 |
if ($form->isValid()) {
|
1795 |
if ($form->isValid()) {
|
1794 |
// Set files in storage and select the 'cover' file by its input name
|
1796 |
// Set files in storage and select the 'cover' file by its input name
|
1795 |
$storage->setFiles($request->getFiles()->toArray());
|
1797 |
$storage->setFiles($request->getFiles()->toArray());
|
1796 |
if (!$storage->setCurrentFilename('cover')) { // Ensure 'cover' is the correct file input name from CoverForm
|
1798 |
if (!$storage->setCurrentFilename('cover')) { // Ensure 'cover' is the correct file input name from CoverForm
|
Línea 1803... |
Línea 1805... |
1803 |
$target_width = (int)$target_width_str;
|
1805 |
$target_width = (int)$target_width_str;
|
1804 |
$target_height = (int)$target_height_str;
|
1806 |
$target_height = (int)$target_height_str;
|
Línea 1805... |
Línea 1807... |
1805 |
|
1807 |
|
1806 |
$filename = 'user-cover-' . uniqid() . '.png'; // Generate unique filename for the new cover
|
1808 |
$filename = 'user-cover-' . uniqid() . '.png'; // Generate unique filename for the new cover
|
1807 |
$source_filename = $storage->getTmpFilename(); // Temporary path of the uploaded file
|
1809 |
$source_filename = $storage->getTmpFilename(); // Temporary path of the uploaded file
|
Línea 1808... |
Línea 1810... |
1808 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_USER, $currentUser->id, $filename);
|
1810 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_USER, $user_uuid, $filename);
|
1809 |
|
1811 |
|
1810 |
// Upload, resize, and save the image
|
1812 |
// Upload, resize, and save the image
|
1811 |
if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
|
1813 |
if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
|
Línea 1812... |
Línea 1814... |
1812 |
return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
|
1814 |
return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
|
1813 |
}
|
1815 |
}
|
1814 |
|
1816 |
|
1815 |
// If an old cover exists, delete it from storage
|
1817 |
// If an old cover exists, delete it from storage
|
1816 |
if ($userProfile->cover) {
|
1818 |
if ($userProfile->cover) {
|
1817 |
if (!$storage->deleteFile($target_path, $currentUser->uuid, $userProfile->cover)) {
|
1819 |
if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
|
1818 |
// Decide if this is a critical error. Original code returns error.
|
1820 |
// Decide if this is a critical error. Original code returns error.
|
1819 |
// Consider logging this and proceeding if deletion of old file is non-critical.
|
1821 |
// Consider logging this and proceeding if deletion of old file is non-critical.
|