Problem/Motivation
Follow-up to #3021653: Move file status constant to FileSystemInterface
This constant related to file entity, so better to keep it in interface
Proposed resolution
Move definition to \Drupal\file\FileInterface and replace all usage
Also make sure that file module enabled when new constant will be used
Remaining tasks
- discus naming STATUS_PERMANENT or just PERMANENT
- patch, review, commit
User interface changes
no
API changes
Constant FILE_STATUS_PERMANENT moved to \Drupal\file\FileInterface::STATUS_PERMANENT
Data model changes
Release notes snippet
Comments
Comment #2
andypostLooks no usage of the constant except file module and dependent ones
Comment #3
andypostNaming still needs discussion
Comment #4
kim.pepperI like STATUS_PERMANENT. :-)
Can import the class.
Comment #6
andypostit means that lots of tests does not depend on file module but using it somehow
Comment #7
andypostAbout #4.1 I intentionally added FQDN here because this is a part of api docs
Comment #8
berdirI don't think the constant is really "used", but it *is* in file.inc, which is always loaded.
Just don't use the constant there and keep the old hardcoded value. Loading the constants there defeats the point of having them lazy-loaded on the interface anyway (just for BC, but still).
It's a constant, there is no reason to have it dynamic somehow.
Comment #9
googletorp commentedDid as suggested in #8 and converted FILE_STATUS_PERMANENT back to static variable.
Comment #10
andypostnot clear how that change can affect tests while this constant is not used
But I guess because this file loaded always so causing autoloader to fail when file module is not enabled
Comment #11
andypostComment #12
berdir> not clear how that change can affect tests while this constant is not used
But it *is* used right there, simply by loading that file, and that file is always loaded. The constant is defined there, based on the other constant, so it has to load that.
Instead of a @see, we need an change record for this and then the @deprecated line needs to point to that.
I remember this code from another issue, this is broken because $file->status is an object.
And it's extra broken because it is a type safe against an entity value, which aren't type safe.
Instead of just doing a 1:1 replacement of the constant, lets use isPermanent()/isTemporary() here, this will be much easier to read. Also the comment above doesn't really need to refer the constant, it's then also clear enough of we just write "is not yet permanent".
Comment #13
andypostFiled CR https://www.drupal.org/node/3022147
@Berdir nice idea! fixed both and added to CR as example
Comment #14
andypostThe related to #12.2 #2923428: Wrong check for file status in _editor_record_file_usage It needs to add tests anyway
Comment #15
andypostfix cs
Comment #16
berdirI thought it needs to be part of the @deprecated text, not @see. but that could be fixed on commit if necessary.
"temporary", also "saved" is not needed. Maybe also something to be fixed on commit, but someone could also upload an updated patch while it's RTBC.
Comment #17
alexpottSo for me we should consider completely removing this constant. I wonder what @Berdir thinks.
Let's change all of these to $file->setPermanent()
Consider replacing with ->setPermanent() on the entity once created.
For me hardcoding here would be fine - we've hardcoded the temporary after all.
If we do choose to keep the constant then this could be static::STATUS_PERMANENT as this object implements the interface.
If we choose to remove the constant then we should move these docs to \Drupal\file\FileInterface::isPermanent(). And perhaps these docs belong there more anyway.
This looks like one good reason to have the constant.
Comment #18
berdirHm, not sure, this constant isn't different to node status/sticky/promoted, user status, comment published, they all have such constants. We did convert them to constants on the interface, but they all date back a very long time.
Media on the other hand doesn't do that anymore and EntityPublishedInterface expects a boolean on setPublished (and the argument is deprecated anyway). And \Drupal\Core\Entity\EntityPublishedTrait::isPublished() just casts the value to a boolean. On the database level, it's 0/1, but the status/published fields are all of type boolean and then having value constants for that is indeed a bit strange.
permanent/temporary explains better than true/false or 0/1 what file status actually means, but most calls could indeed use the methods.
Comment #19
andypostI'd like to weight on more storage relation to this property neighter "published" otoh "draft" is makes more sense to me about file storage
Entity::create()and "filter value" is the only reason to have a constant, then maybe better move it to storage interface?Comment #20
berdirI don't like moving it to the storage, that's still different to all other entity types and I don't really want to promote custom storage implementations more than they already are, they just don't make for nice API's (hard to get correct autocomplete suggestions and things like that and every entity type with a custom storage class makes it harder for alternative storages to exist).
Comment #21
alexpottI agree with @Berdir that putting an entity value constant on the storage feels wrong because it is not storage related.
For the call is whether or not we should have the constant. If we should then let's put it on \Drupal\file\FileInterface.
I think this might be clearer once we convert everything to
isPermanent()/isTemporary()/setPermanent()/setTemporary()Comment #22
andypostDid rework for changes in #17
Comment #23
alexpottIt looks much nicer with
->setPermanent(). Thanks.So for me stuff like this is really odd... ie. once with the
(1, 0)and once with(1, FileInterface::STATUS_PERMANENT).I also ponder whether we need the word
STATUS<code>? i.e. <code>FileInterface::PERMANENTbut then maybe this is odd withFileInterface::isPermanent()andFileInterface::setPermanent(). Not sure.Comment #25
berdirComment #26
kim.pepperRe-roll of #22
Comment #29
daffie commentedPatch looks good.
Can we change this line to: "const FILE_STATUS_PERMANENT = FileInterface::STATUS_PERMANENT".
Deprecation must now happen in 9.1.
Comment #30
pavnish commentedComment #31
pavnish commented@daffie #1 and #2 done on this patch
Comment #32
daffie commentedPatch fails to apply.
Error:
@pavnish: Did you do a "git pull"?
Comment #33
pavnish commentedComment #34
pavnish commentedComment #35
pavnish commented@daffie yes i am working with drupal 8.8 and simply apply the patch #26 and done the changes.
Please correct me if i am wrong.
Comment #36
daffie commented@pavnish: The patch for 9.1 should go first and the testbot does not return green.
Edit: I did not want to unassign @pavnish from this issue.
Comment #37
pavnish commentedComment #38
pavnish commentedComment #39
pavnish commentedComment #40
pavnish commentedComment #41
pavnish commentedComment #42
daffie commentedThis change does not work. Please, change it back to:
Comment #43
pavnish commentedComment #44
kim.pepperI just did a re-roll of #26, updated the deprecation message version, and replaced a couple more usages of FILE_STATUS_PERMANENT in tests.
The interdiff is against #26.
Comment #45
kim.pepperSorry @pavnish just saw you had assigned this to yourself.
Comment #46
pavnish commented@daffie same #42 has been changed
Comment #47
pavnish commented@ your patch looks good @kim.pepper
Comment #48
daffie commentedAll occurrences of
FILE_STATUS_PERMANENThave been replaced.The constant has been properly deprecated.
The FileInterface has the replacement constant
STATUS_PERMANENT.The Is and the CR are in order.
All code changes look good to me.
For me it is RTBC.
Re-uploading the patch from comment #44 as that is the one that should be committed.
Comment #49
xjmAdding reviewer credits.
I read the above discussion about the constant naming and whether we should have an interface constant, and I think the current patch is taking the right approach on both points.
Since
setPermanent()is actually a better replacement whenever we have an instantiated file object, let's mention that in the deprecation message as well? (And in the CR.)We can probably just say:
Use \Drupal\file\FileInterface::STATUS_PERMANENT or \Drupal\file\FileInterface::setPermanent() instead.This is awkward wording. Since this is a deprecation (and therefore copied docs), but only a deprecation for this one exact thing, I could go either way on whether fixing the docs is in scope. Let's either fix it here or file a followup to fix it to:
Both those points could be addressed by a novice contributor, so tagging accordingly. Thanks!
Comment #50
munish.kumar commentedComment #51
munish.kumar commentedComment #52
munish.kumar commentedComment #53
munish.kumar commentedHi,
Uploading the patch with the above changes has been addressed. Please verify the patch.
Comment #54
munish.kumar commentedFixed the spacing issue, Uploaded the interdiff from the previous patch. Please review
Comment #55
daffie commentedUpdated the CR.
1 nitpick left:
The comment is not fully using the maximum 80 character limit.
Comment #56
munish.kumar commentedThanks @Daffie, For quick review. Here is the updated patch.
Comment #57
munish.kumar commentedComment #58
daffie commented@munish.kumar: I am missing the interdiff.txt. It makes reviewing your patch a lot easier.
Comment #59
munish.kumar commentedSorry @Daffie, I forgot to upload it. Here it is
Comment #60
munish.kumar commentedComment #61
daffie commented@munish.kumar: Thank you for the interdiff.txt file.
All points of @xjm and myself are addressed.
Back to RTBC.
Comment #62
xjmI changed the CR a bit to emphasize the public methods over the interface constant: https://www.drupal.org/node/3022147
I guess the deprecation message should also mention
isPermanent().Is that too long? We could shorten it to:
...and then the linked CR details which methods.
That said. After doing that, I'm actually going back to earlier comments and questioning whether we actually want the new API to be a constant. Yes, as @Berdir points out this is the historical behavior, but
isPermanent()andisTemporary()are a much clearer public API. Before, we didn't have an interface to make it explicit; now we do.isPermanent()versusisTemporary().$file->status->valuecould become booleans instead of integers. I guess there's the contrib usecase of defining additional file status values, likeFILE_STATUS_UNICORN = 2;But I'd argueFile::isUnicorn()should go in a separate field.FileStorage::spaceUsed()is... weird, broken? It defaults toFILE_STATUS_PERMANENTfor the second argument but doesn't say what you should pass instead if the file is not permanent. There's noFILE_STATUS_TEMPORARYso you'd have to pass a magic0. Seems like that second arg could easily be converted to boolean as well, with@trigger_error()ed fallback code if an integer is passed.Thoughts?
Comment #63
andypostit is not doable in near future, booleans are stored as integer in database and db drivers often return its values as string
Comment #66
andypostre-parented
needs update for 9.3
Comment #67
andypostRe-roll for 9.3.x and removed some usage as the value is the default
this method has 2nd argument default to permanent
Comment #68
andypostThe #62.3 about
\Drupal\file\FileStorage::spaceUsed()last argument needs follow-upComment #69
daffie commentedPatch looks good.
Just a small nitpick
The parameter value NULL can be removed. As it is the default value.
Comment #70
swatichouhan012 commentedRemoved Default 'NULL' parameter from patch #67.
Comment #72
andypostUnrelated failure
Comment #73
daffie commentedPatch is updated for 9.3.
The IS and the CR are in order.
All code changes look good to me.
There is no deprecation message test, because we are deprecating a constant.
For me it is RTBC.
Comment #75
catchCommitted a227db1 and pushed to 9.3.x. Thanks!