New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate Catalog > Files page #14864
Migrate Catalog > Files page #14864
Conversation
Hello @RaimondasSapola! This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community! |
/** | ||
* @return AttachmentId[] | ||
*/ | ||
public function getAttachmentIds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use return type hints 🙂
* | ||
* @throws AttachmentConstraintException | ||
*/ | ||
public function __construct($attachmentId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scalar type hints can be used everywhere in method signatures
/** | ||
* @param $attachmentId | ||
* | ||
* @throws \PrestaShop\PrestaShop\Core\Domain\Attachment\Exception\AttachmentConstraintException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class should be imported
/** | ||
* Defines contract for GetAttachmentPathHandler | ||
*/ | ||
interface GetAttachmentPathHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you are handling GetAttachment
query, maybe the handler should be named GetAttachmentHandler
as well, for consistency
@@ -35,6 +35,9 @@ | |||
*/ | |||
final class SubmitRowAction extends AbstractRowAction | |||
{ | |||
const MESSAGE_TYPE_STATIC = 'static'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments would be helpful, explaining what these constants are used for
use Symfony\Component\Form\Extension\Core\Type\NumberType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
final class AttachmentGridDefinitionFactory extends AbstractGridDefinitionFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing docblock
Connection $connection, | ||
$dbPrefix, | ||
DoctrineSearchCriteriaApplicatorInterface $searchCriteriaApplicator, | ||
$employeeIdLang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing type hint
|
||
$qb | ||
->select('a.`id_attachment`, al.`name`, a.`file`, a.`file_size`') | ||
->addSelect('CONCAT(COALESCE(virtual_product_attachment.`product_count`, 0), " product(s)") AS products') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
product(s)
- this part is not translatable 🤔 was it like this in the legacy code?
{% set confirmation_message = action.options.confirm_message %} | ||
{% if action.options.confirm_message_type == 'dynamic' and record[action.options.dynamic_message_field] is defined %} | ||
{% set dynamic_field = record[action.options.dynamic_message_field] %} | ||
{% set confirmation_message = dynamic_field is defined ? dynamic_field : action.options.confirm_message %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% set confirmation_message = dynamic_field is defined ? dynamic_field : action.options.confirm_message %} | |
{% set confirmation_message = dynamic_field|default(action.options.confirm_message) %} |
$attachment = $this->getAttachment($attachmentId); | ||
|
||
if (!$this->deleteAttachment($attachment)) { | ||
throw new DeleteAttachmentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if only the last one failed?
The response will return an error while everything instead of one id weren't deleted? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see there is an unresolved discussion about this topic #14179
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed 😉 nice finding it !
So we should follow strategy skip it, attempt to perform the action on the remaining items, and at the end display a list of the failed usecases
unless we think it's not relevant, in this case we ask Product Team (@marionf for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was decided for this behavior?
src/Core/Grid/Data/Factory/AttachmentGridDataFactoryDecorator.php
Outdated
Show resolved
Hide resolved
defaults: | ||
_controller: PrestaShopBundle:Admin/Sell/Catalog/Attachment:index | ||
_legacy_controller: AdminAttachments | ||
# _legacy_link: AdminAttachments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably because the page is not visible yet, so the legacy links are not updated.
src/Core/Grid/Data/Factory/AttachmentGridDataFactoryDecorator.php
Outdated
Show resolved
Hide resolved
src/Core/Grid/Definition/Factory/AttachmentGridDefinitionFactory.php
Outdated
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Sell/Catalog/AttachmentController.php
Outdated
Show resolved
Hide resolved
$productNamesArray = $this->getProductNames($attachment['id_attachment']); | ||
$productNames = $productNamesArray['product_names'] ?? ''; | ||
$attachment['dynamic_message'] = $this->trans( | ||
'This file is associated with the following products, do you really want to delete it?', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that there is a useless space in the original string, but I'm not fond of letting it as-is because it is a mistake. In order to bypass the typo, I would suggest writing the following new wording This file is associated with the following products. Are you sure you want to delete it?, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sound good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RaimondasSapola Nice job ! 😄 I've got a few feedbacks to handle but the work is overall very good ✅
$attachment = $this->getAttachment($attachmentId); | ||
|
||
if (!$this->deleteAttachment($attachment)) { | ||
throw new DeleteAttachmentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed 😉 nice finding it !
So we should follow strategy skip it, attempt to perform the action on the remaining items, and at the end display a list of the failed usecases
unless we think it's not relevant, in this case we ask Product Team (@marionf for example)
src/Core/Grid/Data/Factory/AttachmentGridDataFactoryDecorator.php
Outdated
Show resolved
Hide resolved
src/Core/Grid/Definition/Factory/AttachmentGridDefinitionFactory.php
Outdated
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Sell/Catalog/AttachmentController.php
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Sell/Catalog/AttachmentController.php
Outdated
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Sell/Catalog/AttachmentController.php
Show resolved
Hide resolved
Fixed CR issues including bulk delete behavior and file_exist check. @matks could you take a second look ? :) |
$path = _PS_DOWNLOAD_DIR_ . $attachment->file; | ||
|
||
if (!file_exists($path)) { | ||
throw new AttachmentNotFoundException('Attachment file was not found'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new AttachmentNotFoundException('Attachment file was not found'); | |
throw new AttachmentNotFoundException(sprintf('Attachment file was not found at %s', $path)); |
Exceptions are meant to be read by developers and consequently it's best to provide as much as possible info to them. If file does not exists, developer will need the $path
to understand where it's supposed to be. For example if _PS_DOWNLOAD_DIR_
is missing a slash, he'll see it immediately this way 😉
@RaimondasSapola sorry for the late answer, only 1 thing to improve and we're done ! |
…ring File -> Attachment
…names, file size bytes to other units conversion
7b4cc2c
to
9917dbf
Compare
This change is