示例#1
0
 function handleForm(&$form_values)
 {
     $errorMessage = NULL;
     module_load_include('php', 'Fedora_Repository', 'CollectionClass');
     module_load_include('php', 'Fedora_Repository', 'ContentModel');
     module_load_include('php', 'fedora_repository', 'api/fedora_item');
     $content_model_pid = ContentModel::getPidFromIdentifier($form_values['models']);
     $content_model_dsid = ContentModel::getDSIDFromIdentifier($form_values['models']);
     $collectionHelper = new CollectionClass();
     $startTime = time();
     $collection_pid = $form_values['collection_pid'];
     $this->parse_refworks_item($form_values);
     $this->security_helper = new SecurityClass();
     $collection_item = new Fedora_Item($collection_pid);
     $this->collection_policy_stream = $collection_item->get_datastream_dissemination('CHILD_SECURITY');
     if (empty($this->collection_policy_stream)) {
         $this->collection_policy_stream = file_get_contents(drupal_get_path('module', 'fedora_repository') . '/policies/noObjectEditPolicy.xml');
     }
     $success = 0;
     $errors = 0;
     foreach ($this->referencelist as $reference) {
         $dom = new DomDocument("1.0", "UTF-8");
         $dom->substituteEntities = FALSE;
         $dom->formatOutput = true;
         $pid = $collectionHelper->getNextPid($collection_pid, $content_model_dsid);
         $rootElement = $dom->createElement("foxml:digitalObject");
         $rootElement->setAttribute('VERSION', '1.1');
         $rootElement->setAttribute('PID', "{$pid}");
         $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#");
         $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
         $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd");
         $dom->appendChild($rootElement);
         //create standard fedora stuff
         $qdc_element = $this->createQDCStream($dom, $rootElement, $reference);
         if (!$qdc_element) {
             drupal_set_message(t('Error Create DC for Refworks'), 'error');
             continue;
         }
         $item_title = '';
         foreach ($reference->t1 as $value) {
             $item_title .= ' --- ' . $value;
         }
         $this->createStandardFedoraStuff($form_values, $dom, $rootElement, $reference);
         $rootElement->appendChild($qdc_element);
         //create relationships
         $this->createRelationShips($form_values, $dom, $rootElement, $pid);
         //create dublin core
         $this->createFedoraDataStreams($form_values, $dom, $rootElement, $reference);
         if (!empty($this->collection_policy_stream)) {
             $this->create_security_policies($dom, $rootElement, $reference);
         }
         $params = array('objectXML' => $dom->saveXML(), 'format' => 'info:fedora/fedora-system:FOXML-1.1', 'logMessage' => "Fedora Object Ingested");
         try {
             $soapHelper = new ConnectionHelper();
             $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl'));
             if ($client == null) {
                 drupal_set_message(t('Error Getting Soap Client.'), 'error');
                 watchdog(t("FEDORA_REPOSITORY"), t("Error Getting SOAP client") . $e, null, WATCHDOG_ERROR);
                 return;
             }
             $object = $client->__soapCall('ingest', array($params));
             watchdog(t("FEDORA_REPOSITORY"), t("Successfully added repository item ") . $pid . ' - ' . $item_title, null, WATCHDOG_INFO);
             $deleteFiles = $form_values['delete_file'];
             //remove files from drupal file system
             if ($deleteFiles > 0) {
                 unlink($form_values['fullpath']);
             }
         } catch (exception $e) {
             $errors++;
             $errorMessage = 'yes';
             //drupal_set_message(t('Error Ingesting Object! Check Drupal watchdog logs for more info' . $e->getMessage()), 'error');
             watchdog(t("FEDORA_REPOSITORY"), t("Error during ingest") . $item_title . ' ' . $e, null, WATCHDOG_ERROR);
             //return ' ';
         }
         $success++;
     }
     if (isset($errorMessage)) {
         drupal_set_message(t('Error Ingesting one or more records! Check Drupal watchdog logs for more info'), 'error');
     }
     $endTime = time();
     drupal_set_message(t('Successfull ingest of %success records.  %errors records failed.  Ingest took %seconds seconds', array('%success' => $success - $errors, '%errors' => $errors, '%seconds' => $endTime - $startTime)), 'info');
     //drupal_set_message(t('ingest took %seconds ',array('%seconds'=>$endTime-$startTime)),'info');
 }