Skip to content
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

Merged
merged 54 commits into from Oct 10, 2019
Merged

Conversation

RaimondasSapola
Copy link
Contributor

@RaimondasSapola RaimondasSapola commented Jul 26, 2019

Questions Answers
Branch? develop
Description? Catalog > Files and Catalog > Files
Type? refacto
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? #10550
How to test? Go to /admin-dev/index.php/sell/attachments. The page should work as previously.

This change is Reviewable

@RaimondasSapola RaimondasSapola requested a review from a team as a code owner July 26, 2019 06:30
@prestonBot
Copy link
Collaborator

Hello @RaimondasSapola!

This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community!

@prestonBot prestonBot added develop Branch Refactoring Type: Refactoring Waiting for wording Status: action required, waiting for wording labels Jul 26, 2019
/**
* @return AttachmentId[]
*/
public function getAttachmentIds()
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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';
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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')
Copy link
Contributor

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?

src/Core/Util/File/FileSizeConverter.php Outdated Show resolved Hide resolved
{% 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 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% 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(
Copy link
Contributor

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? 🤔

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor

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?

defaults:
_controller: PrestaShopBundle:Admin/Sell/Catalog/Attachment:index
_legacy_controller: AdminAttachments
# _legacy_link: AdminAttachments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented?

Copy link
Contributor

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.

@matks matks added the migration symfony migration project label Jul 26, 2019
@LouiseBonnard LouiseBonnard added the Waiting for author Status: action required, waiting for author feedback label Jul 29, 2019
$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?',
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound good to me

@LouiseBonnard LouiseBonnard added Wording ✔️ Status: check done, wording approved and removed Waiting for author Status: action required, waiting for author feedback Waiting for wording Status: action required, waiting for wording labels Aug 8, 2019
Copy link
Contributor

@matks matks left a 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(
Copy link
Contributor

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/Util/File/FileSizeConverter.php Outdated Show resolved Hide resolved
@RaimondasSapola
Copy link
Contributor Author

RaimondasSapola commented Aug 22, 2019

Fixed CR issues including bulk delete behavior and file_exist check. @matks could you take a second look ? :)

@matks matks mentioned this pull request Sep 9, 2019
33 tasks
$path = _PS_DOWNLOAD_DIR_ . $attachment->file;

if (!file_exists($path)) {
throw new AttachmentNotFoundException('Attachment file was not found');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 😉

@matks
Copy link
Contributor

matks commented Sep 11, 2019

@RaimondasSapola sorry for the late answer, only 1 thing to improve and we're done !
=> #14864 (comment)

@matks matks added the Waiting for author Status: action required, waiting for author feedback label Sep 11, 2019
@matks matks merged commit e06677d into PrestaShop:develop Oct 10, 2019
@eternoendless eternoendless changed the title Files list migration Migrate Catalog > Files page Feb 17, 2020
@prestonBot prestonBot added the Waiting for wording Status: action required, waiting for wording label Feb 17, 2020
@jolelievre jolelievre removed the Waiting for wording Status: action required, waiting for wording label Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
develop Branch migration symfony migration project QA ✔️ Status: check done, code approved Refactoring Type: Refactoring Wording ✔️ Status: check done, wording approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants