Skip to content

Commit

Permalink
use integer ids for external contacts and skip storing them as local …
Browse files Browse the repository at this point in the history
…contacts
  • Loading branch information
kroky committed Feb 16, 2024
1 parent c82ad65 commit 82a381d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/contacts/hm-contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public function init($user_config, $session) {
}

public static function save() {
$local_contacts = array_map(function($c) { $c->update('type', 'local'); return $c->export(); }, self::$entities);
$local_contacts = array_map(function($c) {
$c->update('type', 'local');
return $c->export();
}, array_filter(self::$entities, function($c) {
return ! $c->value('external');
}));
self::$user_config->set(self::$name, $local_contacts);
self::$session->set('user_data', self::$user_config->dump());
}
Expand Down Expand Up @@ -124,6 +129,10 @@ public function export($source = 'local') {

public function import($data) {
foreach ($data as $contact) {
if (! isset($contact['id'])) {
$contact['id'] = self::count();
}
$contact['external'] = true;
$contact = new Hm_Contact($contact);
self::add($contact, false);
}
Expand Down

0 comments on commit 82a381d

Please sign in to comment.