예제 #1
0
파일: import.php 프로젝트: nxc/nxc_import
        unset($filterAttributes[$key]);
    }
}
$importConfig = new $options['arguments'][0]();
if ($importConfig->getContentClass() instanceof eZContentClass === false) {
    $cli->error('Import config hasn`t a valid content class');
    $script->shutdown(1);
}
if ($importConfig instanceof nxcImportConfig === false) {
    $cli->error('Class "' . $options['arguments'][0] . '" isn`t a valid import config');
    $script->shutdown(1);
}
if (count($filterAttributes) > 0) {
    $importConfig->setFilterAttributes($filterAttributes);
}
$importController = new nxcImportController($importConfig, $cli);
$importController->log('Starting import for ' . $importConfig, array('blue'));
$startTime = microtime(true);
$importController->run($remove, $useStateHashes, $update, $create);
$executionTime = round(microtime(true) - $startTime, 2);
$importController->log('Import took ' . $executionTime . ' secs.');
$importController->log('Created ' . $importController->counter['create'] . ' objects, updated ' . $importController->counter['update'] . ' objects, skiped ' . $importController->counter['skip'] . ' object.');
$importController->log('Available objects in feed: ' . count($importController->config->dataList) . '.');
if ($importController->counter['create'] + $importController->counter['update'] > 0) {
    $speed = round(($importController->counter['create'] + $importController->counter['update']) / $executionTime, 2);
    $importController->log('Average speed: ' . $speed . ' objects/sec.');
}
if ($importController->counter['remove'] > 0) {
    $importController->log($importController->counter['remove'] . ' objects was removed');
}
unset($importController);
예제 #2
0
파일: import.php 프로젝트: nxc/nxc_import
$config = null;
$errors = array();
$counter = array();
if ($http->hasVariable('ImportButton')) {
    $config = nxcCSVImportDBConfig::fetch((int) $http->variable('config_id'));
    if ($config instanceof nxcCSVImportDBConfig === false) {
        $errors[] = ezpI18n::tr('extension/nxc_import', 'Please select Import Configuration');
    }
    $allowedMimeTypes = array('text/csv', 'text/plain', 'application/csv', 'text/comma-separated-values', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext', 'application/octet-stream', 'application/txt');
    $file = $_FILES['file'];
    if (empty($file['name']) || in_array($file['type'], $allowedMimeTypes) === false) {
        $errors[] = ezpI18n::tr('extension/nxc_import', 'Please upload valid CSV file');
    }
    if (count($errors) === 0) {
        $importConfig = new nxcImportDatabaseCSVConfig();
        $importConfig->setConfig($config);
        $importConfig->setSource($file['tmp_name']);
        $controller = new nxcImportController($importConfig, false, false);
        $controller->run(false, false, true, true);
        $counter = $controller->counter;
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('configs', $configs);
$tpl->setVariable('selected_config', $config);
$tpl->setVariable('errors', $errors);
$tpl->setVariable('counter', $counter);
$Result = array();
$Result['content'] = $tpl->fetch('design:csv_import/config/import.tpl');
$Result['left_menu'] = 'design:csv_import/menu.tpl';
$Result['path'] = array(array('text' => ezpI18n::tr('extension/nxc_import', 'CSV Import'), 'url' => false));