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 from ObjectModel to Doctrine (final) #177

Conversation

leemyongpakvn
Copy link
Contributor

@leemyongpakvn leemyongpakvn commented Jul 24, 2023

Questions Answers
Description? Please check details in the related issue.
Type? refacto
BC breaks? yes
Deprecations? yes
Fixed ticket? Fixes PrestaShop/PrestaShop#33055
How to test? Apply PR changes; Clear web browser cache & BO > Advanced Params > Performance > Clear Cache.
Check to make sure module works as usual in BO and FO.

@leemyongpakvn leemyongpakvn reopened this Jul 24, 2023
@SharakPL SharakPL requested review from a team and removed request for SharakPL July 24, 2023 14:02
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.

Hi @leemyongpakvn and bravo for this PR. I suggested some little things 😉 .

Also I see you have a lot of commits with the same commit message can you squash them?

And I'm afraid there are git conflicts

src/Repository/ProductCommentCriterionRepository.php Outdated Show resolved Hide resolved
src/Repository/ProductCommentRepository.php Outdated Show resolved Hide resolved
src/Repository/ProductCommentRepository.php Outdated Show resolved Hide resolved
src/Repository/ProductCommentRepository.php Outdated Show resolved Hide resolved
@leemyongpakvn leemyongpakvn force-pushed the migrate-from-objectmodel-to-doctrinedbal-final branch from 776c07b to da835f5 Compare August 4, 2023 14:47
@leemyongpakvn
Copy link
Contributor Author

@matks Rebased and applied your suggestion.

