So I’ve been struggling with a problem for a couple days now, in which $modx->runProcessor seemed to break my Registry (a custom log so to speak) which works with $modx->log().
This is what I was doing:
logConsole('info','before processor');
$response = $modx->runProcessor('resource/create',$line);
logConsole('info','after processor');
This is my logConsole function that uses $modx->log():
function logConsole($type,$msg) {
global $modx;
switch ($type) {
case 'error':
sleep(1);
$modx->log(modX::LOG_LEVEL_ERROR,'FATAL ERROR: '.$msg);
sleep(2);
$modx->log(modX::LOG_LEVEL_INFO,'COMPLETED');
sleep(1);
return $modx->error->failure($msg); // Die to prevent the process to go on anyway!
break;
default:
case 'info':
$modx->log(modX::LOG_LEVEL_INFO,$msg);
//return true;
break;
case 'warn':
$modx->log(modX::LOG_LEVEL_WARN,$msg);
return true;
break;
}
}
I know the function worked, cause everything I logged with it showed up in the registry (and thus in my console), until I ended up with $modx->runProcessor. Not a single log entry would show up after that.
After digging into the code of the resource/create processor and finding nothing that linked it to the log, I went a step back and checked out the main connector (connectors/index.php) which would be handling the request. Turned out that it is setting some logging variables for the process..
/* set debugging/logging options */
$modx->setDebug(E_ALL | E_STRICT);
$modx->setLogLevel(modX::LOG_LEVEL_ERROR);
$modx->setLogTarget('FILE');
While the registry would be set up automatically by the request handler (I guess - it just works), it is probably instantiating these variables differently to point to the right file to return the information to my console. And now the connector is overwriting that. I tested it by setting the log level in the connector to use INFO and up, and those messages were appearing in the error log instead of on my screen.
After spending some time trying to nullify the connectors behavior in my own script I ended up commenting the above mentioned three lines. And then my script started working as intended.
Now my question is whether this is a bug or not. From my point of view, trying to get direct feedback in my CMP, this seems like a bug. But what would happen if those three lines are not there for other processors to use? I assume there’s a default set somewhere, so is it needed in the connector? Shouldn’t it check for existing values before overwriting them? Am I just goofing up? My complete code for this is on Github:
https://github.com/Mark-H/importX