Problem/Motivation

There is a unique constraint on the uri column in {file_managed}. When inserting a new row it is only checked that the URI is unique on the filesystem, but not in the database. If the file has been deleted from the filesystem, but the entity still exists, this results in a PDO exception.

Proposed resolution

The code is already too complicated and buggy - previous patches posted in this issue were making it more complicated: refactor the code related to creating unique URIs.

Managed file operations, e.g. file_copy() / file_move() should not have the option to "take over" an existing file entity. It should be hardcoded to make sure the new URI is unique in database and filesystem. A file entity's URI can change, but the contents of a file entity's file must never change.

Replace constants:
FILE_EXISTS_RENAME, FILE_EXISTS_REPLACE, FILE_EXISTS_ERROR
should be:
FILE_CHECK_EXISTS_FALSE, FILE_CHECK_EXISTS_FS, FILE_CHECK_EXISTS_DB_FS

We do not need FILE_EXISTS_ERROR - code that needs this functionality can check itself.

The database should be checked for an existing URI before the filesystem as communicating with the filesystem can be very expensive, e.g. it could be in the cloud.

There is no situation where it is necessary to check database for an existing URI but not the filesystem.

Combine file_destination() and file_create_filepath() into file_uri_prepare() - a single function that ensures a URI is suitable for a new file.

Calls to file_valid_uri() just get in the way as it is perfectly valid to pass a filepath instead of a URI.

file_move() shouldn't return an entity as it is just modifying the entity that is passed to it.

file_copy() / file_move() / file_save_data() should set the filename of the resultant entity to the basename of the desired destination (provided it isn't a directory), not the basename of the resultant URI.

Remaining tasks

Review patch.

User interface changes

none

API changes

file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_copy(File $file, $destination = NULL)

file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_unmanaged_copy($source, $destination = NULL, $check_exists = FILE_CHECK_EXISTS_FS)

file_destination($destination, $replace) and file_create_filename($basename, $directory) =>
file_uri_prepare($uri, $check_exists = FILE_CHECK_EXISTS_FS)

file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_move(File $file, $destination = NULL)

file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_unmanaged_move($source, $destination = NULL, $check_exists = FILE_CHECK_EXISTS_FS)

drupal_file_exists($uri, $check_db = FALSE)

file_save_upload($source, $validators = array(), $destination = FALSE, $replace = FILE_EXISTS_RENAME) =>
file_save_upload($source, $validators = array(), $destination = NULL)

file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_save_data($data, $destination = NULL)

file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) =>
file_unmanaged_save_data($data, $destination = NULL, $check_exists = FILE_CHECK_EXISTS_FS)

system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) =>
system_retrieve_file($url, $destination = NULL, $check_exists = FILE_CHECK_EXISTS_FS)

Original report by pwolanin

Found this in Drupal 7, but the fix should be the same for both 7 and 8 (and maybe 6?).

Discussed the problem with aaronwinborn and effulgensia and the it seems pretty clear we have a bug in terms of file_destination() because for a managed file it only checks if the file exists on disk.

This can lead to an SQL error if the URI exists in the {file_managed} table. For example, if I have 2 webnodes with local /tmp directories, a file being saved to temporary:// may not exist on disk, but may exist in the database. This can also happen if entries are not correctly purged when a file is deleted off disk.

There is a second bug which is a renaming race condition. If 2 users are trying to upload a file at about the same time, the simple incrementing logic may give both users the same file name.

Proposed fixes:

#1: when saving a managed file, check the URI in the database as well as on disk.