public function getCategories(int $id_criterion)
{
$sql = '
SELECT pccc.id_category, pccc.id_product_comment_criterion
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
SELECT pccc.id_category, pccc.id_product_comment_criterion
SELECT pccc.id_category, pccc.id_product_comment_criterion

there's something wrong with indentation, I'm surprised cs fixer didn't catch it, you should indent using spaces, also the indentation itself is wrong for the queries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indentation and tabs are copied from existing ObjectModel code. I have just replaced tabs by spaces. Be free to change queries' indentation if you think it is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We know php-cs-fixer and php-stan are not reliable in some cases.

*/
public function getTypes()
{
$sfTranslator = SymfonyContainer::getInstance()->get('translator');
Copy link
Contributor

Choose a reason for hiding this comment

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

You could inject translator service in the construtor

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 tried inserting @translator in common.yml but got this error

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "product_comment_criterion_repository" has a dependency on a non-existent service "translator".

Then I discovered that ps_linklist uses @translator in its services, Symfony\Contracts\Translation\TranslatorInterface in its repository, and dropped support for both PS 1.7.8, PS 8.0 😢

Copy link
Contributor

Choose a reason for hiding this comment

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

With the upgrade to symfony 4, Symfony\Component\Translation\TranslatorInterface is transferred to Symfony\Contracts\Translation\TranslatorInterface. On the other hand, the translator service is still present, it has just changed the package.

Copy link
Contributor Author

@leemyongpakvn leemyongpakvn Aug 22, 2023

Choose a reason for hiding this comment

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

Injecting translator service create error now so I'd prefer try to do it in the next minor version.

Comment on lines +45 to +48
* @method ProductComment|null find($id, $lockMode = null, $lockVersion = null)
* @method ProductComment|null findOneBy(array $criteria, array $orderBy = null)
* @method ProductComment[] findAll()
* @method ProductComment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fun of such comments, what's the purpose of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are generated automatically when you run Symfony make:entity in terminal . I think it is useful in case someone try to reinvent the wheel ;)

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.

Hi !

I have 1 good piece of news and 1 bad 😞

The good news: for me this PR is valid 👍 I can approve it

The bad: this PR is modifying ProductComments module Doctrine entities, right?

Last week we released GDPR 2.0.1 module. This release also also modify module Doctrine entities. And it started to create failures for people trying to upgrade PrestaShop 8.x. So the module was rollbacked.

Right now, the problem is under analyzis but the main culprit is that the way modules handle Doctrine schema updates migth break the shop upgrade process.

So ... if we put this PR #177 inside release 6.0.0 of Productcomments, the same thing might happen. It might start crashing people shop upgrades 😞 .

So I'm really really really sad 😭 to say this but I'm afraid we should wait for the resolution of this upgrade problem before merging this PR. Because of the Doctrine entities being changed.

@kpodemski
Copy link
Contributor

@matks when I check the code inside the class which is inside Entity directory, I don't see anything that could trigger schema upgrade

@leemyongpakvn
Copy link
Contributor Author

I see 2 good news from matks's bad news 😆
First, the community can avoid a possible crash that is still under analyzed.
Second, I can bump the first version 7 in native modules next month.

@matks
Copy link
Contributor

matks commented Aug 22, 2023

Wait I might be wrong 😄

https://github.com/PrestaShop/productcomments/blob/c85529e874056c82f68ab7daae0104ea3d26db5d/src/Entity/ProductCommentCriterion.php

@leemyongpakvn you added private properties in the Entity BUT you did not map them to SQL column so the Doctrine entities are NOT modified, right?

@leemyongpakvn
Copy link
Contributor Author

@matks Correct, the ProductCommentCriterion Entity is MODIFIED, but 3 additional private properties is NOT mapped to SQL columns so as @kpodemski said

I don't see anything that could trigger schema upgrade

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.

Then let's ask QA team to test this PR 💪 we move to the next stage

Copy link
Member

@PululuK PululuK left a comment

Choose a reason for hiding this comment

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

Small feedback :)

public function __construct()
{
$langIsoIds = Language::getIsoIds();
$langString = '';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$langString = '';

Copy link
Member

Choose a reason for hiding this comment

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

Remove unused variable :)

Comment on lines 208 to 216
public function isValid()
{
$res = true;
foreach ($this->names as $key => $value) {
$res &= Validate::isGenericName($value);
}

return $res;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function isValid()
{
$res = true;
foreach ($this->names as $key => $value) {
$res &= Validate::isGenericName($value);
}
return $res;
}
public function isValid()
{
foreach ($this->getNames() as $value) {
if(!Validate::isGenericName($value)) {
return false;
}
}
return true;
}

Copy link
Member

Choose a reason for hiding this comment

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

Performances improvement :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$this->getNames() returns $this->names in fact, so I think we simply need removing unused $key

Copy link
Member

Choose a reason for hiding this comment

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

@leemyongpakvn You don't need to loop all the names... just have a false for the condition to return false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PululuK You're right. Applied :)

@leemyongpakvn
Copy link
Contributor Author

@matks In need of re-approve after removing unused variables (small tweak, no logic change ;)

@hibatallahAouadni
Copy link

@PululuK @M0rgan01 @kpodemski we need second approval on this PR 🙏

@kpodemski
Copy link
Contributor

@hibatallahAouadni modules don't require two approvals, it's ok 👍🏻

Copy link

@hibatallahAouadni hibatallahAouadni left a comment

Choose a reason for hiding this comment

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

Hello @leemyongpakvn

Thanks for your PR 🚀
All module's functionalities works like expected ✅
@matks about the upgrade pb, do you want me test the upgrade with this PR? to check if there will be problems?
Waiting for your feedback.

Thanks!

Copy link

@hibatallahAouadni hibatallahAouadni left a comment

Choose a reason for hiding this comment

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

As discussed with @kpodemski no need to test the upgrade 😉

@M0rgan01 M0rgan01 merged commit 43c6fb1 into PrestaShop:dev Aug 23, 2023
21 of 24 checks passed
@MatShir MatShir added this to the 6.0.0 milestone Aug 23, 2023
@leemyongpakvn leemyongpakvn deleted the migrate-from-objectmodel-to-doctrinedbal-final branch January 20, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants