Followup to #3039026: Deprecate file_directory_temp() and move to FileSystem service

Problem/Motivation

The following comment in \Drupal\Core\Database\Driver\sqlite\Install\Tasks::connect refers to a removed function, file_directory_temp()

        // We cannot use file_directory_temp() here because we haven't yet
        // successfully connected to the database.

file_directory_temp() is deprecated and moved to the FileSystem service. See change notice.

Proposed resolution

Replace mention of the deprecated function in the comment with the new function.

\Drupal::service('file_system')->getTempDirectory() also requires database access.

Remaining tasks

Make a patch
Review
Commit

Comments

quietone created an issue. See original summary.

s_bhandari’s picture

Assigned: Unassigned » s_bhandari
s_bhandari’s picture

StatusFileSize
new811 bytes

Added a patch for the same.

s_bhandari’s picture

Assigned: s_bhandari » Unassigned
Status: Active » Needs review
nitvirus’s picture

Status: Needs review » Needs work

I think we should replace the function file_directory_temp() (as this is deprecated) with \Drupal::service('file_system')->getTempDirectory();. So, instead of removing the comment fully we should just replace the deprecated function with the code.

Thanks.

s_bhandari’s picture

Assigned: Unassigned » s_bhandari
s_bhandari’s picture

Assigned: s_bhandari » Unassigned
Status: Needs work » Needs review

Hi @nitvirus,

Thanks for reviewing the issue. The original requirement here was to remove the comment referring to file_directory_temp() and that has been done in this patch. Also, I think the point that you are depicting here has already been addressed. Please do have a check and let me know if there are any other thoughts on this.

Thanks.

nitvirus’s picture

Status: Needs review » Needs work

Sure,

Correct @S_Bhandari, the scope defines we should remove the comment.
The patch looks fine , can we also remove the empty line coming on top of comments.

s_bhandari’s picture

Assigned: Unassigned » s_bhandari

Sure, I will work on this.

Thanks.

mradcliffe’s picture

I think this still could be a novice issue because it needs an issue summary update to figure out why the comment exists.

+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
@@ -74,8 +74,6 @@ protected function connect() {
         $connection_info['default']['database'] = \Drupal::service('file_system')->tempnam(sys_get_temp_dir(), 'sqlite');

I think the comment may have some important history. Can you update the issue summary after researching why/when the comment got into the code base in the first place? This could be going into drupal 7's old directory structure for database drivers.

s_bhandari’s picture

Assigned: s_bhandari » Unassigned
Status: Needs work » Needs review
StatusFileSize
new872 bytes

Hi @nitvirus,

Added a patch for the observation you have shared. Please review the same and let me know for any other observation on this.

Thanks.

s_bhandari’s picture

Hi @mradcliffe,

I did research on when the comment got into the code base in the first place by running the git blame on the file and I can see that it is added in the commit ID - a5a2ce92, on 2012-11-20 10:57:13. I also have looked into the commit ID by running git show [COMMIT_ID] and can confirm that it was added in this commit only. Please do let me know if this information is fine with you.

Thanks.

mradcliffe’s picture

That's a good start. Finding the commit allows us to find that it was added in #203955: Create database at installation time. A really old issue. Back then, issues sometimes got multiple commits, spanned multiple versions. The patch that ended up being committed, that's relevant is https://www.drupal.org/project/drupal/issues/203955#comment-6698374.

We need to dig into that issue to starting from that comment, going up, and see if there was any discussion or reason why it was added. It wasn't in the initial several patches in the issue that I found.

We're looking for the explanation to determine if that comment should be removed in this patch or not.

tvb’s picture

Title: Remove comment referring to file_directory_temp() » Modify comment referring to file_directory_temp()
Issue summary: View changes
Issue tags: -Needs issue summary update
StatusFileSize
new838 bytes
new975 bytes

The comment appears for the first time in the patch file in comment #36.

file_directory_temp() is deprecated and moved to the FileSystem service. See change notice.

\Drupal::service('file_system')->getTempDirectory() also requires database access.

Tested by setting a faulty database connection and then executing a
drush php-eval "var_dump(\Drupal::service('file_system')->getTempDirectory());"
command.

The attached patch changes the comment to:

// We cannot use \Drupal::service('file_system')->getTempDirectory()
// here because we haven't yet successfully connected to the database.

Issue summary updated accordingly.

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.

awset’s picture

The patch file on #14 is working. Tested on 9.2 branch.

awset’s picture

Status: Needs review » Reviewed & tested by the community

  • catch committed a083cdf on 9.2.x
    Issue #3157370 by S_Bhandari, tvb, quietone: Modify comment referring to...

  • catch committed 563d6cb on 9.1.x
    Issue #3157370 by S_Bhandari, tvb, quietone: Modify comment referring to...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.