Bearsampp / sandbox

R&D Repo for Bearsampp
GNU General Public License v3.0
0 stars 1 forks source link

Clear Logs #48

Closed N6REJ closed 3 months ago

N6REJ commented 3 months ago

User description

To Test: Generate logs. use clear temp function and verirfy all logs except mailpit, memcached & xlight are deleted and .gitignore is not.


PR Type

enhancement


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
class.action.clearFolders.php
Add log clearing functionality to clearFolders action       

core/classes/actions/class.action.clearFolders.php
  • Added functionality to clear log files in the clearFolders action.
  • Specified exclusions for log files that should not be deleted.
  • +3/-0     

    πŸ’‘ PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
    πŸ§ͺ No relevant tests
    πŸ”’ No security concerns identified
    ⚑ Key issues to review

    Consistency Issue
    The exclusion list in the `Util::clearFolder` call for logs includes '.gitignore', which is inconsistent with the user description stating that '.gitignore' should not be deleted. Please verify if this is intended or an oversight.
    codiumai-pr-agent-pro[bot] commented 3 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Error handling
    Implement error handling for folder clearing operations ___ **Add error handling for the Util::clearFolder method to manage cases where the folder
    path might be incorrect or permissions are insufficient.** [core/classes/actions/class.action.clearFolders.php [44]](https://github.com/Bearsampp/sandbox/pull/48/files#diff-cfbca2eae07cd2bbbecf11139dc0e2583cdbcf5d89c6a4e491e9b5d6464eaf96R44-R44) ```diff -Util::clearFolder($bearsamppRoot->getLogsPath(), array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore')); +if (!Util::clearFolder($bearsamppRoot->getLogsPath(), array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore'))) { + error_log('Failed to clear logs folder.'); +} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 10 Why: Adding error handling is crucial for robustness, ensuring that issues with folder paths or permissions are logged and managed appropriately. This significantly improves the reliability of the code.
    10
    Possible issue
    Ensure consistent use of constants or strings for 'Mailpit' ___ **Ensure that the 'Mailpit' class constant is consistently used or declared. In the
    previous code, 'Mailpit' appears without quotes, suggesting it might be intended as
    a constant. If it's a string, it should be quoted.** [core/classes/actions/class.action.clearFolders.php [41]](https://github.com/Bearsampp/sandbox/pull/48/files#diff-cfbca2eae07cd2bbbecf11139dc0e2583cdbcf5d89c6a4e491e9b5d6464eaf96R41-R41) ```diff -Util::clearFolder($bearsamppRoot->getTmpPath(), array('cachegrind', 'composer', 'openssl', 'mailhog', Mailpit, 'xlight', 'npm-cache', 'pip', 'yarn', '.gitignore')); +Util::clearFolder($bearsamppRoot->getTmpPath(), array('cachegrind', 'composer', 'openssl', 'mailhog', 'Mailpit', 'xlight', 'npm-cache', 'pip', 'yarn', '.gitignore')); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This suggestion addresses a potential bug where 'Mailpit' might be intended as a constant but is used without quotes. Ensuring consistency can prevent runtime errors and improve code clarity.
    9
    Enhancement
    Abstract the list of files to clear into a configurable property or method ___ **Consider abstracting the list of file types and logs to clear into a configuration
    file or a class property, which can be easily updated without modifying the method
    directly.** [core/classes/actions/class.action.clearFolders.php [44]](https://github.com/Bearsampp/sandbox/pull/48/files#diff-cfbca2eae07cd2bbbecf11139dc0e2583cdbcf5d89c6a4e491e9b5d6464eaf96R44-R44) ```diff -Util::clearFolder($bearsamppRoot->getLogsPath(), array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore')); +$filesToClear = $this->getFilesToClear(); // This method would retrieve the array from a config or property +Util::clearFolder($bearsamppRoot->getLogsPath(), $filesToClear); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Abstracting the list of files into a configuration file or class property enhances flexibility and maintainability. It allows updates without modifying the method directly, which is beneficial for larger projects.
    8
    Maintainability
    Use a variable to store log file names for better maintainability ___ **Consider using a variable to store the array of log files to be cleared. This will
    make the code cleaner and easier to maintain, especially if the list of log files
    changes in the future.** [core/classes/actions/class.action.clearFolders.php [44]](https://github.com/Bearsampp/sandbox/pull/48/files#diff-cfbca2eae07cd2bbbecf11139dc0e2583cdbcf5d89c6a4e491e9b5d6464eaf96R44-R44) ```diff -Util::clearFolder($bearsamppRoot->getLogsPath(), array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore')); +$logFiles = array('mailpit.err.log', 'mailpit.out.log', 'memcached.err.log', 'memcached.out.log', 'xlight.err.log', 'xlight.log', '.gitignore'); +Util::clearFolder($bearsamppRoot->getLogsPath(), $logFiles); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: This suggestion improves code maintainability by storing the log file names in a variable, making it easier to update the list in the future. However, it is a minor enhancement and not critical for functionality.
    7