Error running job from dashboard
Permalink
I just started with C5 yesterday so please forgive a lack of knowledge here.
I loaded the Less Compiler addon which adds a block to the Dashboard to "Manage LESS Files". Click that and it brings up a page where it will run the Less compiler to convert them to CSS. When you click the "Compile LESS" button it runs a Job.
Now, in the Job class the executeJobI() method is executed, invoking run() on the derived LessCompile class.
The result from run() is a string.
In executeJob it does this:
$obj = $this->markCompleted($error, $resultMsg);
return $obj;
markCompleted() generates a new stdClass object, populates it with the result and jDateLastRun and other values.
So the result of all of this is a complex object of type stdClass.
Now we go to themes/dashboard/elements/header.php which tries to render the results. The check for if (isset($message)) is true ... in this case $message is that stdClass object. And there the code attempts to display the result of the job run for the user:
echo nl2br(Loader::helper('text')->entities($message))
However, entities() in Concrete5_Helper_Text just calls:
return htmlentities( $v, ENT_COMPAT, APP_CHARSET);
So... the PHP function htmlentities() only accepts a string, not an object. So if you return the results of a Job call you get an error, even if the result was something like "Successful!".
My amateur hack for that, in themes/dashboard/elements/header.php around line 162 I modified the code as follows:
That's not a great solution because the $message may not be of the object type returned from Job. So error or result may not exist, and then another error will be generated. Again, it's a hack, and very temporary.
HTH
I loaded the Less Compiler addon which adds a block to the Dashboard to "Manage LESS Files". Click that and it brings up a page where it will run the Less compiler to convert them to CSS. When you click the "Compile LESS" button it runs a Job.
Now, in the Job class the executeJobI() method is executed, invoking run() on the derived LessCompile class.
The result from run() is a string.
In executeJob it does this:
$obj = $this->markCompleted($error, $resultMsg);
return $obj;
markCompleted() generates a new stdClass object, populates it with the result and jDateLastRun and other values.
So the result of all of this is a complex object of type stdClass.
Now we go to themes/dashboard/elements/header.php which tries to render the results. The check for if (isset($message)) is true ... in this case $message is that stdClass object. And there the code attempts to display the result of the job run for the user:
echo nl2br(Loader::helper('text')->entities($message))
However, entities() in Concrete5_Helper_Text just calls:
return htmlentities( $v, ENT_COMPAT, APP_CHARSET);
So... the PHP function htmlentities() only accepts a string, not an object. So if you return the results of a Job call you get an error, even if the result was something like "Successful!".
My amateur hack for that, in themes/dashboard/elements/header.php around line 162 I modified the code as follows:
if (isset($message)) { if ($message instanceof stdClass) $message = $message->error . ' ' . $message->result; ?>
That's not a great solution because the $message may not be of the object type returned from Job. So error or result may not exist, and then another error will be generated. Again, it's a hack, and very temporary.
HTH
I'm still learning my way around this environment. I posted notes about this issue and others in the LESS Compiler addon forum.
http://www.concrete5.org/marketplace/addons/less-compiler/forums/...
http://www.concrete5.org/marketplace/addons/less-compiler/forums/...
Looks like the issue is in:
packages/less_compiler/controllers/dashboard/less_compiler
file less_files.php
In the compile() method (activated by the button) change:
$this->set("message",$jobObj->executeJob());
to:
$this->set("message",$jobObj->executeJob()->result);
That precludes the need for a core change. I'll notify the author.
Sorry for the trouble, but leaving this for anyone else tripping on it - especially in case another addon does something like this.