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
feat: change scandir by symfony finder #197
Conversation
fox-john
commented
Mar 27, 2023
Questions | Answers |
---|---|
Description? | remove all scandir call and use symfony Finder |
Type? | improvement |
BC breaks? | no |
Deprecations? | no |
How to test? | Test install / uninstall of module and update to 2.0.0 |
upgrade/upgrade-2.0.0.php
Outdated
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.
Several things here. See comments in the code
//use Symfony\Component\Finder\Finder;
$finder = (new Finder())
->files()
->in(dirname(__DIR__) . '/psgdpr/sql/install')
->name('*.sql')//We deal only with sql files
;
//This is needed because if $finder->hasResults() return true but the files are empty there will be no query executions
//and then we should return false
$hasExecutedAtLeastOneQuery = false;
//use Symfony\Component\Finder\SplFileInfo
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$contents = $file->getContents();
//Test first avoid using str_replace needlessly
if ($contents === '') {
continue;
}
$hasExecutedAtLeastOneQuery = true;
$query = str_replace('PREFIX_', _DB_PREFIX_, $contents);
\Db::getInstance()->execute($query);
}
return $hasExecutedAtLeastOneQuery;
You can remove the comments
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.
About executeQuerySql method several things. See comments in the code
/** @var EntityManager $entityManager */
$entityManager = $this->get('doctrine.orm.entity_manager');
$finder = (new Finder())
->files()
->in(dirname(__DIR__) . '/psgdpr/sql/' . $folder)
->name('*.sql')//We deal only with sql files
;
//This is needed because if $finder->hasResults() return true but the files are empty there will be no query executions
//and then we should return false
$hasExecutedAtLeastOneQuery = false;
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$contents = $file->getContents();
//Test first avoid using str_replace needlessly
if ($contents === '') {
continue;
}
$hasExecutedAtLeastOneQuery = true;
$query = str_replace('PREFIX_', _DB_PREFIX_, $contents);
$entityManager->getConnection()->executeQuery($query);
}
$entityManager->flush();//Didn't it work without this line before?
return $hasExecutedAtLeastOneQuery;
You can remove the comments
psgdpr.php
Outdated
public function enable($force_all = false) | ||
{ | ||
$this->executeQuerySql(self::SQL_QUERY_TYPE_INSTALL); | ||
|
||
return parent::enable($force_all); | ||
} | ||
|
||
public function disable($force_all = false) | ||
{ | ||
$this->executeQuerySql(self::SQL_QUERY_TYPE_UNINSTALL); | ||
|
||
return parent::disable($force_all); | ||
} | ||
|
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 don't understand what are they for?
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's an oversight, I had put that for my tests. i remove it.
b5df871
to
3af0f3b
Compare
Hello ! |
Hello @fox-john, I have tested your PR and it's good for me! 🎉 Thanks! |
Thank you @fox-john |