Skip to content

Commit af9077b

Browse files
Merge pull request #55146 from nextcloud/backport/54736/stable32
[stable32] fix: always use english name for recently contacted category
2 parents 7415f7f + ca4dd9e commit af9077b

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

apps/contactsinteraction/appinfo/info.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<name>Contacts Interaction</name>
1010
<summary>Manages interaction between accounts and contacts</summary>
1111
<description>Collect data about accounts and contacts interactions and provide an address book for the data</description>
12-
<version>1.13.0</version>
12+
<version>1.13.1</version>
1313
<licence>agpl</licence>
1414
<author>Christoph Wurst</author>
1515
<author homepage="https://github.com/nextcloud/groupware">Nextcloud Groupware Team</author>
@@ -26,6 +26,11 @@
2626
<background-jobs>
2727
<job>OCA\ContactsInteraction\BackgroundJob\CleanupJob</job>
2828
</background-jobs>
29+
<repair-steps>
30+
<live-migration>
31+
<step>OCA\ContactsInteraction\Migration\FixVcardCategory</step>
32+
</live-migration>
33+
</repair-steps>
2934
<sabre>
3035
<address-book-plugins>
3136
<plugin>OCA\ContactsInteraction\AddressBookProvider</plugin>

apps/contactsinteraction/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => $baseDir . '/../lib/Db/RecentContactMapper.php',
1818
'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => $baseDir . '/../lib/Listeners/ContactInteractionListener.php',
1919
'OCA\\ContactsInteraction\\Listeners\\UserDeletedListener' => $baseDir . '/../lib/Listeners/UserDeletedListener.php',
20+
'OCA\\ContactsInteraction\\Migration\\FixVcardCategory' => $baseDir . '/../lib/Migration/FixVcardCategory.php',
2021
'OCA\\ContactsInteraction\\Migration\\Version010000Date20200304152605' => $baseDir . '/../lib/Migration/Version010000Date20200304152605.php',
2122
);

apps/contactsinteraction/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ComposerStaticInitContactsInteraction
3232
'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => __DIR__ . '/..' . '/../lib/Db/RecentContactMapper.php',
3333
'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listeners/ContactInteractionListener.php',
3434
'OCA\\ContactsInteraction\\Listeners\\UserDeletedListener' => __DIR__ . '/..' . '/../lib/Listeners/UserDeletedListener.php',
35+
'OCA\\ContactsInteraction\\Migration\\FixVcardCategory' => __DIR__ . '/..' . '/../lib/Migration/FixVcardCategory.php',
3536
'OCA\\ContactsInteraction\\Migration\\Version010000Date20200304152605' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20200304152605.php',
3637
);
3738

apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ private function generateCard(RecentContact $contact): string {
117117
$props = [
118118
'URI' => UUIDUtil::getUUID(),
119119
'FN' => $this->getDisplayName($contact->getUid()) ?? $contact->getEmail() ?? $contact->getFederatedCloudId(),
120-
'CATEGORIES' => $this->l10n->t('Recently contacted'),
120+
// Recently contacted not translated on purpose: https://github.com/nextcloud/contacts/issues/4663
121+
'CATEGORIES' => 'Recently contacted',
121122
];
122123

123124
if ($contact->getEmail() !== null) {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\ContactsInteraction\Migration;
11+
12+
use OC\Migration\BackgroundRepair;
13+
use OCA\ContactsInteraction\AppInfo\Application;
14+
use OCP\BackgroundJob\IJobList;
15+
use OCP\IDBConnection;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\IRepairStep;
18+
use Sabre\VObject\ParseException;
19+
use Sabre\VObject\Reader;
20+
21+
class FixVcardCategory implements IRepairStep {
22+
23+
private const CARDS_PER_BATCH = 5000;
24+
25+
public function __construct(
26+
private readonly IDBConnection $connection,
27+
private readonly IJobList $jobList,
28+
) {
29+
}
30+
31+
public function getName(): string {
32+
return 'Fix category of recent contacts vcards';
33+
}
34+
35+
public function run(IOutput $output): void {
36+
$query = $this->connection->getQueryBuilder();
37+
38+
$cardsWithTranslatedCategory = $query->select(['id', 'card'])
39+
->from('recent_contact')
40+
->where($query->expr()->notLike(
41+
'card',
42+
$query->createNamedParameter('%CATEGORIES:Recently contacted%')
43+
))
44+
->setMaxResults(self::CARDS_PER_BATCH)
45+
->executeQuery();
46+
$rowCount = $cardsWithTranslatedCategory->rowCount();
47+
48+
$output->startProgress($rowCount);
49+
50+
$this->connection->beginTransaction();
51+
52+
$updateQuery = $query->update('recent_contact')
53+
->set('card', $query->createParameter('card'))
54+
->where($query->expr()->eq('id', $query->createParameter('id')));
55+
56+
while ($card = $cardsWithTranslatedCategory->fetch()) {
57+
$output->advance(1);
58+
59+
try {
60+
$vcard = Reader::read($card['card']);
61+
} catch (ParseException $e) {
62+
$output->info('Could not parse vcard with id ' . $card['id']);
63+
continue;
64+
}
65+
66+
$vcard->remove('CATEGORIES');
67+
$vcard->add('CATEGORIES', 'Recently contacted');
68+
69+
$updateQuery->setParameter('id', $card['id']);
70+
$updateQuery->setParameter('card', $vcard->serialize());
71+
$updateQuery->executeStatement();
72+
}
73+
74+
$this->connection->commit();
75+
76+
$cardsWithTranslatedCategory->closeCursor();
77+
78+
$output->finishProgress();
79+
80+
if ($rowCount === self::CARDS_PER_BATCH) {
81+
$this->jobList->add(BackgroundRepair::class, [
82+
'app' => Application::APP_ID,
83+
'step' => FixVcardCategory::class,
84+
'reschedule' => time(), // Use a different argument to reschedule the job
85+
]);
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)