public static function markProcessed($id, $relationship, $hash)
 {
     if (!is_string($relationship) || !is_string($hash) || !is_string($id) || !$id || !$hash || !$relationship) {
         $this->raiseError("bad parameters");
         return null;
     }
     if (self::$mark_stmt === null) {
         $db = mdb2::singleton();
         self::$mark_stmt = $db->prepare("INSERT INTO form_relationship_importer (id,relationship,hash) VALUES (?, ?, ?)", array('text', 'text', 'text'), MDB2_PREPARE_MANIP);
         if (I2CE::pearError(self::$mark_stmt, "Could not prepare mark statement")) {
             return null;
         }
     }
     if (!self::$mark_stmt) {
         return null;
     }
     return !I2CE::pearError(self::$mark_stmt->execute(array($id, $relationship, $hash)), "Could not mark processed");
 }
 protected function import($file, $ignore_ids = false)
 {
     $reader = new XMLReader();
     $reader->open($file, null, 1 << 19);
     $save_ids = array();
     $count = 0;
     $exec = array('max_execution_time' => 20 * 60, 'memory_limit' => 256 * 1048576);
     $importer = new I2CE_FormRelationship_Importer();
     if (array_key_exists('HTTP_HOST', $_SERVER)) {
         $importer->setMessageCallback(array($this, 'pushMessage'));
     }
     $defaults = array('ignoreids' => $ignore_ids ? '1' : '0', 'nomatching' => '', 'invalid' => '');
     $next = false;
     while ($next || $reader->read()) {
         $next = false;
         if ($reader->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         switch ($reader->name) {
             case 'relationshipCollection':
                 foreach ($defaults as $key => $val) {
                     if (($v = $reader->getAttribute($key)) !== null) {
                         $defaults[$key] = $v;
                     }
                 }
                 while ($reader->read()) {
                     //skip to a relationship sub-element
                     if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'relationship') {
                         break;
                     }
                 }
                 //break;  - purposefully do not break as we want to get process any relationship under a relationshipCollection
             //break;  - purposefully do not break as we want to get process any relationship under a relationshipCollection
             case 'relationship':
                 I2CE::longExecution($exec);
                 $node = $reader->expand();
                 $doc = new DOMDocument();
                 $i_node = $doc->importNode($node, true);
                 foreach ($defaults as $k => $v) {
                     $i_node->setAttribute($k, $v);
                 }
                 $new_ids = $importer->loadFromXML($i_node);
                 $save_ids = array_merge($save_ids, $new_ids);
                 if (array_key_exists('HTTP_HOST', $_SERVER) && count($new_ids) > 0) {
                     $this->pushMessage("Imported records with ids:\n" . implode(",", $new_ids));
                 }
                 $count++;
                 $reader->next();
                 $next = true;
                 break;
             default:
                 if (array_key_exists('HTTP_HOST', $_SERVER)) {
                     $this->pushError("Unrecognized data type: " . $reader->name);
                 }
                 break;
         }
     }
     $summary = "Import Summary:  (processed {$count} relationships)\n";
     foreach ($save_ids as $save_id => $msg) {
         $summary .= str_replace("\n", "\n  - ", $msg) . "\n";
     }
     I2CE::raiseMessage($summary);
     $this->pushMessage($summary);
     return true;
 }