Ejemplo n.º 1
0
 /**
  * Execute import/export tasks using the command-line interface.
  * @param $args Parameters to the plugin
  */
 function executeCLI($scriptName, &$args)
 {
     $command = array_shift($args);
     $xmlFile = array_shift($args);
     $schedConfPath = array_shift($args);
     $flags =& $args;
     $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
     $userDao =& DAORegistry::getDAO('UserDAO');
     $schedConf =& $schedConfDao->getSchedConfByPath($schedConfPath);
     if (!$schedConf) {
         if ($schedConfPath != '') {
             echo Locale::translate('plugins.importexport.users.import.errorsOccurred') . ":\n";
             echo Locale::translate('plugins.importexport.users.unknownSchedConf', array('schedConfPath' => $schedConfPath)) . "\n\n";
         }
         $this->usage($scriptName);
         return;
     }
     switch ($command) {
         case 'import':
             $this->import('UserXMLParser');
             $sendNotify = in_array('send_notify', $flags);
             $continueOnError = in_array('continue_on_error', $flags);
             import('file.FileManager');
             // Import the uploaded file
             $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId());
             $users =& $parser->parseData($xmlFile);
             if (!$parser->importUsers($sendNotify, $continueOnError)) {
                 // Failure.
                 echo Locale::translate('plugins.importexport.users.import.errorsOccurred') . ":\n";
                 foreach ($parser->getErrors() as $error) {
                     echo "\t{$error}\n";
                 }
                 return false;
             }
             // Success.
             echo Locale::translate('plugins.importexport.users.import.usersWereImported') . ":\n";
             foreach ($parser->getImportedUsers() as $user) {
                 echo "\t" . $user->getUserName() . "\n";
             }
             return true;
             break;
         case 'export':
             $this->import('UserExportDom');
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $rolePaths = null;
             if (empty($args)) {
                 $users =& $roleDao->getUsersBySchedConfId($schedConf->getId());
                 $users =& $users->toArray();
             } else {
                 $users = array();
                 $rolePaths = array();
                 foreach ($args as $rolePath) {
                     $roleId = $roleDao->getRoleIdFromPath($rolePath);
                     $thisRoleUsers =& $roleDao->getUsersByRoleId($roleId, $schedConf->getId());
                     foreach ($thisRoleUsers->toArray() as $user) {
                         $users[$user->getId()] = $user;
                     }
                     $rolePaths[] = $rolePath;
                 }
                 $users = array_values($users);
             }
             $doc =& UserExportDom::exportUsers($schedConf, $users, $rolePaths);
             if (($h = fopen($xmlFile, 'wb')) === false) {
                 echo Locale::translate('plugins.importexport.users.export.errorsOccurred') . ":\n";
                 echo Locale::translate('plugins.importexport.users.export.couldNotWriteFile', array('fileName' => $xmlFile)) . "\n";
                 return false;
             }
             fwrite($h, XMLCustomWriter::getXML($doc));
             fclose($h);
             return true;
     }
     $this->usage($scriptName);
 }