diff --git a/migration/20.10/migrate.sh b/migration/20.10/migrate.sh index 666a20f552dd7a332a6999815f60cedb1855fcf8..7dc4748e204c7205c57473b45c7a7857e428147e 100755 --- a/migration/20.10/migrate.sh +++ b/migration/20.10/migrate.sh @@ -1,2 +1,3 @@ #!/bin/sh php ./migrateModulesConfig.php +php ./migrateNotificationsProperties.php diff --git a/migration/20.10/migrateNotificationsProperties.php b/migration/20.10/migrateNotificationsProperties.php new file mode 100644 index 0000000000000000000000000000000000000000..3aa007c1192eac0fcc1bd6af496dfa64c8f23297 --- /dev/null +++ b/migration/20.10/migrateNotificationsProperties.php @@ -0,0 +1,36 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$customs = scandir('custom'); +$migrated = 0; +foreach ($customs as $custom) { + if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') { + continue; + } + + \SrcCore\models\DatabasePDO::reset(); + new \SrcCore\models\DatabasePDO(['customId' => $custom]); + + $notifications = \Notification\models\NotificationModel::get([ + 'select' => ['diffusion_properties', 'notification_sid'], + 'where' => ['diffusion_type = ?'], + 'data' => ['user'] + ]); + foreach ($notifications as $notification) { + $users = explode(',', $notification['diffusion_properties']); + if (!empty($users)) { + $users = \User\models\UserModel::get(['select' => ['id'], 'where' => ['user_id in (?)'], 'data' => [$users]]); + $users = array_column($users, 'id'); + if (!empty($users)) { + $users = implode(',', $users); + \Notification\models\NotificationModel::update(['notification_sid' => $notification['notification_sid'], 'diffusion_properties' => $users]); + } + } + } + $migrated++; +} + +printf("migrateNotificationsProperties : " . $migrated . " custom(s) trouvé(s) et migré(s).\n"); diff --git a/src/app/notification/models/NotificationModelAbstract.php b/src/app/notification/models/NotificationModelAbstract.php index a1230d068e11b4252c9134605cf48952490a70ba..eb3207336306cc6806d5625a39234eca38ab8ad1 100755 --- a/src/app/notification/models/NotificationModelAbstract.php +++ b/src/app/notification/models/NotificationModelAbstract.php @@ -243,10 +243,14 @@ abstract class NotificationModelAbstract public static function getDiffusionTypesUsers() { $users = DatabaseModel::select([ - 'select' => ["user_id as id, concat(firstname,' ',lastname) as label"], + 'select' => ["id, concat(firstname,' ',lastname) as label"], 'table' => ['users'], ]); + foreach ($users as $key => $user) { + $users[$key]['id'] = (string)$user['id']; + } + return $users; }