
var topic = '/goodnewsimport/';
var register = 'mgr';
...
...
...
if (this.console == null || this.console == undefined) {
this.console = MODx.load({
xtype: 'modx-console'
,register: register
,topic: topic
,show_filename: 0
,listeners: {
'shutdown': {fn:function() {
//reload CMP to reset fields
//location.href = MODx.config.manager_url + '?a=' + MODx.request.a + '&action=import';
}
,scope:this}
}
});
} else {
this.console.setRegister(register,topic);
}
this.console.show(Ext.getBody());
...
...
...
this.getForm().submit({
url: GoodNews.config.connectorUrl
,params: {
action: 'mgr/subscribers/import'
,register: register
,topic: topic
}
,success: function(form,action){
if(action.result.success){
this.console.fireEvent('complete');
}
}
,failure: function(result,request) {
this.console.fireEvent('complete');
}
,scope: this
});
This question has been answered by markh. See the first response.
Are you certain the order is "random"? It could be that some messages are being delayed until the end of a process and are not being written in the "expected" order... Or perhaps you are sending messages with keys that define the order, overriding normal timestamps + sequences that would be given to the messages?
public function process() {
$error = false;
$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('goodnews.import_subscribers_log_prep_csv_import'));
sleep(1);
if (!($this->goodnewsimportsubscribers instanceof GoodNewsImportSubscribers)) {
$this->modx->log(modX::LOG_LEVEL_FATAL, $this->modx->lexicon('goodnews.import_subscribers_log_no_class'));
$error = true;
}
// Make sure a csv file was specified ($csvfile is an array!)
$csvfile = $this->getProperty('csvfile');
if (empty($csvfile['name'])) {
$this->addFieldError('csvfile', $this->modx->lexicon('goodnews.import_subscribers_log_ns_csvfile'));
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_log_ns_csvfile'));
sleep(1);
} elseif (!$this->goodnewsimportsubscribers->csvMimeType($csvfile['type'])) {
$this->addFieldError('csvfile', $this->modx->lexicon('goodnews.import_subscribers_log_wrong_filetype'));
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_log_wrong_filetype'));
sleep(1);
}
// Make sure a batchsize was specified
$batchsize = $this->getProperty('batchsize');
if (empty($batchsize) && !is_numeric($batchsize)) {
$this->addFieldError('batchsize', $this->modx->lexicon('goodnews.import_subscribers_log_ns_batchsize'));
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_log_ns_batchsize'));
sleep(1);
}
...
...
...
// Only continue with processing if no errors occured
if ($error || $this->hasErrors()) {
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_log_failed'));
sleep(1);
unset($this->goodnewsimportsubscribers);
return $this->failure();
}
$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('goodnews.import_subscribers_log_importing_csv').' '.$csvfile['name']);
sleep(1);
// Initialize the GoodNewsImportSubscribers object
if ($this->goodnewsimportsubscribers->init($csvfile['tmp_name'], $delimiter, $enclosure) == false) {
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_err_open_csvfile'));
sleep(1);
$error = true;
}
// Only continue with processing if no errors occured
if ($error) {
unset($this->goodnewsimportsubscribers);
$this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('goodnews.import_subscribers_log_failed'));
sleep(1);
return $this->failure();
}
// The importUsers method of the GoodNewsImportSubscribers class holds the
// foreach loop, which writes valid users to the database
// + it also sends a proper log message for each imported (or not imported) user
$count = $this->goodnewsimportsubscribers->importUsers($batchsize, $groups, $categories);
unset($this->goodnewsimportsubscribers);
// Especially this last log message almost never is shown in the MODExt console window!
// Instead it is written to the console as the first message when I start a complete new import.
$this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('goodnews.import_subscribers_log_finished').$count);
sleep(1);
return $this->success();
}
<?php return array ( 'timestamp' => '2013-12-26 14:55:11', 'level' => 'INFO', 'msg' => 'Import finished. Successfully imported subscribers: 0', 'def' => '', 'file' => '/modxdev/goodnews/assets/components/goodnews/connector.php', 'line' => '', );
What is the filename of the message there in the registry?
<?php return array ( 'timestamp' => '2013-12-26 16:17:27', 'level' => 'INFO', 'msg' => 'Import finished. Successfully imported subscribers: 0', 'def' => '', 'file' => '/modxdev/goodnews/assets/components/goodnews/connector.php', 'line' => '', );
Are you only retrieving a single message? I'm not sure what is happening without being able to run the code...
I assume you have a different action checking status messages from the one that is running the import?
...
I have increased the sleep time after the last log message in the process method (line 72 of the above code) to 2 seconds and now it seems to work!
If I leave it at 1 second it sometimes works. If I remove the sleep completely, the console output goes crazy and many .msg.php messages remain in the cache/registry/... folder.
Seems to be a timing issue!?