diff --git a/vendor/magento/module-customer/Controller/Account/EditPost.php b/vendor/magento/module-customer/Controller/Account/EditPost.php index 085b4ab2d3f..aff05eed4b0 100644 --- a/vendor/magento/module-customer/Controller/Account/EditPost.php +++ b/vendor/magento/module-customer/Controller/Account/EditPost.php @@ -16,6 +16,7 @@ use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterf use Magento\Customer\Model\AuthenticationInterface; use Magento\Customer\Model\Customer\Mapper; use Magento\Customer\Model\EmailNotificationInterface; +use Magento\Customer\Model\Metadata\Form\File; use Magento\Framework\App\CsrfAwareActionInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\Request\InvalidRequestException; @@ -233,9 +234,15 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http $customer = $this->getCustomerDataObject($this->session->getCustomerId()); $customerCandidate = $this->populateNewCustomerDataObject($this->_request, $customer); - $attributeToDelete = $this->_request->getParam('delete_attribute_value'); - if ($attributeToDelete !== null) { - $this->deleteCustomerFileAttribute($customerCandidate, $attributeToDelete); + $attributeToDelete = (string)$this->_request->getParam('delete_attribute_value'); + if ($attributeToDelete !== "") { + $attributesToDelete = $this->prepareAttributesToDelete($attributeToDelete); + foreach ($attributesToDelete as $attribute) { + $uploadedValue = $this->_request->getParam($attribute . File::UPLOADED_FILE_SUFFIX); + if ((string)$uploadedValue === "") { + $this->deleteCustomerFileAttribute($customerCandidate, $attribute); + } + } } try { @@ -300,6 +307,26 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http return $resultRedirect; } + /** + * Convert comma-separated list of attributes to delete into array + * + * @param string $attribute + * @return array + */ + private function prepareAttributesToDelete(string $attribute) : array + { + $result = []; + if ($attribute !== "") { + if (str_contains($attribute, ',')) { + $result = explode(',', $attribute); + } else { + $result[] = $attribute; + } + $result = array_unique($result); + } + return $result; + } + /** * Adds a complex success message if email confirmation is required * @@ -468,11 +495,7 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http string $attributeToDelete ) : void { if ($attributeToDelete !== '') { - if (strpos($attributeToDelete, ',') !== false) { - $attributes = explode(',', $attributeToDelete); - } else { - $attributes[] = $attributeToDelete; - } + $attributes = $this->prepareAttributesToDelete($attributeToDelete); foreach ($attributes as $attr) { $attributeValue = $customerCandidateDataObject->getCustomAttribute($attr); if ($attributeValue!== null) { diff --git a/vendor/magento/module-customer/Model/Metadata/Form/File.php b/vendor/magento/module-customer/Model/Metadata/Form/File.php index 54b8b75c9ca..05788dcaf76 100644 --- a/vendor/magento/module-customer/Model/Metadata/Form/File.php +++ b/vendor/magento/module-customer/Model/Metadata/Form/File.php @@ -23,6 +23,8 @@ use Magento\Framework\Filesystem\Io\File as IoFile; */ class File extends AbstractData { + public const UPLOADED_FILE_SUFFIX = '_uploaded'; + /** * Validator for check not protected extensions * @@ -59,7 +61,8 @@ class File extends AbstractData /** * @var FileProcessorFactory - * @deprecated 101.0.0 + * @deprecated 101.0.0 Call fileProcessor directly from code + * @see $this->fileProcessor */ protected $fileProcessorFactory; @@ -126,7 +129,7 @@ class File extends AbstractData $attrCode = $this->getAttribute()->getAttributeCode(); // phpcs:disable Magento2.Security.Superglobal - $uploadedFile = $request->getParam($attrCode . '_uploaded'); + $uploadedFile = $request->getParam($attrCode . static::UPLOADED_FILE_SUFFIX); if ($uploadedFile) { $value = $uploadedFile; } elseif ($this->_requestScope || !isset($_FILES[$attrCode])) { @@ -424,7 +427,8 @@ class File extends AbstractData * Get file processor * * @return FileProcessor - * @deprecated 100.1.3 + * @deprecated 100.1.3 we don’t use such approach anymore. Call fileProcessor directly + * @see $this->fileProcessor */ protected function getFileProcessor() {