1

I'm trying to get File Permissions working in Drupal 8.9 with Drush 9. The old code calls _drush_file_private_path(), which doesn't exist anymore, and _drush_file_public_path() is probably a no-go as well.

What is the proper way to do the following in Drush 9?

define('DS', DIRECTORY_SEPARATOR);

// Define default paths and variables.
$default = 'sites' . DS . 'default';
$private = $default . DS . 'private';
$files = $default . DS . 'files';
$directories = array();

// Check for Private Files subdirectory.
$private_directory = _drush_file_private_path();
if (empty($private_directory)) {
  $private_directory = $private;
}
$directories[] = $private_directory;

// Check for Public Files subdirectory.
$public_directory = _drush_file_public_path();
if (empty($public_directory)) {
  $public_directory = $files;
}
$directories[] = $public_directory;

As an additional note, it would be amazing if a resource existed to see all deprecated/removed functions and their equivalent replacements. I can't even get decent results when using a search engine and the function name.

  • When I google those functions together with the word "deprecated" I come to github.com/drush-ops/drush/pull/2654/…. Have you tried \Drupal\Core\StreamWrapper\PrivateStream::basePath() and \Drupal\Core\StreamWrapper\PublicStream::basePath() already? – leymannx Sep 7 at 19:56
  • No there is noch such resource. Simply scan the Drush codebase to look for similar patterns. – leymannx Sep 7 at 20:03
  • 1
    @leymannx Yeah, that works. Including the word "deprecated" when searching seems to improve the results significantly. Thanks. Consider writing an answer. – mbomb007 Sep 7 at 20:08
  • 1
    It should also be noted that DuckDuckGo doesn't return good search results, but Google does. – mbomb007 Sep 7 at 20:16
  • Yep, that's true. I have DuckDuckGo as default search engine but for work-related stuff most of the time I have to search via Google (with a logged in dummy account to have even better results later). I have g as keyword in the address bar for Google Search and then only have to type g and then press tab and can enter the search query I want to feed to Google. – leymannx Sep 7 at 20:29
1
  • _drush_file_private_path()
  • _drush_file_public_path()

in the end were just wrapper functions of

  • \Drupal\Core\StreamWrapper\PrivateStream::basePath()
  • \Drupal\Core\StreamWrapper\PublicStream::basePath()

And you probably get the same from

  • \Drupal::service('file_system')->realpath('private://')
  • \Drupal::service('file_system')->realpath('public://')
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.