Beispiel #1
0
 protected function getDataToImport(UserSettings $userSettings)
 {
     $xmlrpc = new XmlRpc($userSettings->getUsername(), $userSettings->getPassword());
     $result = [];
     try {
         $listEntry = $xmlrpc->phonebookListGet();
         $entryIds = array_map(function (PhonebookListEntry $entry) {
             return $entry->getEntryId();
         }, $listEntry);
         $entries = $xmlrpc->phonebookEntryGet($entryIds);
     } catch (XmlRpcException $e) {
         $this->logError('An XMLRPC exception occurred: %s', $e->getMessage());
         return $result;
     } catch (HttpException $e) {
         $this->logError('Remote backend failed with HTTP status code %d', $e->getCode());
         return $result;
     }
     foreach ($entries as $entry) {
         /** @var PhonebookEntry $entry */
         try {
             $numbers = $entry->getPhoneNumbers($userSettings->getDefaultCountryCode());
             foreach ($numbers as $number) {
                 $result[] = new Item($entry->getEntryId(), $entry->getFullName(), $number);
             }
         } catch (NumberParseException $e) {
             $this->logError('Error parsing phone number for entry #%s (code %d): %s', $entry->getEntryId(), $e->getCode(), $e->getMessage());
         } catch (ParseException $e) {
             $this->logError('Error parsing VCard for entry #%s: %s', $entry->getEntryId(), $e->getMessage());
         }
     }
     return $result;
 }
 protected function insert($userId, HistoryEntry $entry, UserSettings $userSettings)
 {
     /** @var \PDOStatement $stmt */
     try {
         $sql = 'INSERT IGNORE INTO `*PREFIX*sipgate_history` SET userId=:userId, status=:status, tos=:tos, time=:time, localUri=:localUri, remoteUri=:remoteUri, remotePhoneNumber=:remotePhoneNumber, localPhoneNumber=:localPhoneNumber';
         $stmt = $this->db->prepare($sql);
         $stmt->bindValue(':userId', $userId, \PDO::PARAM_STR);
         $stmt->bindValue(':status', $entry->getStatus(), \PDO::PARAM_STR);
         $stmt->bindValue(':tos', $entry->getTypeOfService(), \PDO::PARAM_STR);
         $stmt->bindValue(':time', $entry->getTime()->format('Y-m-d H:i:s'), \PDO::PARAM_STR);
         $stmt->bindValue(':localUri', $entry->getLocalUri(), \PDO::PARAM_STR);
         $stmt->bindValue(':remoteUri', $entry->getRemoteUri(), \PDO::PARAM_STR);
         $stmt->bindValue(':remotePhoneNumber', $entry->getRemotePhoneNumber($userSettings->getDefaultCountryCode()), \PDO::PARAM_STR);
         $stmt->bindValue(':localPhoneNumber', $entry->getLocalPhoneNumber($userSettings->getDefaultCountryCode()), \PDO::PARAM_STR);
         $stmt->execute();
         return $stmt->rowCount();
     } catch (DbException $e) {
         $this->logger->error('Error inserting into database: %s', $e->getMessage());
     }
 }
Beispiel #3
0
 protected function getDataToImport(UserSettings $userSettings)
 {
     /** @var \PDOStatement $stmt */
     $sql = 'SELECT c.id AS externalId, c.fullname AS name, p.value AS phoneNumber ' . 'FROM `*PREFIX*contacts_cards_properties` p ' . 'JOIN `*PREFIX*contacts_cards` c ON p.contactid = c.id ' . 'WHERE p.userid = :userId AND p.name = :name';
     $stmt = $this->db->prepare($sql);
     $stmt->bindValue(':userId', $userSettings->getUserId(), \PDO::PARAM_STR);
     $stmt->bindValue(':name', 'TEL', \PDO::PARAM_STR);
     $stmt->execute();
     $rows = $stmt->fetchAll(\PDO::FETCH_OBJ);
     $result = [];
     foreach ($rows as $row) {
         $normalizedNumber = $this->normalizePhoneNumber($row->phoneNumber, $row->externalId, $userSettings->getDefaultCountryCode());
         if ($normalizedNumber !== null) {
             $result[] = new Item($row->externalId, $row->name, $normalizedNumber);
         }
     }
     return $result;
 }