Allow creation of temporary files when using file_save_data function by adding the $status parameter. Will default to FILE_STATUS_PERMANENT to preserve previous behaviour.
Use cases:
#327512-31: devel_themer leaves files in /tmp
#105436: file_save_data -- Could use to easily save temp files too
Also, defining constant FILE_STATUS_TEMPORARY.
I'm aware that it was removed in #353207: Remove FILE_STATUS_TEMPORARY.
However, bitwise operation was dropped later in #809600: Stop using bit-wise operators for {file_managed}.status so now it makes sense to define it, IMO.
Comment | File | Size | Author |
---|---|---|---|
#77 | 1659116-nr-bot.txt | 134 bytes | needs-review-queue-bot |
#65 | interdiff-64-65.txt | 1.37 KB | Anonymous (not verified) |
#65 | 1659116-65.patch | 3.59 KB | Anonymous (not verified) |
#65 | interdiff-64-65.txt | 1.37 KB | Anonymous (not verified) |
#65 | 1659116-65.patch | 3.59 KB | Anonymous (not verified) |
Comments
Comment #1
amonteroComment #2
amonteroOps. Fixing title.
Comment #3
amonteroRerrolling testbot verified patch with amended commit message and function doc fix.
Comment #4
amonteroUnassigning to allow review.
Comment #5
amonteroTagging
Comment #6
amonteroChasing HEAD. Reroll in case issue gets attention.
Comment #7
amontero#6: 1659116-define-FILE_STATUS_TEMPORARY-and-expose-status-in-file_save_data-6.patch queued for re-testing.
Comment #8
amontero#6: 1659116-define-FILE_STATUS_TEMPORARY-and-expose-status-in-file_save_data-6.patch queued for re-testing.
Comment #10
amonteroReroll.
Comment #11
slashrsm CreditAttribution: slashrsm commentedI like the idea. Some people could complain that there are not so many use-cases that this does not make sense, but I believe it does no harm to include status as an argument.
I definitely support re-introduction of FILE_STATUS_TEMPORARY. Let's wait a little bit if any other arguments appear before we RTBC.
Comment #12
Berdir#10: drupal--1659116--define-FILE_STATUS_TEMPORARY-and-expose-status-in-file_save_data-10.patch queued for re-testing.
Comment #13
BerdirRe-roll incorrectly changes $user->id() back.
Comment #14
amonteroAddressing #13.
Comment #15
amonteroTest pass OK. Also, it looks like an easily backportable change.
If/when going RTBC, it would be great to have feedback about this.
Comment #16
slashrsm CreditAttribution: slashrsm commentedWould it make sense to FILE_STATUS_TEMPORARY and FILE_STATUS_PERMANENT into File entity class as class constants?
+1 for back-port. This shouldn't brake any APIs.
Comment #17
BerdirFileInterface actually. And yes, but that's a API change.
Comment #18
slashrsm CreditAttribution: slashrsm commented@Berdir: Are you talking about moving constants to an interface or backporting to D7?
Comment #19
BerdirAbout the constants. Agreed that this can be backported, but it is a feature, so getting it in core and backporting it is going to take... a long time ;)
Comment #20
slashrsm CreditAttribution: slashrsm commentedShould we leave this constants as they are then?
Comment #21
amonteroReroll of #14 with constants moved to FileInterface as per #16 & #17.
Comment #23
amonteroLots of commits lately. Failed to rebase against HEAD. Rebase'n'roll.
Comment #25
amontero@berdir , @slashrm: Moving constant definition triggers lots of 'undefined constant' notices. A quick grep on the constant FILE_STATUS_PERMANENT throws 28 occurences in 13 distinct files.
Such an added change would make patch bigger and harder to review. I'm afraid that this would slow even more the issue resolution and make it fail to be in before beta. Anyway, if such constant move is truly required, it can be dealt with in a followup (novice) issue.
Also, I'm not sure if this entire issue is a valid "Approved API" change. Would love to have some qualified feedback on this before proceeding any further.
Comment #26
amonteroStale patch, reroll.
Comment #27.0
(not verified) CreditAttribution: commentedAdding use case
Comment #28
amonteroReroll
Comment #29
slashrsm CreditAttribution: slashrsm commentedLooks good. Maybe we can open a follow-up to move constants to the interface?
Comment #30
alexpottMissing test coverage of calling this with FILE_STATUS _TEMPORARY
Comment #32
amonteroComment #33
amonteroFirst stab at tests.
Patch with just tests, should fail.
Comment #34
amonteroComment #36
amonteroAnd now, patch and test.
Comment #42
willzyx CreditAttribution: willzyx commented@amontero the test fails because
$this->randomName(8)
not exists. Probably you should use$this->randomMachineName(8)
Comment #43
amontero@willzyx: Thanks! Didn't spotted that... maybe my branch was too old and became obsolete (?) I was also tracking old '8.x' branch.
Tests only attached, should fail.
Comment #45
amonteroAnd now the full patch.
Comment #47
amonteroComment #48
amonteroAs soon as tests are deemed good enough, as per #29 this will be RTBC. I'll open a followup as requested and tag this as 'needs backport to D7', since it's a backwards compatible change.
Comment #51
amontero#45 became stale. Reroll.
Comment #52
amonteroSetting to RTBC as per #29. Steps after getting commited:
- Open followup issue to move constant as needed (seeding novice-tagged issue).
- Backport to 7.x.
Comment #53
alexpottHi @amontero thanks for work on this. Unfortunately we're in beta phase for Drupal 8 which means we're not accepting any new features. See https://www.drupal.org/core/beta-changes.
Looking at the patch two thoughts spring to mind firstly contrib can create temporary file entities by just creating a temporary and a file entity directly and it'd be possible to add support for this in a non bc breaking manner so I'm going to postpone to 8.1
Comment #55
drikc CreditAttribution: drikc commentedNeed this for D7.
Comment #58
Chi CreditAttribution: Chi commentedReopening this since 8.1 was release a long time ago.
Comment #59
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedReroll of #51
Comment #60
amonteroLooks good to me.
Comment #62
Anonymous (not verified) CreditAttribution: Anonymous commented+1 to RTBC.
FILE_STATUS_TEMPORARY
looks nice and it will be useful in other places too. As a possible follow-up can be created issue about replace magic value1 / 0
toFILE_STATUS_PERMANENT / FILE_STATUS_TEMPORARY
.Personally, I'm not a fan of the emergence of new opportunities to make files temporary 😜, but the flexibility in this behavior seems fair.
Also it would also be great to remove ossified behavior in
file_save_upload
, where we have the opposite situation:But it is separate issue, of course.
Comment #63
dawehnerPlease use
assertEquals
here. Please also keep in mind that on the left side of the equation you want to have the expected value.Comment #64
Anonymous (not verified) CreditAttribution: Anonymous commentedIndeed! Thank you, @dawehner! The test is hopelessly outdated. I overlooked this moment (the desire to get FILE_STATUS_TEMPORARY distracted me). Here's another:
Unnamed - not actual info, because we have name file to this test.
file_uri_scheme, drupal_basename, file_load also deprecated.
We need to check other options too, because we add a new parameter.
This patch fixed all of them. Only this test is interdiff with #59 (see test-only.patch).
In the next post will be offered another version of the test.
Comment #65
Anonymous (not verified) CreditAttribution: Anonymous commentedThis version based on question: Why do we do so many unrelated checks while checking the status?) Perhaps for historical reasons. Then we can do a general test, in which we check the basic behavior, and in-depth tests, in which there will be specific tests. Like this test.
Additional review:
Why in the dataProvider are used 1/0 instead of FILE_STATUS_PERMANENT/FILE_STATUS_TEMPORARY? I dont know. They are available inside the tests, but not available in dataProvider, so I replaced them with magic values.
Comment #77
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.