public static function importCommentsAjax($source, $language, $start = 0) { $response = JCommentsFactory::getAjaxResponse(); require_once dirname(__FILE__) . '/admin.jcomments.migration.php'; $importer = new JCommentsMigrationTool($source, $language, $start); $importer->import(); if ($importer->getStart() == 0 && $importer->getImported() == 0) { // if we couldn't import any items on first step $message = JText::_('A_IMPORT_FAILED'); $response->addScript("jcbackend.showMessage('{$message}', 'info', 'jcomments-message-" . strtolower($source) . "',1);"); $response->addScript("finishCommentsImport('{$source}');"); } else { if ($importer->getImported() == $importer->getTotal()) { $message = JText::sprintf('A_IMPORT_DONE', $importer->getImported()); $response->addScript("jcbackend.showMessage('{$message}', 'info', 'jcomments-message-" . strtolower($source) . "');"); $response->addScript("finishCommentsImport('{$source}');"); } else { if ($importer->getImported() < $importer->getTotal()) { $imported = $importer->getImported(); $total = $importer->getTotal(); $percent = ceil($imported / $total * 100); $message = JText::sprintf('%s %% (%s from %s)', $percent, $imported, $total); $response->addScript("jcbackend.showMessage('{$message}', 'wait', 'jcomments-message-" . strtolower($source) . "');"); $start = $importer->getStart() + $importer->getLimit(); $response->addScript("JCommentsImportCommentsAJAX('{$source}', '{$language}', '{$start}');"); } } } return $response; }