Ability to rotate "Session Log" and "Changes Log"
Details
Part 1
- go to Configuration → Website → Advanced section
- ensure that "Keep "Session Log" for" is set to "Forever"
- ensure that "Track database changes to change log" is checked, save
- log out
- log in
- log out
- log in
- go to Tools → Query Database section
- launch SQL like: UPDATE inp_UserSessionLogs SET SessionEnd = -5 WHERE NOT ISNULL(SessionEnd);
- go to Logs & Reports → Session Log section
- confirm, that Session end date for all ended sessions is about 01/01/1970
- run in-portal scheduled-task:run rotate_session_logs command from shell while in the project directory
- go to Logs & Reports → Session Log section
- confirm, that oldest sessions remains in the list
Part 2
- go to Configuration → Website → Advanced section
- ensure that "Keep "Session Log" for" is set to "1 week"
- change "Enable SEO-friendly URLs mode (MOD-REWRITE)" setting, save
- go to Logs & Reports → Changes Log section
- confirm, that last change of Configuration is in the list
- log out
- log in
- go to Tools → Query Database section
- launch SQL like: UPDATE inp_UserSessionLogs SET SessionEnd = UNIX_TIMESTAMP() - #seconds# WHERE NOT ISNULL(SessionEnd), where #seconds# must be replaced with corresponding integer value from note above
- go to Logs & Reports → Session Log section
- confirm, that Session end date for all ended sessions is about ("Current Date" - "period, selected from note above for test")
- run in-portal scheduled-task:run rotate_session_logs command from shell while in the project directory
- go to Logs & Reports → Changes Log section
- confirm, that list is empty
- go to Logs & Reports → Session Log section
- confirm, that only current session is in the list
Part 3
- make 2 or more outdated sessions with change log records (login and logout several times, make some changes and save)
- launch SQL like: UPDATE inp_UserSessionLogs SET SessionEnd = -5 WHERE NOT ISNULL(SessionEnd)
- go to Logs & Reports → Session Log section
- confirm, that Session end date for all ended sessions is about 01/01/1970
- go to Configuration → Website → Advanced section
- ensure that "Keep "Session Log" for" is set to "1 week"
- change system code temporarily - set $limit = 1 in place of $limit = 100 in SessionLogEventHandler::OnRotate event
- run in-portal scheduled-task:run rotate_session_logs command from shell while in the project directory
- go to Logs & Reports → Session Log section
- confirm, that only current session is in the list
- go to Logs & Reports → Changes Log section
- confirm, that only last session changes are in the list
- restore system code - set $limit = 100 in SessionLogEventHandler::OnRotate event
Diff Detail
- Repository
- rINP In-Portal
- Branch
- /in-portal/branches/5.3.x
- Lint
Lint Errors Excuse: full event handler re-formatting is not a part of this task Severity Location Code Message Error core/units/logs/session_logs/session_log_eh.php:190 PHPCS.E.CodingStandard.Classes.ClassDeclaration.SpaceBeforeCloseBrace CodingStandard.Classes.ClassDeclaration.SpaceBeforeCloseBrace - Unit
No Unit Test Coverage - Build Status
Buildable 249 Build 249: arc lint + arc unit
Event Timeline
Aside from inline comments following needs to be fixed in the test plan as well:
- go to Configuration → Website → Advanced section
- ensure that "Track database changes to change log" is checked
- ensure that "Keep "Session Log" for" is set to "1 week"
- change "Enable SEO-friendly URLs mode (MOD-REWRITE)" setting, save
- log out
- launch some SQL to offset all non-null UserSessionLogs.SessionEnd values more than "1 week" to the past
Above mentioned part of "Part 1" from test plan will have no effect, because the Track database changes to change log system setting change will only have effect on newly created session (admin session, where it was changed isn't affected).
- launch some SQL to offset all non-null UserSessionLogs.SessionEnd values more than "1 week" to the past
The test is performed by human, that isn't aware of how changed functionality works now or before and ideally by a non-developer. Therefore the test plan items must be as concrete is possible (not some SQL as in this case). Please (in test plan):
- mention exact SQL
- explain how to adapt SQL to always work (e.g. replace timestamp to today, etc.)
- explain how to verify, that SQL really worked
- edit "rotate_session_logs" record, change "Next Run On" to some date in the past
- wait until "rotate_session_logs" scheduled task performs it's job
In case, when user haven't configured CRON and set scheduled task to be executed from cron this will never work. Instead I recommend running in-portal scheduled-task:run rotate_session_logs command from shell while in the project directory.
- confirm, that only last change of Scheduled task is in the list
Update this to still work even if scheduled task invocation code was changed.
core/units/logs/session_logs/session_log_eh.php | ||
---|---|---|
148 | With such a small limit there will be a lot of database queries (one per database record) executed. | |
149 | Please use boolean data type here (e.g. true and false) not 1 and 0. The variable value doesn't represent quantity, but integer data type value is being used. | |
150 | Please rename to $session_log_config. Makes code easier to read. | |
151 | Please move variable closer (but above cycle) to the usage point. Variable is declared too far ahead of it's usage place. | |
152–155 | Please rename to $session_log_select_sql. Makes code easier to read. | |
157–169 | Please:
Makes code easier to read. | |
158–162 | Please rename to $session_log_temp_handler. Makes code easier to read. | |
171 | Please:
The do ... while variation of while cycle is best to be used, when cycle condition needs to be checked after iteration. | |
172 | Please rename $ids to $session_log_ids. Makes code easier to read. | |
181–191 | Please:
Code might look like this: do { $change_log_ids = $this->Conn->GetCol($change_log_select_sql); if ( $change_log_ids ) { $change_log_temp_handler->DeleteItems('change-log', '', $change_log_ids); } } while ( count($change_log_ids) == $limit ); The do ... while variation of while cycle is best to be used, when cycle condition needs to be checked after iteration. | |
core/units/logs/system_logs/system_logs_config.php | ||
1 ↗ | (On Diff #404) | Please remove this file from diff. File doesn't contain any relevant changes. |
The test plan seems to out of sync with reality this time as well.
- go to Configuration → Website → Advanced section
- ensure that "Keep "Session Log" for" is set to "Forever"
- ensure that "Track database changes to change log" is checked, save
- log out
- log in
- go to Tools → Query Database section
- launch SQL like "UPDATE inp_UserSessionLogs SET SessionEnd = -5 WHERE NOT ISNULL(SessionEnd)"
This last item would affect 0 rows in the database, because the only record in SessionLog table would be the one matching active admin session and that's the record, that isn't affected by mentioned SQL.
I recommend you to use your own test plan to test your work (on clean In-Portal install) to detect other such inconsistencies.
core/units/helpers/temp_tables_helper.php | ||
---|---|---|
23–38 | Please:
In my initial request (create helper, that would accept ...) I've forgot to put method word. I wanted just helper method, not helper class. Sorry for confusion. | |
core/units/logs/session_logs/session_log_eh.php | ||
152 | Please add an empty line below this line. To logically group connected variables together. | |
164 | Please use inverted condition to leave the cycle (via break;) right away. IF statement that covers 100% of the cycle scope (code inside cycle). | |
171–175 | Do not change anything here please. | |
177 | Please inline this variable. Cycle condition already means I will iterate again when condition matches. There is no need to create temp variable to describe how PHP language constructs work. | |
183 | Please inline this variable. Cycle condition already means I will iterate again when condition matches. There is no need to create temp variable to describe how PHP language constructs work. | |
core/units/logs/system_logs/system_logs_config.php | ||
1 ↗ | (On Diff #406) | This wasn't addressed in previous fix. |
core/install/cache/class_structure.php | ||
---|---|---|
31 | The changes in these file tell, that you have some other patches applied in your working copy as well. You should Shelve them (in PhpStorm) before running the in-portal classmap:rebuild command. |
Please thoroughly look through each comment I leave (every time on every revision). If you decide not to do as I've advised, then please explain why as a reply to relevant comment.
core/install/cache/class_structure.php | ||
---|---|---|
31 | This wasn't addressed in previous fix. | |
core/units/helpers/temp_tables_helper.php | ||
23–38 | This wasn't addressed in previous fix. | |
core/units/logs/session_logs/session_log_eh.php | ||
177 | This wasn't addressed in previous fix. | |
183 | This wasn't addressed in previous fix. |
core/units/logs/session_logs/session_log_eh.php | ||
---|---|---|
177 | The comment is a reminder about previous commit, which is marked with grey color, because it references previous code version. I'm talking about $change_log_need_more_iteration variable here. | |
183 | That's ok. You still can change it. I think that this is an error in the sniff itself, that reports that line as error. I've reported it as https://github.com/squizlabs/PHP_CodeSniffer/issues/764 . |
Code tested according to plan. Please do that last cosmetical change and we're done here.
core/units/logs/session_logs/session_log_eh.php | ||
---|---|---|
154–156 | The SQL statement part isn't properly indented: The SQL in the $change_log_select_sql variable below however is indented correctly: |