#2: when generating a suffix in the case of a duplicate file to be renamed, use a random 4-6 character string, rather than just incrementing.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because Drupal throws a PDO exception and gets into a broken state that can only be resolved by editing the database directly. This prevents people from adding files.
Issue priority Not critical because it only affects sites where the database and filesystem are no longer have consensus and the problem can be resolved by manually editing the database to match the filesystem. Major because this bug prevents file uploads from working and is encountered quite commonly, e.g. due to staging.
Prioritized changes This bug is prioritized because it is a bug fix, it needs to be backported to D7, and because the fix reduces fragility and narrows the API.
Disruption Disruptive because contrib modules using these functions will need to be updated. However, these changes are very minor.
BC layer A bc layer is not required because it would introduce a lot of technical debt. The patch really simplifies the API. There is no benefit in retaining the broken API for compatibility purposes. The patch removes 216 lines of code.
Can it be postponed If this change was postponed until 8.1 then we would need a BC layer which would increase technical debt.
CommentFileSizeAuthor
#133 drupal-refactor_file_inc-1556396-133-D7.patch7.77 KBoadaeh
#120 interdiff.txt26.9 KBsriharsha.uppuluri
#120 refactor_file_inc_to-1556396-120.patch92.4 KBsriharsha.uppuluri
#116 refactor_file_inc_to-1556396-116.patch92.42 KBmgifford
#108 refactor_file_inc_to-1556396-108.patch94.69 KBsidharrell
#107 1556396-zombies-106-D7.patch7.43 KBsidharrell
#106 1556396-zombies-106-D7-do-not-test.patch7.43 KBsidharrell
#94 interdiff-1556396-92-94.txt6.92 KBsidharrell
#94 refactor_file_inc_to-1556396-94.patch94.69 KBsidharrell
#92 refactor_file_inc_to-1556396-92.patch93.07 KBsidharrell
#92 interdiff-1556396-90-92.txt4.77 KBsidharrell
#90 interdiff-1556396-88-90.txt4.33 KBsidharrell
#90 refactor_file_inc_to-1556396-90.patch92.41 KBsidharrell
#88 refactor_file_inc_to-1556396-88.patch92.4 KBsidharrell
#88 interdiff-1556396-86-88.txt2.03 KBsidharrell
#86 refactor_file_inc_to-1556396-86.patch91.98 KBsidharrell
#72 refactor-check-files-exist.patch90.31 KBjbrown
#70 refactor-check-files-exist.patch91.29 KBjbrown
#67 refactor-check-files-exist.patch91.1 KBjbrown
#66 refactor-check-files-exist.patch91.09 KBjbrown
#63 refactor-check-files-exist.patch91.05 KBjbrown
#58 refactor-check-files-exist.patch90.9 KBjbrown
#56 refactor-check-files-exist.patch90.93 KBjbrown
#53 refactor-check-files-exist.patch90.81 KBjbrown
#51 refactor-check-files-exist.patch88.75 KBjbrown
#50 refactor-check-files-exist.patch89.97 KBjbrown
#47 refactor-check-files-exist.patch90.03 KBjbrown
#46 refactor-check-files-exist.patch82.88 KBjbrown
#43 refactor-check-files-exist.patch90.31 KBjbrown
#39 refactor-check-files-exist.patch89.55 KBjbrown
#33 refactor-check-files-exist.patch89.49 KBjbrown
#31 refactor-check-files-exist.patch85.78 KBjbrown
#27 drupal-1556396-27.patch7.8 KBtim.plunkett
#21 1556396-zombies-21.patch7.72 KBpwolanin
#19 1556396-zombies-19.patch7.61 KBpwolanin
#17 1556396-zombies-15-D7-do-not-test.patch7.43 KBgábor hojtsy
#15 1556396-zombies-15-D7-do-not-test.patch7.42 KBpwolanin
#9 drupal-zombie-files.patch7.45 KBeffulgentsia

Comments

dave reid’s picture

It looks like file_create_filename() is also going to have this problem too.

pwolanin’s picture

It's not clear if this is a problem with the normal core file module, but at least will be a problem with user pictures in user_validate_picture()

effulgentsia’s picture

I think the bug is real, but to make progress, we should find a nonbuggy way of triggering it. Which means, we either need a plausible scenario under which a public:// (or other non-temporary) file can be in {file_managed} but not on disk, or else a plausible scenario under which temporary:// files can exist (even if briefly) in {file_managed} (given a multiple web node scenario, we should always assume that temporary:// files might not be on disk at any particular time).

