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

Move creation of default address book to backend

Fixes owncloud/contacts#513
This commit is contained in:
Jakob Sack 2014-08-29 15:18:11 +02:00
parent dc33a738e9
commit 026fb01af3
2 changed files with 16 additions and 14 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 = array($addressBook);
} else {
\OCP\Util::writeLog(
'contacts',
__METHOD__ . ', Error creating default address book',
\OCP\Util::ERROR
);
}
}
return $this->addressBooks;
}