1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

Merge pull request #621 from jakobsack/master

Move creation of default address book to backend
This commit is contained in:
LEDfan 2014-12-05 07:45:49 +01:00
commit 95bd2ff182
2 changed files with 18 additions and 16 deletions

View File

@ -105,20 +105,6 @@ class App {
foreach (array_keys(self::$backendClasses) as $backendName) {
$backend = self::getBackend($backendName, $this->user);
$addressBooks = $backend->getAddressBooksForUser();
if ($backendName === 'local' && count($addressBooks) === 0) {
$id = $backend->createAddressBook(array('displayname' => self::$l10n->t('Contacts')));
if ($id !== false) {
$addressBook = $backend->getAddressBook($id);
$addressBooks = array($addressBook);
} else {
\OCP\Util::writeLog(
'contacts',
__METHOD__ . ', Error creating default address book',
\OCP\Util::ERROR
);
}
}
foreach ($addressBooks as $addressBook) {
$addressBook['backend'] = $backendName;

View File

@ -117,6 +117,22 @@ class Database extends AbstractBackend {
$this->addressBooks[$row['id']] = $row;
}
// Create default address book if the list is empty
if (count($this->addressBooks) === 0) {
$l10n = \OCP\Util::getL10N('contacts');
$id = $this->createAddressBook(array('displayname' => $l10n->t('Contacts')));
if ($id !== false) {
$addressBook = $this->getAddressBook($id);
$this->addressBooks[$id] = $addressBook;
} else {
\OCP\Util::writeLog(
'contacts',
__METHOD__ . ', Error creating default address book',
\OCP\Util::ERROR
);
}
}
return $this->addressBooks;
}