As per #2, a regular file field upload does not save an intermediary temporary:// file to {file_managed}, but possibly user module, media module, and other modules do, but the question is, is doing so ever legitimate, or is that a bug in itself?

pwolanin’s picture

Yes, basically file_create_filename() is where the problem lies.

Possible we need to create an alternate version of that, or pass in a flag for managed files.

pwolanin’s picture

discussed w/ effulgensia - a simple way to reproduce (and write a test) is to delete the file off disk and then try to upload the same file again.

It's a #fail if for some reason the sysadmin deletes a file off disk (e.g. via SFTP) and then it's impossible to ever upload a replacement via the UI.

effulgentsia’s picture

Title: PDO exceptions when uploading files due to duplicate URI in {file_managed} » PDO exception when trying to upload a file that exists in {file_managed} but not on disk
Priority: Major » Normal

I can confirm that #5 happens. Retitling and downgrading to normal, because I don't think it's major unless there's a way to reproduce it from Drupal interaction exclusively.

pwolanin’s picture

Priority: Normal » Major

@effulgensia - for user profiles it can happen for sure?

dave reid’s picture

Considering this is the first I've heard of this with over a year of Drupal 7, I'm inclined to say it's more of a un-typical server configuration or unintentionally malicious admin removing files, which to me says this is normal.

effulgentsia’s picture

Status: Active » Needs review
StatusFileSize
new7.45 KB

How about this? This does #1 from the issue summary. I think randomizing suffix for race conditions belongs in a separate issue.

pwolanin’s picture

Looks like a reasonable approach to me.

dries’s picture

This patch looks good so I'm tempted to mark it RTBC.

The only question that came to mind is whether we need all these options? Can't we always check for the file to exist in both the database and on the file system? It seems odd that we would want to support inconsistent database tables.

effulgentsia’s picture

The reason for FILE_CHECK_EXISTS_FILE is to make drupal_file_exists() by default be BC compatible with file_exists(), because:
1) I think we generally try to do that for drupal_*() versions of native PHP functions
2) So this patch can be backported to D7
3) So that when file_destination() is called from file_unmanaged_copy(), it works (unmanaged files are ones that don't exist in the {file_managed}).

The reason for FILE_CHECK_EXISTS_FILE_OR_ENTITY is to support the goal of this issue, which is to rename an upload to not clash with either something on disk, or something in the db. While we don't want to encourage inconsistency between db and disk, there are conditions in which it can happen (e.g., someone deletes a file from disk via the command line, but leaves the db record around, or an unmanaged file is copied to disk, and by definition isn't meant to have a db entry), and if we're saving an upload, we just want a name that's free both with respect to disk and with respect to db.

FILE_CHECK_EXISTS_FILE_AND_ENTITY is used by the test in this patch for asserting a file exists in both.

FILE_CHECK_EXISTS_ENTITY has no use-case so far, but is just there for symmetry.

pwolanin’s picture

The function is also used for unmanged files - i.e. they are never listed in the database.

I guess the DB query is a no-op in that case, but it's a query we don't need to do.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

I backported this to D7 and verified that it prevents the error there also when the patch is applied.

pwolanin’s picture

StatusFileSize
new7.42 KB

Here's the D7 patch - the .test file is in a different directory.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

The const keyword is not available in PHP 5.2.4/5.2.5 which is the minimim requirement for Drupal 7 as per http://drupal.org/drupal-7.0 and http://drupal.org/requirements

gábor hojtsy’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7.43 KB

Wups, sorry, the issue is still on D8. Here is an updated D7 patch though. This should not be committed to D8. I'm setting back to RTBC for the D8 patch. I did not test either patch.

