Hello !
I post this question, because I don’t find how we delete a contact with IManager in PHP.
I had read the documentation of Nextcloud, but it’s doesn’t work
My code :
$contact = $this->contactsManager->search($IDuser, ['UID'], ['types' => true])[0];
$this->contactsManager->delete($contact['UID'], $contact['addressbook-key']);
Do you have the solution ?
With my research, I had found, that function need a ID which is in $contact[‘id’] but this key doesn’t exist ! And I don’t undestand why…
I had tried again with this code :
$isDelete = $this->contactsManager->delete($change, $contact['addressbook-key']);
$isDelete2 = $this->contactsManager->delete($contact, $contact['addressbook-key']);
$isDelete3 = $this->contactsManager->delete($contact['UID'], $contact['addressbook-key']);
$isDelete4 = $this->contactsManager->delete($contact['URI'], $contact['addressbook-key']);
$this->logger->info((string) $isDelete, array('DELETE' => "My DELETE"));
$this->logger->info((string) $isDelete2, array('DELETE' => "My DELETE"));
$this->logger->info((string) $isDelete3, array('DELETE' => "My DELETE"));
$this->logger->info((string) $isDelete4, array('DELETE' => "My DELETE"));
But they return null
I have find a another solution :
$dbDriver = "mysql";
$dbHostname = $this->config->getSystemValue('dbhost');
$dbDatabase = $this->config->getSystemValue('dbname');
$dbUsername = $this->config->getSystemValue('dbuser');
$dbPassword = $this->config->getSystemValue('dbpassword');
$dbPort = $this->config->getSystemValue('3306');
$connection = $this->getConnection($dbDriver, $dbHostname, $dbDatabase, $dbUsername, $dbPassword, $dbPort);
$qdb = $connection->getQueryBuilder();
$qdb->delete('oc_cards')
->where('
uid = :uid
')
->setParameters(array(
':uid' => $utilisateur,
));
$qdb->execute();
private function getConnection($dbDriver, $dbHostname, $dbDatabase, $dbUsername, $dbPassword, $dbPort)
{
if (empty($dbDriver)) {
throw new DatabaseException("No database driver specified.");
}
$connectionFactory = new ConnectionFactory(
\OC::$server->getSystemConfig()
);
$parameters = [
"host" => $dbHostname,
"password" => $dbPassword,
"user" => $dbUsername,
"dbname" => $dbDatabase,
"tablePrefix" => ""
];
$connection = $connectionFactory->getConnection($dbDriver, $parameters);
return $connection;
}