Problem/Motivation

system_check_directory() is only used in one place in core, in locale_form_system_file_system_settings_alter(), but its loaded on every request.

http://codcontrib.hank.vps-private.net/search?text=system_check_director...

Proposed resolution

Deprecated it without replacement because there's only 8 usages found in contrib

Remaining tasks

- patch/review
- update CR
- commit

User interface changes

no

API changes

The system_check_directory() is deprecated

Data model changes

no

Release notes snippet

no

Issue fork drupal-3073684

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Issue summary: View changes
kim.pepper’s picture

Status: Active » Needs review
StatusFileSize
new4.95 KB

Moved to locale.module and deprecated system_check_directory(). Also added a deprecation test.

kim.pepper’s picture

Issue tags: +Kill includes, +@deprecated
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Nice clean-up

andypost’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/locale/locale.module
@@ -758,7 +758,7 @@ function locale_form_system_file_system_settings_alter(&$form, FormStateInterfac
-    '#after_build' => ['system_check_directory'],
+    '#after_build' => ['locale_form_check_directory'],

@@ -767,6 +767,51 @@ function locale_form_system_file_system_settings_alter(&$form, FormStateInterfac
+function locale_form_check_directory($form_element, FormStateInterface $form_state) {

btw not sure that new "API" method in locale makes sense, usage in contrib is not big http://grep.xnddx.ru/search?text=system_check_directory

kim.pepper’s picture

@andypost do you suggest making it private? e.g. _locale_form_check_directory()

larowlan’s picture

I was originally thinking we could just move it to an .inc file and load that in locale module, to get it out of the hotpath.

We should be doing the same here, putting it in locale.module also means its in the hotpath for every page.

larowlan’s picture

actually, could we use a static method on a class to make it autoloaded on demand?

kim.pepper’s picture

StatusFileSize
new5.76 KB
new5.39 KB

OK. Something like this...

kim.pepper’s picture

As there are a bunch of dependencies, it would be better to make this a service.

+++ b/core/modules/locale/locale.module
@@ -758,7 +759,7 @@ function locale_form_system_file_system_settings_alter(&$form, FormStateInterfac
-    '#after_build' => ['system_check_directory'],
+    '#after_build' => [[SettingsFormHelper::class, 'checkDirectory']],

Would doing something like '#after_build' => [[\Drupal::service('locale.settings.helper'), 'checkDirectory']], be acceptable?

larowlan’s picture

My 2c

Keep the static method, but make it do \Drupal::classResolver()->getInstanceFromDefinition(self::class)->{aProtectedMethodThatIsntStatic} and move the logic into a protected method that isn't static

kim.pepper’s picture

But ClassResolver will just do $instance = new $definition(); which means you can't inject the deps?

larowlan’s picture

If your class implements ContainerInjectionInterface, it will call the ::create method and pass the container

kim.pepper’s picture

That's seems like a few additional steps of indirection. How is that better than just \Drupal::service()? (not even sure that works 🤔)

larowlan’s picture

using \Drupal::service means its in the container for all requests, which it doesn't need to be

larowlan’s picture

there's no harm in keeping it static fwiw

kim.pepper’s picture

StatusFileSize
new6.99 KB
new4.49 KB

OK here's a patch that uses the above approach.

berdir’s picture

Just some quick thoughts:

#6 shows that is not used *often*, but it is used a few times and there are likely quite a few more use cases that could use it, they probably just don't know about it. Given that it's autoloaded now, any harm in putting it somewhere outside of locale module? maybe Drupal\Core\Form, given how tightly integrated into the form system it is.

The "its loaded on every request." argument feels like micro-optimization, there's nowway that the existence of a 30loc function is in any way relevant for performance. The bigger argument is that having it has a service directly would get mean that we'd have to serialize the object and its dependencies as part of the form for the callback definition, that's considerably more overhead than having a function or service defined. Thought about a trait, would have the advantage that you can just define it as '::checkDirectory', but that requires each form using it to inject the necessary dependencies. So the approach in the patch, although a bit uncommon, seems like an interesting solution, maybe we could document how it's supposed to be used on the method, specifically if we make it an actual API?

kim.pepper’s picture

StatusFileSize
new7.63 KB
new2.26 KB

Thanks for the review @Berdir!

Moved the helper to \Drupal\Core\Form\SettingsFormHelper and added a comment about it being used as a #after_build callback.

kim.pepper’s picture

Title: Deprecate system_check_directory() and move to locale module » Deprecate system_check_directory()
Issue summary: View changes
andypost’s picture

As usage shows it's used by form element to ensure that directory exists and writable (puts htaccess?)
So probably better create special element class for that?

Status: Needs review » Needs work

The last submitted patch, 20: 3073684-20.patch, failed testing. View results

voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new7.7 KB
new2.67 KB

Replace deprecated code.

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.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.5.x-dev » 10.1.x-dev
StatusFileSize
new0 bytes
new6.15 KB

Rerolled for 10.1

Status: Needs review » Needs work

The last submitted patch, 31: 3073684-31.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new434 bytes
new6.37 KB
kim.pepper’s picture

Status: Needs review » Needs work

We seem to have dropped the deprecation test.

vacho made their first commit to this issue’s fork.

smustgrave’s picture

What file should that go to? The file SystemFunctionsLegacyTest is deleted

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new7.55 KB
new1.18 KB

It's ok to just create a new legacy test. I've added one here.

smustgrave’s picture

Makes sense! Can I mark RTBC

andypost’s picture

I'd want to rtbc but naming sounds weird, form helper class named as Settings*

No idea ATM for better name but I bet it will not pass commiters

smustgrave’s picture

Thinking just FormHelper?

andypost’s picture

+++ b/core/lib/Drupal/Core/Form/SettingsFormHelper.php
@@ -0,0 +1,112 @@
+ * Provides form helper methods.
...
+class SettingsFormHelper implements ContainerInjectionInterface {
...
+      $container->get('logger.factory')->get('file system'),
+      $container->get('file_system')

maybe instead of helper use a ElementFileSystem

andypost’s picture

Issue summary: View changes

OTOH there's only 8 usages in contrib so probably better to inline it into Locale module and deprecate without replacement

http://codcontrib.hank.vps-private.net/search?text=system_check_director...

Updated IS

smustgrave’s picture

maybe instead of helper use a ElementFileSystem

Not sure I follow

Or

better to inline it into Locale module and deprecate without replacement

smustgrave’s picture

Status: Needs review » Needs work
smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)

per #43

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Needs work

Believe this is still valid.

voleger’s picture

Status: Needs work » Needs review

Rerolled in MR. Please leave review comments in MR.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Small comment on MR

Looking at the CR, believe it should be fine but personally I'm big fan of before/after snippets.

Super close and will keep an eye out for this one.

If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

voleger’s picture

Status: Needs work » Needs review

Addressed review comments and updated CR

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks feedback appears to be addressed

catch’s picture

Status: Reviewed & tested by the community » Needs work

One comment on the MR.

voleger’s picture

Status: Needs work » Needs review

Introduced logger channel as a dependency

nicxvan’s picture

Status: Needs review » Needs work

A bunch of failures looks like a service is wrong.

berdir’s picture

The reason that only locale still uses this function is that we moved configuration of private/public/tmp stream wrappers to Settings in settings.php.

What if we do the same instead with this locale setting? Then we don't need any replacements.

(I had some concerns about removing as there are a handful of modules using this based on code search. But only 2 of those have a release that works on a supported core version, l10n_server and library_manager) and those don't seem to use it in current versions. So should be OK).

kim.pepper’s picture

What if we do the same instead with this locale setting? Then we don't need any replacements.

That sounds great!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

nicxvan’s picture

Title: Deprecate system_check_directory() » [pp-1] Deprecate system_check_directory()
Status: Needs work » Postponed
Related issues: +#3571172: Deprecate system_sort_themes() and system_check_directory() in system module

Thank you everyone for the great direction here.

I think we should postpone this even if it's older since the .module cleanup initiative is grouping these cleanup efforts to reduce conflict and churn.

I'll be sure to apply credit here before closing it out if we do go that direction.

There are only a few remaining functions and they are all relatively simple so we should just take care of all of them at once.

berdir’s picture

I created #3571593: Deprecate translation.path config in favor of settings, whether we deprecate this function here or in the other issue, that non-trivial but also not crazy-complex issue will make it trivial.

kim.pepper’s picture

nicxvan’s picture

yeah maybe we postpone this on that one for now, and we address it there or here, I'll work on the other functions in the other issue.

nod_’s picture

better search link: system_check_directory, i see only 2 contrib use that looks legit

nicxvan’s picture

I think the other one is very close.

I took a pass at credit to prepare.

nicxvan’s picture

nicxvan’s picture

Status: Postponed » Closed (outdated)

Thank you everyone! The other one landed so this is now outdated, I already applied credit in 65.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.