diff --git a/migration/20.10/2010.sql b/migration/20.10/2010.sql index cec8867cd1e3076404fe3827e502d1fd346989e9..4a2a2432f4ea51d42b956b7853aeff7cabfd4137 100755 --- a/migration/20.10/2010.sql +++ b/migration/20.10/2010.sql @@ -17,6 +17,16 @@ DELETE FROM usergroups_services WHERE service_id IN ('reports', 'admin_reports') ALTER TABLE users DROP COLUMN IF EXISTS refresh_token; ALTER TABLE users ADD COLUMN refresh_token jsonb NOT NULL DEFAULT '[]'; +DO $$ BEGIN + IF (SELECT count(column_name) from information_schema.columns where table_name = 'notif_event_stack' and column_name = 'user_id' and data_type != 'integer') THEN + ALTER TABLE notif_event_stack ADD COLUMN user_id_tmp INTEGER; + UPDATE notif_event_stack set user_id_tmp = (select id FROM users where users.user_id = notif_event_stack.user_id); + DELETE FROM notif_event_stack WHERE user_id_tmp IS NULL; + ALTER TABLE notif_event_stack ALTER COLUMN user_id_tmp set not null; + ALTER TABLE notif_event_stack DROP COLUMN IF EXISTS user_id; + ALTER TABLE notif_event_stack RENAME COLUMN user_id_tmp TO user_id; + END IF; +END$$; DO $$ BEGIN IF (SELECT count(column_name) from information_schema.columns where table_name = 'users_email_signatures' and column_name = 'user_id' and data_type != 'integer') THEN ALTER TABLE users_email_signatures ADD COLUMN user_id_tmp INTEGER; diff --git a/modules/notifications/batch/basket_event_stack.php b/modules/notifications/batch/basket_event_stack.php index 39a16403435ce1a36eeb67953dbbf892591a1c0d..721946135dadd2b4af83ac7f8767e54f5169b738 100755 --- a/modules/notifications/batch/basket_event_stack.php +++ b/modules/notifications/batch/basket_event_stack.php @@ -52,7 +52,6 @@ while ($state != 'END') { foreach ($baskets as $basket) { Bt_writeLog(['level' => 'INFO', 'message' => 'BASKET: '.$basket['basket_id'].' in progess ...']); - $exceptUsers[$basket['basket_id']] = []; $groups = \Basket\models\GroupBasketModel::get(['select' => ['group_id'], 'where' => ['basket_id = ?'], 'data' => [$basket['basket_id']]]); $nbGroups = count($groups); @@ -70,16 +69,15 @@ while ($state != 'END') { foreach ($users as $userToNotify) { $real_user_id = ''; $whereClause = \SrcCore\controllers\PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $userToNotify['user_id']]); - $user_id = $userToNotify['user_id']; + $user_id = $userToNotify['id']; $redirectedBasket = \Basket\models\RedirectBasketModel::get([ 'select' => ['actual_user_id'], 'where' => ['owner_user_id = ?', 'basket_id = ?', 'group_id = ?'], 'data' => [$userToNotify['id'], $basket['basket_id'], $groupInfo['id']] ]); if (!empty($redirectedBasket)) { - $real_user_id = $user_id; - $user = \User\models\UserModel::getById(['id' => $redirectedBasket[0]['actual_user_id'], 'select' => ['user_id']]); - $user_id = $user['user_id']; + $real_user_id = $userToNotify['id']; + $user_id = $redirectedBasket[0]['actual_user_id']; } $resources = \Resource\models\ResModel::getOnView([ @@ -93,9 +91,9 @@ while ($state != 'END') { $i = 1; $info = 'Notification ['.$basket['basket_id'].'] pour '.$userToNotify['user_id']; if (!empty($real_user_id)) { - $notificationEvents = \Notification\models\NotificationsEventsModel::get(['select' => ['record_id'], 'where' => ['event_info = ?', '(user_id = ? OR user_id = ?)'], 'data' => [$info, $userToNotify['user_id'], $user_id]]); + $notificationEvents = \Notification\models\NotificationsEventsModel::get(['select' => ['record_id'], 'where' => ['event_info = ?', '(user_id = ? OR user_id = ?)'], 'data' => [$info, $userToNotify['id'], $user_id]]); } else { - $notificationEvents = \Notification\models\NotificationsEventsModel::get(['select' => ['record_id'], 'where' => ['event_info = ?', 'user_id = ?'], 'data' => [$info, $userToNotify['user_id']]]); + $notificationEvents = \Notification\models\NotificationsEventsModel::get(['select' => ['record_id'], 'where' => ['event_info = ?', 'user_id = ?'], 'data' => [$info, $userToNotify['id']]]); } $aRecordId = array_column($notificationEvents, 'record_id', 'record_id'); @@ -146,10 +144,12 @@ while ($state != 'END') { case 'SCAN_EVENT': $i = 1; + $usersId = array_column($events, 'user_id'); + $usersInfo = \User\models\UserModel::get(['select' => ['*'], 'where' => ['id in (?)'], 'data' => [$usersId]]); + $usersInfo = array_column($usersInfo, null, 'id'); foreach ($events as $event) { preg_match_all('#\[(\w+)]#', $event['event_info'], $result); $basket_id = $result[1]; - //Bt_writeLog(['level' => 'INFO', 'message' => 'scanning EVENT : '.$i.'/'.$totalEventsToProcess.' (BASKET => '.$basket_id[0].', DOCUMENT => '.$res_id.', RECIPIENT => '.$user_id.')']); if ($event['table_name'] == $coll_table || $event['table_name'] == $coll_view) { $res_id = $event['record_id']; @@ -160,11 +160,12 @@ while ($state != 'END') { $event['res_id'] = $res_id; $user_id = $event['user_id']; - if (!isset($tmpNotifs[$user_id])) { - $tmpNotifs[$user_id]['recipient'] = \User\models\UserModel::getByLogin(['select' => ['*'], 'login' => $user_id]); + $userInfo = $usersInfo[$user_id]; + if (!isset($tmpNotifs[$userInfo['user_id']])) { + $tmpNotifs[$userInfo['user_id']]['recipient'] = $userInfo; } - $tmpNotifs[$user_id]['baskets'][$basket_id[0]]['events'][] = $event; + $tmpNotifs[$userInfo['user_id']]['baskets'][$basket_id[0]]['events'][] = $event; ++$i; } @@ -177,13 +178,13 @@ while ($state != 'END') { /**********************************************************************/ Bt_writeLog(['level' => 'INFO', 'message' => 'STATE:MERGE NOTIF']); $i = 1; - foreach ($tmpNotifs as $user_id => $tmpNotif) { + foreach ($tmpNotifs as $login => $tmpNotif) { foreach ($tmpNotif['baskets'] as $basketId => $basket_list) { $baskets = \Basket\models\BasketModel::getByBasketId(['select' => ['basket_name'], 'basketId' => $basketId]); $subject = $baskets['basket_name']; // Merge template with data and style - Bt_writeLog(['level' => 'INFO', 'message' => 'generate e-mail '.$i.'/'.$totalNotificationsToProcess.' (TEMPLATE =>'.$notification['template_id'].', SUBJECT => '.$subject.', RECIPIENT => '.$user_id.', DOCUMENT(S) => '.count($basket_list['events'])]); + Bt_writeLog(['level' => 'INFO', 'message' => 'generate e-mail '.$i.'/'.$totalNotificationsToProcess.' (TEMPLATE =>'.$notification['template_id'].', SUBJECT => '.$subject.', RECIPIENT => '.$login.', DOCUMENT(S) => '.count($basket_list['events'])]); $params = array( 'recipient' => $tmpNotif['recipient'], @@ -203,7 +204,7 @@ while ($state != 'END') { \Notification\models\NotificationsEventsModel::update([ 'set' => ['exec_date' => 'CURRENT_TIMESTAMP', 'exec_result' => 'FAILED: Error when merging template'], 'where' => ['event_stack_sid = ?'], - 'data' => [$event->event_stack_sid] + 'data' => [$event['event_stack_sid']] ]); } Bt_exitBatch(8, 'Could not merge template with the data'); @@ -226,7 +227,6 @@ while ($state != 'END') { if ($attachMode) { Bt_writeLog(['level' => 'INFO', 'message' => 'Adding attachments']); foreach ($basket_list['events'] as $event) { - // Check if event is related to document in collection if ($event['res_id'] != '') { $resourceToAttach = \Resource\models\ResModel::getById(['resId' => $event['res_id'], 'select' => ['path', 'filename', 'docserver_id']]); if (!empty($resourceToAttach['docserver_id'])) { @@ -241,37 +241,22 @@ while ($state != 'END') { Bt_writeLog(['level' => 'INFO', 'message' => count($attachments).' attachment(s) added']); } - if (in_array($user_id, $exceptUsers[$basketId])) { - Bt_writeLog(['level' => 'WARNING', 'message' => 'Notification disabled for '.$user_id]); - } else { - Bt_writeLog(['level' => 'INFO', 'message' => '... adding e-mail to email stack']); + Bt_writeLog(['level' => 'INFO', 'message' => '... adding e-mail to email stack']); - $arrayPDO = [ - 'sender' => $sender, - 'recipient' => $recipient_mail, - 'subject' => $subject, - 'html_body' => $html, - 'charset' => $emailConfiguration['charset'], - 'module' => 'notifications', - ]; - if (count($attachments) > 0) { - $arrayPDO[] = implode(',', $attachments); - } - \Notification\models\NotificationsEmailsModel::create($arrayPDO); + $arrayPDO = [ + 'sender' => $sender, + 'recipient' => $recipient_mail, + 'subject' => $subject, + 'html_body' => $html, + 'charset' => $emailConfiguration['charset'], + 'module' => 'notifications', + ]; + if (count($attachments) > 0) { + $arrayPDO[] = implode(',', $attachments); } + \Notification\models\NotificationsEmailsModel::create($arrayPDO); - $notificationSuccess = []; - foreach ($basket_list['events'] as $event) { - if (in_array($event->user_id, $exceptUsers[$basketId])) { - \Notification\models\NotificationsEventsModel::update([ - 'set' => ['exec_date' => 'CURRENT_TIMESTAMP', 'exec_result' => 'WARNING : Notification disabled for '.$event->user_id], - 'where' => ['event_stack_sid = ?'], - 'data' => [$event->event_stack_sid] - ]); - } else { - $notificationSuccess[] = $event->event_stack_sid; - } - } + $notificationSuccess = array_column($basket_list['events'], 'event_stack_sid'); if (!empty($notificationSuccess)) { \Notification\models\NotificationsEventsModel::update([ 'set' => ['exec_date' => 'CURRENT_TIMESTAMP', 'exec_result' => 'SUCCESS'], diff --git a/modules/notifications/batch/load_process_email_stack.php b/modules/notifications/batch/load_process_email_stack.php index 06b20702c17b1bd1e79695975a0f9a0f10f1fba6..42bcc2e79a9239b99e42578d250789a520f41236 100755 --- a/modules/notifications/batch/load_process_email_stack.php +++ b/modules/notifications/batch/load_process_email_stack.php @@ -1,22 +1,9 @@ <?php -/* - * Copyright 2008-2011 Maarch - * - * This file is part of Maarch Framework. - * - * Maarch Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Maarch Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. +/** + * Copyright Maarch since 2008 under licence GPLv3. + * See LICENCE.txt file at the root folder for more details. + * This file is part of Maarch software. */ /** diff --git a/modules/templates/datasources/letterbox_events.php b/modules/templates/datasources/letterbox_events.php index 4ff3edf56b16fa8d5d2c18bf116255c7356bca40..33ea32e3f82b2bd93fd4e4240634a13971d391cb 100755 --- a/modules/templates/datasources/letterbox_events.php +++ b/modules/templates/datasources/letterbox_events.php @@ -25,7 +25,6 @@ use Entity\models\EntityModel; use Resource\models\ResourceContactModel; use SrcCore\models\DatabaseModel; use User\models\UserBasketPreferenceModel; -use User\models\UserModel; $datasources['recipient'][0] = (array) $recipient; $datasources['res_letterbox'] = []; @@ -33,12 +32,11 @@ $datasources['contact'] = []; $urlToApp = trim($maarchUrl, '/').'/apps/'.trim($maarchApps, '/').'/index.php?'; -$user = UserModel::getByLogin(['login' => $datasources['recipient'][0]['user_id'], 'select' => ['id']]); $basket = BasketModel::getByBasketId(['select' => ['id'], 'basketId' => 'MyBasket']); $preferenceBasket = UserBasketPreferenceModel::get([ 'select' => ['group_serial_id'], 'where' => ['user_serial_id = ?', 'basket_id = ?'], - 'data' => [$user['id'], 'MyBasket'] + 'data' => [$recipient['id'], 'MyBasket'] ]); foreach ($events as $event) { @@ -81,8 +79,8 @@ foreach ($events as $event) { // Lien vers la page detail $res['linktodoc'] = $urlToApp . 'linkToDoc='.$res['res_id']; $res['linktodetail'] = $urlToApp . 'linkToDetail='.$res['res_id']; - if (!empty($res['res_id']) && !empty($preferenceBasket[0]['group_serial_id']) && !empty($basket['id']) && !empty($user['id'])) { - $res['linktoprocess'] = $urlToApp . 'linkToProcess='.$res['res_id'].'&groupId='.$preferenceBasket[0]['group_serial_id'].'&basketId='.$basket['id'].'&userId='.$user['id']; + if (!empty($res['res_id']) && !empty($preferenceBasket[0]['group_serial_id']) && !empty($basket['id']) && !empty($recipient['user_id'])) { + $res['linktoprocess'] = $urlToApp . 'linkToProcess='.$res['res_id'].'&groupId='.$preferenceBasket[0]['group_serial_id'].'&basketId='.$basket['id'].'&userId='.$recipient['user_id']; } if (!empty($res['initiator'])) { diff --git a/modules/templates/datasources/mlb_notes_content.php b/modules/templates/datasources/mlb_notes_content.php index d5b934810c767095212b154b46ebee5f7ebb0fbd..05b366829623025a5270b1ac3319c4314a99033a 100755 --- a/modules/templates/datasources/mlb_notes_content.php +++ b/modules/templates/datasources/mlb_notes_content.php @@ -45,19 +45,18 @@ foreach ($events as $event) { // Link to detail page $urlToApp = trim($maarchUrl, '/').'/apps/'.trim($maarchApps, '/').'/index.php?'; - $user = UserModel::getByLogin(['login' => $datasources['recipient'][0]['user_id'], 'select' => ['id']]); $basket = BasketModel::getByBasketId(['select' => ['id'], 'basketId' => 'MyBasket']); $preferenceBasket = UserBasketPreferenceModel::get([ 'select' => ['group_serial_id'], 'where' => ['user_serial_id = ?', 'basket_id = ?'], - 'data' => [$user['id'], 'MyBasket'] + 'data' => [$recipient['user_id'], 'MyBasket'] ]); $note['linktodoc'] = $urlToApp . 'linkToDoc='.$resId; $note['linktodetail'] = $urlToApp . 'linkToDetail='.$resId; - if (!empty($resId) && !empty($preferenceBasket[0]['group_serial_id']) && !empty($basket['id']) && !empty($user['id'])) { - $note['linktoprocess'] = $urlToApp . 'linkToProcess='.$resId.'&groupId='.$preferenceBasket[0]['group_serial_id'].'&basketId='.$basket['id'].'&userId='.$user['id']; + if (!empty($resId) && !empty($preferenceBasket[0]['group_serial_id']) && !empty($basket['id']) && !empty($recipient['user_id'])) { + $note['linktoprocess'] = $urlToApp . 'linkToProcess='.$resId.'&groupId='.$preferenceBasket[0]['group_serial_id'].'&basketId='.$basket['id'].'&userId='.$recipient['user_id']; } $resourceContacts = ResourceContactModel::get([ diff --git a/sql/structure.sql b/sql/structure.sql index 8f4b60b9ecf22cb81340f2b0fe7b34b0baa8b2ec..318cda71ed3fde13e82b380525fac946c972255d 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -658,7 +658,7 @@ CREATE TABLE notif_event_stack notification_sid bigint NOT NULL, table_name character varying(50) NOT NULL, record_id character varying(128) NOT NULL, - user_id character varying(128) NOT NULL, + user_id integer NOT NULL, event_info character varying(255) NOT NULL, event_date timestamp without time zone NOT NULL, exec_date timestamp without time zone, diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index f8f4dac79fba61b19858e1180d8d475f838ad8ed..896f521b17ca674aa8c89e8d1763b501b6f9adb2 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -167,7 +167,7 @@ class HistoryController "eventId" => $aArgs['eventId'], "tableName" => $aArgs['tableName'], "recordId" => $aArgs['recordId'], - "userId" => $aArgs['userId'], + "userId" => $GLOBALS['id'], "info" => $aArgs['info'], ]); } diff --git a/src/app/notification/models/NotificationsEventsModelAbstract.php b/src/app/notification/models/NotificationsEventsModelAbstract.php index b5677219f6ee0ac40d8fd4dea6ae7ca33586ff8f..9972f9f00f596e65ad4d882caf2c0cd702ca1160 100755 --- a/src/app/notification/models/NotificationsEventsModelAbstract.php +++ b/src/app/notification/models/NotificationsEventsModelAbstract.php @@ -39,8 +39,8 @@ abstract class NotificationsEventsModelAbstract public static function create(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['notification_sid', 'table_name', 'record_id', 'user_id', 'event_info']); - ValidatorModel::stringType($aArgs, ['table_name', 'user_id', 'event_info']); - ValidatorModel::intval($aArgs, ['notification_sid']); + ValidatorModel::stringType($aArgs, ['table_name', 'event_info']); + ValidatorModel::intval($aArgs, ['notification_sid', 'user_id']); $aArgs['event_date'] = 'CURRENT_TIMESTAMP'; diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index ba0b1e8038daaadf4b998d604ad8eeb4b3928d3b..fb4b037dfb558e3a37de7e2119fdb09468fe19ea 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -216,7 +216,7 @@ class UserController if (!empty($userQuota['param_value_int'])) { $activeUser = UserModel::get(['select' => ['count(1)'], 'where' => ['status = ?', 'user_id <> ?'], 'data' => ['OK', 'superadmin']]); if ($activeUser[0]['count'] > $userQuota['param_value_int']) { - NotificationsEventsController::fillEventStack(['eventId' => 'user_quota', 'tableName' => 'users', 'recordId' => 'quota_exceed', 'userId' => 'superadmin', 'info' => _QUOTA_EXCEEDED]); + NotificationsEventsController::fillEventStack(['eventId' => 'user_quota', 'tableName' => 'users', 'recordId' => 'quota_exceed', 'userId' => $GLOBALS['id'], 'info' => _QUOTA_EXCEEDED]); } } @@ -286,7 +286,7 @@ class UserController if ($user['status'] == 'SPD' && $data['status'] == 'OK') { $activeUser = UserModel::get(['select' => ['count(1)'], 'where' => ['status = ?', 'user_id != ?'], 'data' => ['OK', 'superadmin']]); if ($activeUser[0]['count'] > $userQuota['param_value_int']) { - NotificationsEventsController::fillEventStack(['eventId' => 'user_quota', 'tableName' => 'users', 'recordId' => 'quota_exceed', 'userId' => 'superadmin', 'info' => _QUOTA_EXCEEDED]); + NotificationsEventsController::fillEventStack(['eventId' => 'user_quota', 'tableName' => 'users', 'recordId' => 'quota_exceed', 'userId' => $GLOBALS['id'], 'info' => _QUOTA_EXCEEDED]); } } }