]> git.mxchange.org Git - friendica.git/blob - src/Worker/MergeContact.php
Merge pull request #7851 from annando/mail-header
[friendica.git] / src / Worker / MergeContact.php
1 <?php
2
3 /**
4  * @file src/Worker/MergeContact.php
5  */
6
7 namespace Friendica\Worker;
8
9 use Friendica\Core\Logger;
10 use Friendica\Database\DBA;
11
12 class MergeContact
13 {
14         public static function execute($first, $dup_id, $uid)
15         {
16                 if (empty($first) || empty($dup_id) || ($first == $dup_id)) {
17                         // Invalid request
18                         return;
19                 }
20
21                 Logger::info('Handling duplicate', ['search' => $dup_id, 'replace' => $first]);
22
23                 // Search and replace
24                 DBA::update('item', ['contact-id' => $first], ['contact-id' => $dup_id]);
25                 DBA::update('thread', ['contact-id' => $first], ['contact-id' => $dup_id]);
26                 DBA::update('mail', ['contact-id' => $first], ['contact-id' => $dup_id]);
27                 DBA::update('photo', ['contact-id' => $first], ['contact-id' => $dup_id]);
28                 DBA::update('event', ['cid' => $first], ['cid' => $dup_id]);
29                 if ($uid == 0) {
30                         DBA::update('item', ['author-id' => $first], ['author-id' => $dup_id]);
31                         DBA::update('item', ['owner-id' => $first], ['owner-id' => $dup_id]);
32                         DBA::update('thread', ['author-id' => $first], ['author-id' => $dup_id]);
33                         DBA::update('thread', ['owner-id' => $first], ['owner-id' => $dup_id]);
34                 } else {
35                         /// @todo Check if some other data needs to be adjusted as well, possibly the "rel" status?
36                 }
37
38                 // Remove the duplicate
39                 DBA::delete('contact', ['id' => $dup_id]);
40         }
41 }