Closed (fixed)
Project:
Syntax Highlighter
Version:
7.x-2.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Jun 2013 at 07:18 UTC
Updated:
20 Jun 2013 at 21:07 UTC
This is a minor issue, but I was getting a message in dblog when a 'manual cron run' was done via /admin/reports/status. The message was The file public://syntaxhighlighter.autoloader.js was not deleted, because it does not exist.
Drupal's file.inc still does not properly deal with deleting unmanaged files in the case that the file does not exist. See Fix support for remote streamwrappers
For the mean time, just checking that the file exists before asking Drupal to delete fixes this annoyance.
<?php
/**
* Create the autoload setup script file. Must call this whenever lib
* location and/or the enable brushes change. Make sure never call this
* if the js lib is not found
*/
function _syntaxhighlighter_setup_autoloader_script() {
$path = 'public://syntaxhighlighter.autoloader.js';
if (variable_get('syntaxhighlighter_use_autoloader', FALSE)) {
// use variable_get() instead of _syntaxhighlighter_get_lib_location()
// because this function is called only if the lib location is found
$script_path = base_path() . variable_get('syntaxhighlighter_lib_location', NULL) . '/scripts/';
$script_data = <<<__HERE__
/*
* This file is generated by the Syntaxhighlighter module
*/
__HERE__;
$script_data .= "\nfunction syntaxhighlighterAutoloaderSetup() {\n SyntaxHighlighter.autoloader(\n";
$need_ending = FALSE;
$brushes = variable_get('syntaxhighlighter_enabled_languages', array('shBrushPhp.js'));
foreach ($brushes as $b) {
if ($b) {
if ($need_ending) {
$script_data .= ",\n";
}
$alias = strtolower(substr(substr($b, 7), 0, -3));
$script_data .= " '$alias $script_path$b'";
$need_ending = TRUE;
}
}
$script_data .= "\n);\n}\n";
file_unmanaged_save_data($script_data, $path, FILE_EXISTS_REPLACE);
}
else {
// check the file exists prior to sending it to be deleted.
if (file_exists($path)) {
file_unmanaged_delete($path);
}
}
}
?>
Comments
Comment #1
fizk commentedFixed. Thanks blasthaus!
http://drupalcode.org/project/syntaxhighlighter.git/commit/ab155c4a05593...