-
Notifications
You must be signed in to change notification settings - Fork 25
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
Support fluent and clean up #32
Conversation
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.
Looking good. I was actually just picking this branch up for a project and thought I'd give it a quick review.
Also, no PR emoji @adrhumphreys ? 😎
code/Populate.php
Outdated
} | ||
|
||
/* | ||
* Attempts to truncate a table if it hasn't already been truncated |
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.
Would it be worth completing the docBlock?
code/Populate.php
Outdated
} | ||
} | ||
|
||
if ($obj->hasExtension(FluentExtension::class)) { |
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.
Instead of baking this directly into the logic, could you create an extension point here, and use the config to apply an extension for fluent, when fluent is in the project?
i.e
Only:
moduleexists: 'Fluent'
While it's a complete breakdown if fluent is installed, it still feels quite opinionated to include this concern here.
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 like this idea better in general, but we already have hooks in here for checking whether the object is Versioned or not (Versioned is part of core but it's still optional on objects).
Let's merge this in as-is, and then I'll create an issue to suggest this change.
@jakxnz I've become old and can't relate to emojis anymore 😂 You might want to try out https://github.com/adrhumphreys/silverstripe-fixtures I found that with Fluent, Elemental, and Populate, you end up spending more time debugging missing data in some key table or some such. I still need to get around to updating this PR to reflect the changes I made when making the module |
README.md
Outdated
Example: | ||
```yaml | ||
DNADesign\Populate\Populate: | ||
truncate_classes: |
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.
Is it worth adding an "upgrade" note, for users who don't notice the change in terminology here?
code/Populate.php
Outdated
private static function deleteClass(string $class): void | ||
{ | ||
// First delete the base classes | ||
$tableClasses = ClassInfo::ancestry($class, 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 used to also capture downstream tables as well, e.g ClassInfo::dataClassesFor()
, so only capturing ancestry is quite a deviation. What's the advantage of the change?
I did end up testing this branch, and found that it didn't quite manage a clean slate, and so my populate task crashed due to duplicate keys.
Thanks for the suggestion. Can you elaborate on what that solves @adrhumphreys ? |
@jakxnz just need to find time to update the autocomplete code a bit 🙏🏽 You end up with these hard to read yml files that sort of go like:
Where it becomes more difficult to conceptualise what is being done in the populate config The idea with the other module is you create fixtures in PHP in which you call the normal creation methods that you have in Silverstripe. If you want to create 50 objects with random numbers you can just write a loop to do that. This isn't all smooth though as you'll have a performance hit since you're calling all the after writes etc for your models now when populating them. I just found the tradeoff worth it |
Nice. Yep, I have experienced this. Cool that you're working on an enhancement! @adrhumphreys For anyone looking for a way to support Fluent via populate, I raised a PR against @adrhumphreys fork, with some adjustments that worked for our project adrhumphreys#1 |
Truncate tables extension hook
code/Populate.php
Outdated
self::truncateTable($table); | ||
$tables = []; | ||
|
||
// All acenstors or children with tables |
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.
typo in 'ancestors'
Hey @adrhumphreys there's a few outstanding changes suggested on this, do you still want to look at merging it in at some point? I'm just trying to work out which order to merge changes in - whether merging #26, #32 then #33 makes the most sense or something else... |
Hey @madmatt I haven't actually used the module since I made these changes. I do know there's some internal project(s) using the changes as a fork though so I imagine it's probably higher on the list of wanting to merge in |
@madmatt the suggestions are grammar changes and a disputed suggestion about a method name. Are they a trivial reason to leave a PR on hiatus? The track record demonstrates that the people who progressed the contribution this far haven't had the capacity to address the outstanding nitpicks. As far as I understand it, there's greater internal benefit to having this merged than leaving it as a liability when support is needed for projects that implement it. Is there value enough there for you to get this merged @madmatt ? Or do we need to wait until the contributors of this PR (@adrhumphreys or I) have capacity? |
I've fixed all the conflicts in README.md and rebased/merged the Any final thoughts @jakxnz, @adrhumphreys, @michalkleiner or @chrispenny? If not, I'm happy to merge it now and we can tidy things up later. One question I have is how does it actually support fluent now @adrhumphreys? I see there is some old code that supported it by checking if the Fluent extension was applied to an object that was being truncated, but this appears to have been removed. I don't see anything added to the fluent module either, so does it just handle it implicitly now and you didn't have to do anything? Or am I missing something obvious here? 🙂 |
FWIW, I've made some tweaks to README:
|
All good with me, all the remaining stuff is quite minor. |
@madmatt , it currently "supports" fluent by exposing an extension point that can be used to clear tables created by other modules e.g
I felt this approach was less opinionated and had better grouping of concerns. The title of the PR is a bit misleading. |
code/PopulateTask.php
Outdated
/** | ||
* @var string | ||
*/ | ||
private static $segment = 'populate-task'; |
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.
Just as a heads up, I'm going to remove this. It breaks BC as lot of projects will have defined composer scripts to the original dev/task path.
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.
Folks seem happy enough with the changes here. I've tested it on one of my [mammoth sized] projects, and it ran without issue.
If there are any further improvements, please don't hesitate to raise a new PR. I'm going to do my best to keep on top of things going forward.
use SilverStripe\Core\Config\Configurable; | ||
use SilverStripe\Core\Extensible; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\YamlFixture; | ||
use SilverStripe\ORM\Connect\DatabaseException; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\ORM\DB; | ||
use SilverStripe\Versioned\Versioned; |
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.
Nitpick: It's plausible to use this module without the admin module (and/or the versioned module). So while this is a safe assumption (I'm guessing 99.9% of framework-based projects run admin), are we happy to make this assumption?
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.
Oh, you'd already merged it. I overlooked that, sorry.
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.
PHP allows you to reference classes (that don't exist) in this way without it breaking. Breakages would only occur when you attempt to use that class. My assumption is that that case is already covered, as all I did was change the reference.
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.
Ah, I see. I had assumed if (!$obj->hasExtension(Versioned::class)) {
is invoking the class, and so would throw an error
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.
To be fair, I'm not not 100% sure about older versions of Extensible
, but currently it's just running an is_a()
on the instance and extension name.
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.
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 probably should have checked that 😆
This allows you to now support using the module with fluent
It also splits out objects into classes which we can find the tables for and then tables which are just truncated
Task is now run from
populate-task
and documented correctly for running it