Fix bad unique constraints in Mysql table user_has_notifications
This commit is contained in:
@@ -9,6 +9,7 @@ New features:
|
|||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
* Improve notification configuration form
|
||||||
* Handle state in OAuth2 client
|
* Handle state in OAuth2 client
|
||||||
* Allow to use the original template in overridden templates
|
* Allow to use the original template in overridden templates
|
||||||
* Unification of the project header
|
* Unification of the project header
|
||||||
@@ -30,6 +31,7 @@ Improvements:
|
|||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
|
* Fix bad unique constraints in Mysql table user_has_notifications
|
||||||
* Force integer type for aggregated metrics (Burndown chart concat values instead of summing)
|
* Force integer type for aggregated metrics (Burndown chart concat values instead of summing)
|
||||||
* Fixes cycle time calculation when the start date is defined in the future
|
* Fixes cycle time calculation when the start date is defined in the future
|
||||||
* Access allowed to any tasks from the shared public board by changing the URL parameters
|
* Access allowed to any tasks from the shared public board by changing the URL parameters
|
||||||
|
|||||||
@@ -117,23 +117,20 @@ class UserNotification extends Base
|
|||||||
*/
|
*/
|
||||||
public function saveSettings($user_id, array $values)
|
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);
|
$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 {
|
} else {
|
||||||
$this->disableNotification($user_id);
|
$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
|
* @access public
|
||||||
* @param integer $user_id
|
* @param integer $user_id
|
||||||
* @param string $filter
|
* @param string $filter
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function saveFilter($user_id, $filter)
|
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,
|
'notifications_filter' => $filter,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -87,17 +88,21 @@ class UserNotificationFilter extends Base
|
|||||||
* @access public
|
* @access public
|
||||||
* @param integer $user_id
|
* @param integer $user_id
|
||||||
* @param integer[] $project_ids
|
* @param integer[] $project_ids
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function saveSelectedProjects($user_id, array $project_ids)
|
public function saveSelectedProjects($user_id, array $project_ids)
|
||||||
{
|
{
|
||||||
|
$results = array();
|
||||||
$this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove();
|
$this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove();
|
||||||
|
|
||||||
foreach ($project_ids as $project_id) {
|
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,
|
'user_id' => $user_id,
|
||||||
'project_id' => $project_id,
|
'project_id' => $project_id,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return !in_array(false, $results, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,16 @@ use PDO;
|
|||||||
use Kanboard\Core\Security\Token;
|
use Kanboard\Core\Security\Token;
|
||||||
use Kanboard\Core\Security\Role;
|
use Kanboard\Core\Security\Role;
|
||||||
|
|
||||||
const VERSION = 109;
|
const VERSION = 110;
|
||||||
|
|
||||||
|
function version_110(PDO $pdo)
|
||||||
|
{
|
||||||
|
$pdo->exec("ALTER TABLE user_has_notifications DROP FOREIGN KEY `user_has_notifications_ibfk_1`");
|
||||||
|
$pdo->exec("ALTER TABLE user_has_notifications DROP FOREIGN KEY `user_has_notifications_ibfk_2`");
|
||||||
|
$pdo->exec("DROP INDEX `project_id` ON user_has_notifications");
|
||||||
|
$pdo->exec("ALTER TABLE user_has_notifications DROP KEY `user_id`");
|
||||||
|
$pdo->exec("CREATE UNIQUE INDEX `user_has_notifications_unique_idx` ON `user_has_notifications` (`user_id`, `project_id`)");
|
||||||
|
}
|
||||||
|
|
||||||
function version_109(PDO $pdo)
|
function version_109(PDO $pdo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,11 +3,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post" action="<?= $this->url->href('user', 'notifications', array('user_id' => $user['id'])) ?>" autocomplete="off">
|
<form method="post" action="<?= $this->url->href('user', 'notifications', array('user_id' => $user['id'])) ?>" autocomplete="off">
|
||||||
|
|
||||||
<?= $this->form->csrf() ?>
|
<?= $this->form->csrf() ?>
|
||||||
<?= $this->form->checkbox('notifications_enabled', t('Enable notifications'), '1', $notifications['notifications_enabled'] == 1) ?><br>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<h4><?= t('Notification methods:') ?></h4>
|
<h4><?= t('Notification methods:') ?></h4>
|
||||||
<?= $this->form->checkboxes('notification_types', $types, $notifications) ?>
|
<?= $this->form->checkboxes('notification_types', $types, $notifications) ?>
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ class UserNotificationFilterTest extends Base
|
|||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||||
|
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
|
||||||
|
|
||||||
$this->assertEmpty($nf->getSelectedProjects(1));
|
$this->assertEmpty($nf->getSelectedProjects(1));
|
||||||
$nf->saveSelectedProjects(1, array(1, 2));
|
$this->assertTrue($nf->saveSelectedProjects(1, array(1, 2, 3)));
|
||||||
$this->assertEquals(array(1, 2), $nf->getSelectedProjects(1));
|
$this->assertEquals(array(1, 2, 3), $nf->getSelectedProjects(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSaveUserFilter()
|
public function testSaveUserFilter()
|
||||||
|
|||||||
Reference in New Issue
Block a user