1
0
Fork 0

update for user-contact is added

This commit is contained in:
Michael 2021-09-10 20:22:24 +00:00
parent 9c14eb0c6b
commit 2486c8031b
2 changed files with 44 additions and 1 deletions

View file

@ -221,7 +221,10 @@ class Contact
public static function update(array $fields, array $condition, $old_fields = [])
{
$ret = DBA::update('contact', $fields, $condition, $old_fields);
// @todo Apply changes to the "user-contact" table on dedicated fields
// Apply changes to the "user-contact" table on dedicated fields
Contact\User::UpdateByContactUpdate($fields, $condition);
return $ret;
}

View file

@ -21,12 +21,15 @@
namespace Friendica\Model\Contact;
use Exception;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Model\Contact;
use Friendica\Model\ItemURI;
use PDOException;
/**
* This class provides information about user related contacts based on the "user-contact" table.
@ -71,6 +74,43 @@ class User
return $ret;
}
/**
* Apply changes from contact update data to user-contact table
*
* @param array $fields
* @param array $condition
* @return void
* @throws PDOException
* @throws Exception
*/
public static function UpdateByContactUpdate(array $fields, array $condition)
{
DBA::transaction();
unset($fields['uid']);
unset($fields['cid']);
unset($fields['uri-id']);
if (isset($fields['readonly'])) {
$fields['ignored'] = $fields['readonly'];
}
$update_fields = DBStructure::getFieldsForTable('user-contact', $fields);
if (!empty($update_fields)) {
$contacts = DBA::select('contact', ['uri-id', 'uid'], $condition);
while ($row = DBA::fetch($contacts)) {
if (empty($row['uri-id'])) {
continue;
}
$ret = DBA::update('user-contact', $update_fields, ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
Logger::info('Updated user contact', ['uid' => $row['uid'], 'uri-id' => $row['uri-id'], 'ret' => $ret]);
}
DBA::close($contacts);
}
DBA::commit();
}
/**
* Block contact id for user id
*