-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Initial support for Propel2 #45
Conversation
public function flush() | ||
{ | ||
$models = $this->persistedModels; | ||
Propel::getConnection()->transaction( |
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.
Inject connection
*/ | ||
private $generatedSqlPath; | ||
|
||
public function __construct(string $generatedSqlPath) |
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.
Unfortunately Propel doesn't allow runtime access to its configuration
)); | ||
} | ||
|
||
$connection->exec(file_get_contents($sqlPath)); |
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.
Not sure how well this will work regarding FK conflicts - the generated SQL is basically a dump with "DROP TABLE IF EXISTS ..." "CREATE TABLE ...".
It might otherwise be possible to build up a dependency graph for the models and purge them in order, but Propel doesn't make it easy.
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.
Also the tests are using Sqlite, which I don't think supports FKs - should probably make it use MySQL like the others.
Failing test is:
Not sure if that's a side effect of this PR. |
tests/Bridge/Propel2/propel.yml
Outdated
sqlDir: tests/Bridge/Propel2/generated/sql | ||
generator: | ||
schema: | ||
autoPackage: true |
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.
This config is probably not required.
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.
👍 Nice PR. Is there any integration tests?
vendor-bin/propel2/composer.json
Outdated
{ | ||
"autoload-dev": { | ||
"classmap": [ | ||
"../../tests/Bridge/Propel2/Model" |
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.
you shouldn't need that as this should be inherited thanks to theofidry/composer-inheritance-plugin
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.
But inherited from what? This namespace is manually mapped here because Propel doesn't allow PSR-4 IIRC.
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.
ok makes sense then
vendor-bin/propel2/composer.json
Outdated
] | ||
}, | ||
"require-dev": { | ||
"propel/propel": "@alpha", |
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.
^2.0@alpha
?
No! I missed those, will add. |
|
||
$this->assertCount(5, AuthorQuery::create()->find()); | ||
} | ||
} |
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.
@theofidry this is the integration test as it stands - not sure if there is a better way to build the dependency tree above.
@dantleech what's the status of this one? Is there still bits missing or is it just waiting for my review? |
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.
Ok did a review, looks all good to me except some minor changes. Can you fix them ASAP? I would love to ship them in the next beta.
A mention in the README would also be nice, otherwise that's gonna be yet another undocumented feature :)
public function persist($object) | ||
{ | ||
if (false === $object instanceof ActiveRecordInterface) { | ||
throw new \InvalidArgumentException( |
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.
import this class with a use statement
public function create(PurgeMode $mode, PurgerInterface $purger = null): PurgerInterface | ||
{ | ||
if ($mode == PurgeMode::createDeleteMode()) { | ||
throw new \InvalidArgumentException( |
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.
this class should be imported with a use statement as well
$sqlPath = sprintf('%s/%s.sql', $this->generatedSqlPath, $this->connection->getName()); | ||
|
||
if (false === file_exists($sqlPath)) { | ||
throw new \RuntimeException( |
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.
same here
*/ | ||
public function testCannotPersistANonModelObject() | ||
{ | ||
$object = new \stdClass(); |
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.
this class should be imported with a use statement
vendor-bin/propel2/composer.json
Outdated
{ | ||
"autoload-dev": { | ||
"classmap": [ | ||
"../../tests/Bridge/Propel2/Model" |
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.
ok makes sense then
.gitignore
Outdated
!/bin/test.sh | ||
!/bin/cs.sh | ||
/tests/Bridge/Propel2/generated |
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.
can those two be moved in fixtures
?
Tests are failing at the moment, so will need to find out why... |
Updated, let's see what happens with the tests ... |
7236fce
to
9007774
Compare
@dantleech I rebased your work and tweaks a few things, could you double check if everything is good for you? |
Merging as I really want to include this in the new release. Feel free to point out any error which can then be fixed for the next release. Thanks again for that big contribution :) |
Thanks @theofidry, sorry for not giving it more attention - hope it's a good foundation for Propel 2 support :) |
Work-in-progress: Adds support for Propel2