salesforce_api.module currently uses libraries_get_path() in one of it's calls to define():

define('SALESFORCE_DIR_TOOLKIT', libraries_get_path('salesforce') . '/toolkit');

The problem with this is if the module weight of libraries or salesforce_api is changed so that libraries is loaded after salesforce_api, then this generates a WSOD. ie, the only reason it works by default is because they have the same weight and salesforce_api is alphabetically later.

Perhaps this could / should be made more robust for the odd user who starts playing around with module weights via the Util module?

Comments

kostajh’s picture

That sounds fine to me, a patch would be welcome.

EvanDonovan’s picture

I guess we would have to check function_exists, and if it didn't, fall back on just looking at "sites/all/libraries"?

The side effect then would be that Libraries would not be a hard dependency anymore, either.

kostajh’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Component: Code » salesforce_api
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new867 bytes

The Salesforce API module can't be installed with an install profile until this is fixed.

Here's a patch using the approach in comment #2.

kostajh’s picture

StatusFileSize
new866 bytes

Sorry, small error in the patch above.

kostajh’s picture

StatusFileSize
new8.77 KB

This patch also removes Libraries as a dependency in the .info file, and updates the README (my editor also removed all the trailing spaces from the README... so the patch is a bit larger than it should be).

brianV’s picture

kostajh:

Just a thought, this breaks if you are using a multi-site install and don't have libraries installed.

We should do something like the below - it should work for multi-site, install profiles, and normal sites. Also, should be reasonably performant if variable_set() and variable_get() work in this context. Finally, would remove the need for Libraries altogether as it checks the same paths in the same order.

Sorry for not providing the below as a patch - it started as 'back of envelope' code to illustrate what I was trying to describe, and bloomed into below. I can set up the salesforce repo and create it as a patch if necessary.


$toolkit_path = salesforce_api_locate_toolkit();
define('SALESFORCE_DIR_TOOLKIT', $toolkit_path);

/**
 * Locates the salesforce toolkit api, if installed.
 */
function salesforce_api_locate_toolkit() {
  $toolkit_path = variable_get('salesforce_toolkit_path', '');

  // If the toolkit path is not set or is no longer valid, try to find it.
  if ($toolkit_path == '' || !file_exists($toolkit_path)) {

    $profile = drupal_get_profile();
    $config = conf_path();

    // First check if this was provided along with the profile.
    if (file_exists("profiles/$profile/libraries/salesforce/toolkit")) {
      $toolkit_path = "profiles/$profile/libraries/salesforce/toolkit";
    }
    
    // Check the sites/all directory.
    else if (file_exists("sites/all/libraries/salesforce/toolkit")) {
      $toolkit_path = "sites/all/libraries/salesforce/toolkit";
    }
    
    // Now check our current site directory (if multisite).
    else if (file_exists("$config/libraries/salesforce/toolkit")) {
        $toolkit_path = "$config/libraries/salesforce/toolkit";
    }
    
    // Toolkit not installed.
    else {
      $toolkit_path = "";
    }
    
    variable_set($toolkit_path);
  }

  return $toolkit_path;
}
kostajh’s picture

StatusFileSize
new3.07 KB

Thanks brianV, that looks good and works correctly. Here it is as a patch. I added a line to use Libraries API if it is available.

kostajh’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)
kostajh’s picture

kostajh’s picture

Status: Patch (to be ported) » Closed (won't fix)