Fix bad unique constraints in Mysql table user_has_notifications
This commit is contained in:
@@ -117,23 +117,20 @@ class UserNotification extends Base
|
||||
*/
|
||||
public function saveSettings($user_id, array $values)
|
||||
{
|
||||
$this->db->startTransaction();
|
||||
$types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']);
|
||||
|
||||
if (isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1) {
|
||||
if (! empty($types)) {
|
||||
$this->enableNotification($user_id);
|
||||
|
||||
$filter = empty($values['notifications_filter']) ? UserNotificationFilter::FILTER_BOTH : $values['notifications_filter'];
|
||||
$projects = empty($values['notification_projects']) ? array() : array_keys($values['notification_projects']);
|
||||
$types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']);
|
||||
|
||||
$this->userNotificationFilter->saveFilter($user_id, $filter);
|
||||
$this->userNotificationFilter->saveSelectedProjects($user_id, $projects);
|
||||
$this->userNotificationType->saveSelectedTypes($user_id, $types);
|
||||
} else {
|
||||
$this->disableNotification($user_id);
|
||||
}
|
||||
|
||||
$this->db->closeTransaction();
|
||||
$filter = empty($values['notifications_filter']) ? UserNotificationFilter::FILTER_BOTH : $values['notifications_filter'];
|
||||
$project_ids = empty($values['notification_projects']) ? array() : array_keys($values['notification_projects']);
|
||||
|
||||
$this->userNotificationFilter->saveFilter($user_id, $filter);
|
||||
$this->userNotificationFilter->saveSelectedProjects($user_id, $project_ids);
|
||||
$this->userNotificationType->saveSelectedTypes($user_id, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,10 +61,11 @@ class UserNotificationFilter extends Base
|
||||
* @access public
|
||||
* @param integer $user_id
|
||||
* @param string $filter
|
||||
* @return boolean
|
||||
*/
|
||||
public function saveFilter($user_id, $filter)
|
||||
{
|
||||
$this->db->table(User::TABLE)->eq('id', $user_id)->update(array(
|
||||
return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array(
|
||||
'notifications_filter' => $filter,
|
||||
));
|
||||
}
|
||||
@@ -87,17 +88,21 @@ class UserNotificationFilter extends Base
|
||||
* @access public
|
||||
* @param integer $user_id
|
||||
* @param integer[] $project_ids
|
||||
* @return boolean
|
||||
*/
|
||||
public function saveSelectedProjects($user_id, array $project_ids)
|
||||
{
|
||||
$results = array();
|
||||
$this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove();
|
||||
|
||||
foreach ($project_ids as $project_id) {
|
||||
$this->db->table(self::PROJECT_TABLE)->insert(array(
|
||||
$results[] = $this->db->table(self::PROJECT_TABLE)->insert(array(
|
||||
'user_id' => $user_id,
|
||||
'project_id' => $project_id,
|
||||
));
|
||||
}
|
||||
|
||||
return !in_array(false, $results, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user