A while ago we upgraded to D7 and code highlighting stopped working except for PHP, and only if we had the "Use built-in PHP function highlight_string() for PHP source code." setting enabled.

The problem manifested itself with output that looked something like the following (reproduced from memory):

<div class="geshifilter">
<pre class="javascript geshifilter-javascript">
   var myVar = "hi";  
</pre></div>

Basically geshifilter module was clearly recognizing this as javascript, but the geshi library wasn't doing anything to it.

As a debug approach, I added the following snippet of code in a hook_init():


function mymodule_init() { 
  $geshi_library = libraries_load('geshi');
  if (!$geshi_library['loaded']) {
    drupal_set_message($geshi_library['error message'], 'error');
    return $text;
  }

  $source_code = "alert('hi');";
  $language = 'javascript';
  $output = geshi_highlight($source_code, $language, null, true);
  dsm($output);
}

And this worked! Trying the following though failed:


function mymodule_init() { 
  $geshi_library = libraries_load('geshi');
  if (!$geshi_library['loaded']) {
    drupal_set_message($geshi_library['error message'], 'error');
    return $text;
  }

  $source_code = "alert('hi');";
  $language = 'javascript';
  
  require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
  require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.pages.inc';

  //the following does what _geshifilter_geshi_factory() does
  $available_languages = _geshifilter_get_available_languages();
  dsm($available_languages);

  $geshi = new GeSHi($source_code, $language);
  $geshi->set_language_path($available_languages[$language]['language_path']);
 
  $output = $geshi->parse_code();
  dsm($output);
}

This suggested to me that there was a problem with _geshifilter_get_available_languages. And sure enough, the dsm($available_languages) showed entries like the following:

available_languages: Array
(
    [4cs] => Array
        (
            [language_path] => sites/all/modules/geshifilter/geshi/geshi
            [fullname] => GADV 4CS
        )

    [abap] => Array
        (
            [language_path] => sites/all/modules/geshifilter/geshi/geshi
            [fullname] => ABAP
        )

    [actionscript] => Array
        (
            [language_path] => sites/all/modules/geshifilter/geshi/geshi
            [fullname] => ActionScript
        )
    //lots more
)

Clearly that's not right, since all my geshi language files are in sites/all/libraries/geshi/geshi (as the D7 install asks for) rather than in geshifilter module directory (as was the case in the D6 version, I believe).

Looking inside _geshifilter_get_available_languages(), I noticed it caches by using variable_set('geshifilter_available_languages_cache', $available_languages);

So it seems the problem is simple: this "geshifilter_available_languages_cache" variable is stale, but there's no code to expire it.

Running "drush vdel geshifilter_available_languages_cache" fixed the problem on our site.

The patch (to be attached) to geshifilter.install.inc will hopefully fix the problem for anyone upgrading.

Also I'd suspect that if the code had used cache_set / cache_get rather than variable_set / variable_get, this problem would have been easily sidestepped with a call to "drush cc all". See http://www.lullabot.com/articles/a-beginners-guide-to-caching-data

Comments

pixelite’s picture

And the patch...

pixelite’s picture

Status: Active » Needs review

Forgot to update issue status.

Status: Needs review » Needs work
soxofaan’s picture

Title: Geshifilter stops working on update to D7 » Use cache_set+cache_get for variable caching instead of variable_set+variable+get
Category: bug » feature
StatusFileSize
new143.51 KB

So it seems the problem is simple: this "geshifilter_available_languages_cache" variable is stale, but there's no code to expire it.

There is a button on the GeSHi filter settings page to flush this cache. See attached screenshot.

However, you have a point that cache_set+cache_get would be a better fit here. Changed title and category of this issue accordingly.

yukare’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Assigned: Unassigned » yukare
Category: Feature request » Task

This is fixed in drupal 8, it just created a really big config file. We really need to fix it, The available languages are a cache, not a setting. I Will work on this.

yukare’s picture

Status: Needs work » Closed (outdated)

Since we have drupal 8 now, i do not think pleople will upgrade to drupal 7, so i will close this as outdated.