dave reid’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/includes/file.incundefined
@@ -2275,6 +2299,52 @@ function drupal_unlink($uri, $context = NULL) {
+function _drupal_file_entity_exists($uri) {
+  $query = new EntityFieldQuery();
+  return (bool) $query
+    ->entityCondition('entity_type', 'file')
+    ->propertyCondition('uri', $uri)
+    ->count()
+    ->execute();

Rather than having an internal helper function, we should convert this to file_load_by_uri() so that it actually returs a file object like user_load_by_name() does and therefore can be re-used by core and other modules. I think the use of EFQ is unnecessary here too. Just use a normal entity_load() because file entities are always in the database.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new7.61 KB

@Dave Reid - that's an easy change to make it like the user function, but note that the doxygen at http://api.drupal.org/api/drupal/includes!file.inc/function/file_load_mu... indicates that using the conditions is deprecated.

Status: Needs review » Needs work

The last submitted patch, 1556396-zombies-19.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new7.72 KB

Well, that causes some interesting additional test failures.

Based on the deprecation comments and the fact that fully loading the entity breaks the tests, I think Alex's original patch was closer to right. If we want a re-usable function, we should make it return the fid for a URI, as suggested in the doxygen.

dave reid’s picture

Hrm, could we maybe get more information about what exactly was causing the fails since it wasn't a drastic number of errors?

pwolanin’s picture

@Dave Reid - seems like we should, in any case, not use a deprecated parameter?

catch’s picture

Issue tags: +Needs backport to D7

Tagging.

lasbreyn’s picture

Issue tags: -Needs backport to D7

#21: 1556396-zombies-21.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, 1556396-zombies-21.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new7.8 KB

Rerolled for PSR-0 tests.

Status: Needs review » Needs work

The last submitted patch, drupal-1556396-27.patch, failed testing.

dave reid’s picture

Issue summary: View changes

complete sentence

jbrown’s picture

Title: PDO exception when trying to upload a file that exists in {file_managed} but not on disk » Refactor file.inc to make it simpler and prevent PDO exceptions when trying to upload a file that exists in {file_managed} but n
Status: Needs work » Needs review
StatusFileSize
new85.78 KB

This patch is for the new issue summary and contains the zombie test from #9.

jbrown’s picture

Title: Refactor file.inc to make it simpler and prevent PDO exceptions when trying to upload a file that exists in {file_managed} but n » Refactor file.inc to make it simpler and prevent PDO exceptions
jbrown’s picture

Issue summary: View changes

Issue summary

jbrown’s picture

Assigned: pwolanin » Unassigned
StatusFileSize
new89.49 KB

Added some logic and tests for file_copy() / file_move() / file_save_data() so that filename of resultant entity is updated to the basename of the desired destination (provided it isn't a directory).The problem was identified here: #1415858: file_move() doesn't rename files correctly when the name of the file changes.

jbrown’s picture

Issue summary: View changes

Fix typo

jbrown’s picture

Issue summary: View changes

add info about entity filename

Letharion’s picture

Possibly an issue on it's own, please let me know if so:

Is there any reason why file_unmanaged_copy uses file_exists when it could do fopen($source, "r") instead and get remote file support as well?

Edit: Spun of into #1736312: Let file_unmanaged_copy read remote files as well.

jbrown’s picture

Issue tags: -Needs backport to D7

#33: refactor-check-files-exist.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
Issue tags: +Needs backport to D7

#33: refactor-check-files-exist.patch queued for re-testing.

dave reid’s picture

Issue tags: +sprint, +Media Initiative
jbrown’s picture

StatusFileSize
new89.55 KB

reroll

berdir’s picture

This is going to conflict heavily with #1468328: Move file entity info, managed file, and file usage functionality into File module, which is now RTBC. Sorry about that :) I guess you want to wait with further re-rolls until that one is in, and then the easiest way to re-roll might be to copy the new functions over to file.module.

jbrown’s picture

Yeah - I know ;-). I'll reroll again when the other one gets in.

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new90.31 KB
mgifford’s picture

Marking related issue - #1163740: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} - I'm not sure if it's a duplicate, but worth pointing out here. This is definitely the master thread.

jbrown’s picture

That isn't a duplicate. There are many ways that "Integrity constraint violation" can occur.

jbrown’s picture

StatusFileSize
new82.88 KB
jbrown’s picture

StatusFileSize
new90.03 KB

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

webchick’s picture

Category: bug » task

This sounds like more a task than a bug to me, so moving it there to put us back under thresholds.

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new89.97 KB
jbrown’s picture

StatusFileSize
new88.75 KB

reroll

jbrown’s picture

Issue summary: View changes

minor

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new90.81 KB
yesct’s picture

Status: Needs review » Needs work
Issue tags: +Needs backport to D7, +sprint, +Media Initiative

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new90.93 KB

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new90.9 KB
yesct’s picture

@jbrown thanks for looking after this issue so well.

To aid getting reviews, it's helpful if you post a sentence describing what changes you made, and an interdiff. If you want a hand with making the interdiff, let me know or ask in irc.

jbrown’s picture

I've just been re-rolling the patch since #33 (August 15, 2012) - there aren't any changes.

Status: Needs review » Needs work

The last submitted patch, refactor-check-files-exist.patch, failed testing.

yesct’s picture

OH! no wonder I was having trouble figuring out the differences. well, thanks again. :)

yesct’s picture

Issue summary: View changes

clarify

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new91.05 KB

Fixed a test.

jbrown’s picture

Issue summary: View changes

Clarify summary.

jbrown’s picture

Issue summary: View changes

Summary clarification.

yesct’s picture

this has been being re-rolled for quite a while now.

is there any previous feedback that needs to be resolved?

Does this need a total re-review, or just a quick check to rtbc it?
I'm not sure what the next steps are to stop jbrown from re-roll-perpetuality. :)

pwolanin’s picture

Status: Needs review » Needs work

patch needs a re-roll

1 out of 13 hunks FAILED -- saving rejects to file core/includes/file.inc

jbrown’s picture

Status: Needs work » Needs review
StatusFileSize
new91.09 KB

reroll

jbrown’s picture

StatusFileSize
new91.1 KB

Changed the entity query in drupal_file_exists() to use count().

jbrown’s picture

Status: Needs review » Needs work
Issue tags: +Needs backport to D7, +sprint, +Media Initiative

The last submitted patch, refactor-check-files-exist.patch, failed testing.

jbrown’s picture

StatusFileSize
new91.29 KB
jbrown’s picture

Status: Needs work » Needs review
jbrown’s picture

StatusFileSize
new90.31 KB

Reroll.

jbrown’s picture

Issue summary: View changes

Update summary.

jbrown’s picture

Issue tags: -Needs backport to D7

Removing tag.

Status: Needs review » Needs work
Issue tags: -sprint, -Media Initiative

The last submitted patch, refactor-check-files-exist.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Add comma.

pwolanin’s picture

Category: Task » Bug report
Issue summary: View changes
Issue tags: +Needs backport to D7

not sure why this tag was removed - this is certainly a bug in D7

moving back to bug - I don't think this is just a task

pwolanin’s picture

patch needs a major re-roll for D8 now

Blooniverse’s picture

Who is going to do this (D8 re-rolling)? Since it is quite a hassle to have outdated entries in the table file_managed which refer to deleted files (manually from the file system).

Blooniverse’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 72: refactor-check-files-exist.patch, failed testing.

parasolx’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 72: refactor-check-files-exist.patch, failed testing.

mgifford’s picture

Issue tags: +Needs reroll

Needs a serious re-roll.

marthinal’s picture

Assigned: Unassigned » marthinal

I have started the re-roll but I need time. Let me continue and add the patch.

deanflory’s picture

Anything on this for Drupal 7 as I'm getting this when editing and changing nothing, then saving an Article:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '32' for key 'vid': UPDATE {node} SET vid=:db_update_placeholder_0 WHERE (nid = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => 32 [:db_condition_placeholder_0] => 61 ) in node_save() (line 1167 of /.../modules/node/node.module).

star-szr’s picture

Assigned: marthinal » Unassigned

Unassigning since it's been quite a while. This would be quite a challenging reroll and it may be easier to redo the patch with the most recent patch in mind.

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new91.98 KB

make testbot angry.

Status: Needs review » Needs work

The last submitted patch, 86: refactor_file_inc_to-1556396-86.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new2.03 KB
new92.4 KB

fixed some stuff.

Status: Needs review » Needs work

The last submitted patch, 88: refactor_file_inc_to-1556396-88.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new92.41 KB
new4.33 KB

makin progress.

Status: Needs review » Needs work

The last submitted patch, 90: refactor_file_inc_to-1556396-90.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new4.77 KB
new93.07 KB

more progress

Status: Needs review » Needs work

The last submitted patch, 92: refactor_file_inc_to-1556396-92.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new94.69 KB
new6.92 KB

I think I got all 8 testing green locally.
testbot, I know I've been hard on you lately, but it was for the greater good.
please be kind.

sidharrell’s picture

Issue tags: -Needs reroll

I just want to point out that the last time that patch was green was 2 years ago, and it's a 100kb patch.
Not to toot my own horn, but can I get a high five from someone?
That was some mean, nasty, thankless grunt work.

Where's my next "Needs reroll" tagged issue?

jbrown’s picture

Thanks so much Sidney for taking the time to get this passing again - I spent the best part of a week in the summer of 2012 working on this.

The issue summary explains everything. I think the patch satisfies what @Dries asked for in #11.

The key point is that with this patch Drupal does not assume that what is on the filesystem necessarily matches what is in the database. They can diverge very easily, e.g. due to staging issues. Drupal should be able to handle this in a graceful manner instead of throwing a PDO exception that requires the developer to perform surgery in the database to resolve.

I was able to make the file API considerably simpler while solving this issue. From Sidney's latest patch:
28 files changed, 391 insertions(+), 607 deletions(-)

That's 216 fewer lines of code in core with a vastly more robust file API.

I have reviewed the patch and everything is in order. Because I am the original author of the patch I can't mark RTBC.

I not sure what the policy is at this stage, but this is a major bug that can only be resolved my fixing the API. my recommendation is for this too be committed. It makes the whole sub-system considerably simpler.

Can someone please review?

jbrown’s picture

berdir’s picture

Yes, awesome work with that reroll.

I can't say if this can be committed to 8.0.x still. But to find that out, we need to make sure that the issue summary is up to date, prepare a change record and beta evaluation to argue why the API break would be worth it.

Another thing would be to check if we can find ways to make the API change smaller or keep a BC layer. Parts of file.inc recently moved to a FileSystem service. Maybe we can add the new API's there or make a new service for them, and keep the old functions ans depreated wrappers that still work as they did before.

See #2050759: Move drupal_chmod and other code in file.inc to a Drupal\Core\File\FileSystem class and the meta issue #2229865: [meta] Modernize File/StreamWrapper API.

jbrown’s picture

I think having a BC layer is a bad idea because the old API is fundamentally broken and this patch simplifies everything.

I'm happy to move these functions into a service, but this can happen in a follow up.

I'm going to go ahead and great a change record / beta evaluation.

sidharrell’s picture

All that is above my paygrade.
I'm not familiar enough with the API to be able to weigh in. I've only been in Drupal for a couple weeks, and am just trolling the "Needs reroll" tickets, cause it doesn't actually require very much familiarity with Drupal, and lets me leverage my general php skills. I'll leave all the weighty discussion to my betters and move on to the next ticket.
At least you people have a good base to work off of, now. I'll be curious to see what comes of it.
Cheers.

jbrown’s picture

Issue summary: View changes
jbrown’s picture

Okay - I've added the beta phase evaluation and created the draft change record: https://www.drupal.org/node/2426725

Can someone review them?

crotown’s picture

We have an Elite customer at Acquia who may be experiencing this same PDOException using Drupal 7.32. What are the prospects of someone re-rolling this patch for Drupal 7? We could immediately test the rerolled patch on a live site (if it indeed solves their issue) and help to move the patch toward RTBC status.

sidharrell’s picture

@crotown I rolled #17 (the last D7 version of the patch that I could see) against 7.32 and ran the full test suite against it locally overnight, came up with 51 fails. Gonna keep working on it. I should be able to get something posted today.

sidharrell’s picture

StatusFileSize
new7.43 KB

That straight reroll of #17 against 7.32. Have to upload the patch here, so I can have a link to feed to simplytest.me.
Trying to setup a sandbox there.

sidharrell’s picture

Version: 8.0.x-dev » 7.32
Assigned: Unassigned » sidharrell
StatusFileSize
new7.43 KB

sorry about the noise. I did ask in #drupal-infrastructure if there is an alternative way for my to use testbot outside of the issue, but haven't heard back. I'll change the version back to 8.0-dev soon.

sidharrell’s picture

Version: 7.32 » 8.0.x-dev
StatusFileSize
new94.69 KB

changing version back to 8-0-dev
requeing D8 patch to top of deck. interdiff 94-108 was 0 bytes.

sidharrell’s picture

Assigned: sidharrell » Unassigned
crotown’s picture

The patch #107 seems to have solved the issue for our D7 client, I'll report after it gets serious live use but it looks good so far.
@sidharrell: I cannot thank you enough! But thanks much, even though it is not enough.
The Drupal community is a wonder to behold!

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

pektinasen’s picture

I'll work on it and reroll the patch.

danylevskyi’s picture

I'm a mentor. Helping @pektinasen to work on the issue.

pektinasen’s picture

This reroll seems too big. Too many lines of code changed and file conflicts. I stop working on it.
If anyone wants to help me with this issue I'm at the re-roll table in the mentored sprint room.

danylevskyi’s picture

mgifford’s picture

Status: Needs work » Needs review
StatusFileSize
new92.42 KB

I don't know what happened to:
core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php

Mostly just a reroll though.

Status: Needs review » Needs work

The last submitted patch, 116: refactor_file_inc_to-1556396-116.patch, failed testing.

The last submitted patch, 116: refactor_file_inc_to-1556396-116.patch, failed testing.

zaporylie’s picture

File core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php was deleted in #2534012: Move module-specific migration support into the file module.

sriharsha.uppuluri’s picture

StatusFileSize
new92.4 KB
new26.9 KB

Just rerolled to apply patch successfully.

ndf’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 120: refactor_file_inc_to-1556396-120.patch, failed testing.

Gaelan’s picture

Assigned: Unassigned » Gaelan

Starting reroll.

Gaelan’s picture

Assigned: Gaelan » Unassigned
Issue tags: -Needs reroll

…or not, looks like it's already done.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Chris Charlton’s picture

Is D7 patch stalled?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

oadaeh’s picture

Hello.

I have an updated D7 patch for the one in #107.

I originally created it back in Oct/Nov of last year, but I wasn't sure it would actually work for the problems we were seeing. It turned out that it did, and it's been in production since mid-Nov. However, I forgot to submit it to this issue after realizing it was a keeper.

With the recent security update, the patch for this issue needs some work, since they both operate in some of the same functions.

So, attached is the updated patch with the security release accounted for.

I could not get an interdiff created, so I did not include one.
I kept getting this error:

1 out of 10 hunks FAILED -- saving rejects to file /tmp/interdiff-1.wMZiJE.rej
interdiff: Error applying patch1 to reconstructed file
oadaeh’s picture

Version: 8.6.x-dev » 7.x-dev
Status: Needs work » Needs review

I'm going to go ahead and adjust the issue for testing the D7 patch. Feel free to revert back to D8 afterwards.

roderik’s picture

Version: 7.x-dev » 8.8.x-dev

Thanks for the updated D7 patch. Verified manually that it's still essentially the same as the one in #15 - #107.

Back to 8.x.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mfb’s picture

I think this issue could be closed as outdated, or at a minimum it needs an issue summary update. The original issue is no longer relevant as there is no unique constraint on file_managed.uri since #1314214: MySQL driver does not support full UTF-8 (emojis, asian symbols, mathematical symbols); and all functions in file.inc are deprecated.

larowlan’s picture

Status: Needs review » Closed (works as designed)
Issue tags: +Bug Smash Initiative

Agree that

as there is no unique constraint on file_managed.uri

means this is no longer relevant