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
Setting creation_date and modification_date of entries programatically is buggy #2400
Comments
Thanks Michael! |
Looking at the code this is by design when using When creating an Now, if this function is not run, it's ok, because the Now the date settings can be set programmatically ( Now if the So to circle back:
@michael-e Can you clarify "doesn't work"? I'd expect that the modification date set programmatically would be ignored, but if creation date was set, that should be persisted the database. |
I meant that it is ignored, no matter if dry-run mode is used or not. It is always ignored.
Was supposed to say: Using dry-run mode I can set it programatically. Without dry-run mode it is ignored. Can you confirm this? |
Yep, it will always be ignored because
I can't confirm this, setting |
In the test case we have: $entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s', '2000-01-01 00:00:00'));
$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s', '2000-01-01 00:00:00')); In my environment, both definitely get ignored (and the current date will be used) when I do $entry->setDataFromPost($fields, $errors, false) (in line 87 of the test case). Can you double-check? |
|
|
|
|
|
This is why I used |
Re: 1. Pull request sent—tested, of course. It is now possible to set the modification date of an entry programmatically. Re: 2. I am OK with leaving it as it is. However, as often, I have one stupid question left. Assumed that, in an extension or a background process, I fetch a Symphony entry in order to manipulate one of the fields, the re-commit the entry: Should I call |
@michael-e @brendo I would be interested in the answer myself ;) |
Allow to set modification date programatically. RE: #2400
The simulation is only specific to the
Well yes, at the moment, the creation date is when the entry was persisted to the database. We can solve this by removing these lines and adding the author check to the
So if you look at it like that, Hope that helps! |
+1 Thanks for the clarification ! |
Yep, thanks a lot, @brendo! |
Should we leave this issue open then? Or should we rather say "there's no real need for that"? I won't insist, because I also see the logic behind the current concept. |
We have a problem. My fix which has been pulled leads to a very strange situation. When an entry is saved in the backend, the It might be that my "fix" is s bit stupid. But there is one more thing that really bothers me: How the hell can it be that the system behaves so strange? |
object(Entry)#60 (3) {
["_fields":protected]=>
array(5) {
["id"]=>
string(6) "512436"
["author_id"]=>
string(1) "1"
["section_id"]=>
string(1) "3"
["creation_date"]=>
string(25) "2015-05-01T18:48:14+02:00"
["modification_date"]=>
string(25) "2015-05-01T18:48:14+02:00"
}
["_data":protected]=>
array(7) {
[10]=>
array(2) {
["value"]=>
string(10) "Ted Tester"
["handle"]=>
string(10) "ted-tester"
}
[11]=>
array(1) {
["relation_id"]=>
int(512411)
}
}
["creationDate"]=>
string(25) "2015-05-01T18:48:14+02:00"
} The entry doesn't have any |
At least the above explains the behaviour with my "fix" (which should be reverted). There is a But the process of saving entries in Symphony is over my head. |
@michael-e I think we need, again, @brendo to give us some insights... |
I am also OK with giving up on this, I can use a custom field to achieve what I need. I pass the decision to @brendo. |
Yes, in hindsight that fix doesn't work at all because it can't determine between the initial |
At the moment — working hard to get a project up and running — I have a real talent to open Pandora's box(es). But as I said, we might just quickly close this box, at least for now. I have implemented a custom field that gives me greater flexibility anyway. |
I've reverted the fix for the meantime, but yes, you have a knack of discovering some deep flaws in our architecture! From experience, this problem seems to be something that I've seen handled by the concept of 'dirty' objects. Angular and Laravel (I'm sure others as well) maintain a state of the object, and then are able to different the properties to see if anything has changed. I believe if we could do this, we could do 'if modification date is dirty, don't set it, otherwise set it to be the current time', which would solve our problem and have the code work in both scenarios (programmatically or via the UI). |
@brendo I'd love to have a dirty state. But those things are hard to get right. I'd would love to review any code related to this :) |
Agree. My initial thoughts were to overload the |
I really like the hash idea. But, from experience, the best dirty system I've build required dev to manually set the dirty bits. One could want to change the entries in memory but not persist the change. Also, I would try to see if a global dirty bit would be enough. Or maybe per field dirty bit... I do not know if comparing array is faster than hashing. Is easier to code tho. |
Keep cool. Apart from a performing a programming exercise, what would we win? We'd make a "naturally grown" architecture even more knotted. I'd suggest to revisit this issue when the time comes to re-write this architecture anyway. (I am not even sure that setting these dates programatically is indeed desirable. It was just, well, I tried it…) |
LOL. Having this kind of system would enable perf optimisation. But hey, it's not a requirement... |
This is fixed in 3.0.0 |
When committing entries:
$entry->set('creation_date', $date)
will only work ifsetDataFromPost
is used in dry-run mode.$entry->set('modification_date', $date)
doesn't work at all.@brendo already has a test scenario (that I created for #2398).
The text was updated successfully, but these errors were encountered: