Using Statistics with a Profile installation prevent statistics collection

Created on 5 February 2025, 18 days ago

Problem/Motivation

I am using a Drupal installation using a Profile , my modules are installed in wwwroot/profiles/PROFILE_NAME/modules/contrib/ instead of wwwroot/modules/contrib/ .

In that case, the file statistics.php, accessible from http://mysite/profiles/PROFILE_NAME/modules/contrib/statistics/statistic... is called correctly, but crashes with the following error message :
PHP Fatal error: Uncaught Error: Failed opening required 'autoload.php' (include_path='.:/usr/share/php') in wwwroot/profiles/PROFILE_NAME/modules/contrib/statistics/statistics.php

Because the chdir instruction at line 23 is missing a two-levels jump to hit the Drupal web root.

Steps to reproduce

Install the Statistics module inside a profile-based installation.

The Composer instructions to do so are :

        "installer-paths": {
            "wwwroot/core": [
                "type:drupal-core"
            ],
            "wwwroot/profiles/PROFILE_NAME/libraries/{$name}": [
                "type:drupal-library"
            ],
            "wwwroot/profiles/PROFILE_NAME/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "wwwroot/profiles/PROFILE_NAME/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "wwwroot/profiles/PROFILE_NAME/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "wwwroot/profiles/PROFILE_NAME/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "wwwroot/profiles/PROFILE_NAME/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },

Proposed resolution

Detect if a Profile installation is used, then jump two levels higher.

After line 23 of statistics.php , add :

  // Jump two levels higher if a profile is used (/profiles/PROFILE_NAME/modules/contrib/statistics)
  if (!file_exists('autoload.php') && basename(realpath(getcwd() . '/..')) == 'profiles') {
    chdir('../..');
  }

(I will try to properly submit a merge request but I have never done that)

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance mpellegrin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mpellegrin
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinayakmk47

    Hi @mpellegrin, If you use Composer to manage modules in the profile-based installation, ensure your composer.json includes the correct installer-paths for the statistics module:

    "installer-paths": {
        "wwwroot/modules/contrib/{$name}": ["type:drupal-module"],
        "wwwroot/profiles/PROFILE_NAME/modules/contrib/{$name}": ["type:drupal-module"]
    }
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance mpellegrin

    Hi @vinayakmk47 , thanks for your answer

    I actually do not want to mess with my directory structure and keep the modules inside my profile directory. I assume that the Statistics module should work with any type of Drupal installation ; Drupal distributions like "Drupal Commerce" or the newish "Drupal CMS" are using Profiles, I believed it was a pretty common installation mode.

    Is the installation path actually a prerequisite of the Statistics module ?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinayakmk47

    Hi @mpellegrin,

    Thank you for clarifying your setup! You're absolutely rightโ€”Drupal modules, including the Statistics module, are designed to work regardless of the directory structure, and using profiles is indeed a common practice, especially in distributions like "Drupal Commerce" or "Drupal CMS."

    The issue you're encountering seems to stem from the statistics.php file not correctly detecting the root directory when modules are installed within a profile. The installation path is not a prerequisite for the module itself, but the script assumes a certain directory structure, which may cause issues in profile-based installations.

    To address this without altering your directory structure, you could consider your approach it's fine.

Production build 0.71.5 2024