I had configurate a multisite and trying to use the theme_image_style functionality to create picture on the fly but it does not work.

I am using the multisite configuration with just one DB instance for all sites. My problem is directly with the usability of theme_image_style.

$sites['mysite.com'] = 'default';
$sites['m.mysite.com'] = 'mobile';

mobile/files is a symbolic link to default/files. Even if I do not use a symbolic link, it does not work either.

- theme_style_image return the right URL and looks working perfectly but...
- theme_style_image does not create the images in files/

I do not understand why images are not created for other sites that are not the default one. Please help, I am in the middle of a big development and the architecture requires this working.

Comments

catch’s picture

Component: configuration system » image system
Category: bug » support
Priority: Critical » Normal

This is a support request, moving to the right queue.

You should debug in the image module where derivatives are created/written to disk to see what's going on there.

farfanfelipe’s picture

Title: Multisite configuration and theme_image_style problem » Investigating code theme_image_style

I do not find the trigger for Drupal creating the physical image. Somebody knows about it?

farfanfelipe’s picture

Title: Investigating code theme_image_style » Found the problem but do NOT know the best practices to fix it

File: \modules\image\image.module
Lines: 83 - 90
Why: the multisite configuration is not supported by image core.

I can fix it setting an array with the multisite folder configuration but I want to set it as generic. How?

$sites = array('sites/default/files', 
                'sites/my_site_1/files', 
                'sites/my_site_2/files',
                'sites/my_site_3/files',);
  
  foreach ($sites as $site_path) {
    $items[$site_path . '/styles/%image_style'] = array(
      'title' => 'Generate image style',
      'page callback' => 'image_style_deliver',
      'page arguments' => array(count(explode('/', $site_path)) + 1),
      'access callback' => TRUE,
      'type' => MENU_CALLBACK,
    );
  }

Ideas?

Note: I want to mention that I am using the same DB instance for all sites and same Drupal core... Typical multisite configuration.

farfanfelipe’s picture

Adding items for each site into the image_menu solve the problem. I will create a patch to fix this.

$directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
  $items[$directory_path . '/styles/%image_style'] = array(
      'title' => 'Generate image style',
      'page callback' => 'image_style_deliver',
      'page arguments' => array(count(explode('/', $directory_path)) + 1),
      'access callback' => TRUE,
      'type' => MENU_CALLBACK,
    );
 
  //implementation of multisite image functionality
  foreach( file_scan_directory(DRUPAL_ROOT . '/sites', '//', array('recurse' => FALSE)) as $site_folders) {
    $folder_names_not_sites = array('all', 'default', 'sites', 'README');
    if( !in_array($site_folders->name, $folder_names_not_sites) ) {
      $site_folder_path = str_replace('default', $site_folders->name, $directory_path);
      $items[$site_folder_path . '/styles/%image_style'] = array(
        'title' => 'Generate image style',
        'page callback' => 'image_style_deliver',
        'page arguments' => array(count(explode('/', $site_folder_path)) + 1),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
      );
    }
  }
farfanfelipe’s picture

Status: Needs work » Needs review

I create the patch but not sure if I successfully uploaded to Drupal.

image-multisite-1965620-01.patch

farfanfelipe’s picture

StatusFileSize
new4 KB

Created patch !

David_Rothstein’s picture

Title: Found the problem but do NOT know the best practices to fix it » Issues using theme_image_style() on a multisite configuration
Status: Needs review » Postponed (maintainer needs more info)

@farfanfelipe, are you trying to have one site in a multisite configuration write to another site's files directory?

Drupal doesn't support that; sites in a multisite configuration are supposed to be completely independent Drupal installations that only share the same code (see http://drupal.org/documentation/install/multi-site).

However, if you're trying to make that happen in a custom setup, something similar to the code you wrote above might work. You'd probably want to put that in a custom module.

farfanfelipe’s picture

Yes, I already have different sites under one Drupal core with one DB instance and Drupal itself support that. I created a custom module to handle the permission of content for the different sites, nothing fancy and it is the part that Drupal does not have as functionality. I wanted to implement the image problem and I think that should be part of Drupal core because I am not the only one trying to implement multisite using the same core and BD but they did not figure it out and this implementation can help to improve Drupal for multisite. Don't you think?

farfanfelipe’s picture

I already applied to my sites as part of a custom module but I believe this can be really useful for the Drupal community.

Version: 7.22 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Postponed (maintainer needs more info) » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.