if (!isset($arguments['i'])) { usage(); } else { $archive_path = $arguments['i']; } if (!isset($arguments['m'])) { usage(); } else { $mapping_path = $arguments['m']; } $user_manager = UserManager::instance(); $security = new XML_Security(); $xml_validator = new XML_RNGValidator(); $transformer = new User\XML\Import\MappingFileOptimusPrimeTransformer($user_manager); $logger = new ProjectXMLImporterLogger(); $builder = new User\XML\Import\UsersToBeImportedCollectionBuilder($user_manager, $logger, $security, $xml_validator); $console = new Log_ConsoleLogger(); try { $user = $user_manager->forceLogin($username); if (!$user->isSuperUser() && !$user->isAdmin($project_id) || !$user->isActive()) { throw new RuntimeException($GLOBALS['Language']->getText('project_import', 'invalid_user', array($username))); } $archive = new ZipArchive(); if ($archive->open($archive_path) !== true) { $console->error("Unable to open archive {$archive_path}"); exit(1); } $collection_from_archive = $builder->buildFromArchive($archive); $users_collection = $transformer->transform($collection_from_archive, $mapping_path); $users_collection->process($user_manager, $console); $user_finder = new User\XML\Import\Mapping($user_manager, $users_collection, $logger);
if (!isset($arguments['o'])) { usage(); } else { $output = $arguments['o']; } if (!isset($arguments['i'])) { usage(); } else { $archive_path = $arguments['i']; } $security = new XML_Security(); $xml_validator = new XML_RNGValidator(); $user_manager = UserManager::instance(); $logger = new ProjectXMLImporterLogger(); $console = new Log_ConsoleLogger(); $builder = new User\XML\Import\UsersToBeImportedCollectionBuilder($user_manager, $logger, $security, $xml_validator); try { $user = $user_manager->forceLogin($username); if (!$user->isActive() || !$user->isSuperUser()) { throw new RuntimeException("User {$username} must be site administrator"); } if (is_dir($archive_path)) { $archive = new Import\DirectoryArchive($archive_path); } else { $archive = new Import\ZipArchive($archive_path, ForgeConfig::get('tmp_dir')); } $collection = $builder->buildFromArchive($archive); $collection->toCSV($output); exit(0); } catch (XML_ParseException $exception) { foreach ($exception->getErrors() as $parse_error) {