Exemplo n.º 1
0
 private function RemovePendingOperationForResp($resp)
 {
     // This situation occurs when registry module implements server poll
     // We have response from server and don't know about operation.
     // So try to find it and remove
     $opinfo = self::$RespOperationMap[get_class($resp)];
     if (!$opinfo) {
         return;
     }
     list($object_type, $op_type) = $opinfo;
     // Try to find operation in database
     if ($object_type == self::OBJ_DOMAIN) {
         $parsed_host = FQDN::Parse($resp->HostName);
         $object_id = $this->DBDomain->FindByName($parsed_host[0], $parsed_host[1]);
         if (!$object_id) {
             return;
         }
     } else {
         if ($object_type == self::OBJ_CONTACT) {
             $object_id = $this->DBContact->FindByCLID($resp->CLID);
             if (!$object_id) {
                 return;
             }
         } else {
             return;
         }
     }
     $this->DB->Execute('DELETE FROM pending_operations WHERE objectid = ? AND operation = ? AND objecttype = ?', array($object_id, $op_type, $object_type));
 }
Exemplo n.º 2
0
 function import()
 {
     $module = strtolower($this->module);
     if ($module == "dotnl") {
         $parser = new DotNLParser();
         $registry = $this->registryFactory->GetRegistryByName('DotNL');
     } else {
         if ($module == "rrpproxy") {
             $parser = new RRPProxyParser();
             $registry = $this->registryFactory->GetRegistryByName('RRPProxy');
         }
     }
     if ($parser == null) {
         throw new Exception("Cannot find line parser for module '{$module}'");
     }
     // Import process
     $fp = $this->fopen($this->in);
     $headers = $this->fgetcsv($fp);
     for ($lineno = 1; !feof($fp); $lineno++) {
         $line = $this->fgetcsv($fp);
         $line = array_combine($headers, array_map('trim', $line));
         try {
             $parseResult = $parser->parseLine($line);
             if (!$parseResult) {
                 continue;
             }
         } catch (Exception $e) {
             print "Cannot parse line {$lineno}\n";
             continue;
         }
         if ($this->dbContact->FindByCLID($parseResult['clid'])) {
             // Skip existing in database
             print "[{$parseResult['clid']}] Skipped. Already exists in database.\n";
             continue;
         }
         // Construct contact
         $contact = $registry->NewContactInstanceByGroup($parseResult['group']);
         $contact->CLID = $parseResult['clid'];
         $contact->UserID = $this->userid;
         try {
             $contact->SetFieldList($parseResult['fields'], 1);
         } catch (ErrorList $e) {
             print "[{$contact->CLID}] Contact data violates manifest rules. " . join("; ", $e->GetAllMessages()) . "\n";
             print "[{$contact->CLID}] Set non strict mode\n";
             $contact->SetFieldList($parseResult['fields'], 0);
         }
         // Save contact
         try {
             $this->dbContact->Save($contact);
             print "[{$contact->CLID}] Imported\n";
         } catch (Exception $e) {
             print "[{$contact->CLID}] Cannot save. {$e->getMessage()}\n";
         }
     }
     fclose($fp);
 }