#5766 - Many missing addon guards

This is a spacer post for a website comment topic. The content this topic relates to: #5766 - Many missing addon guards
Automated message: This issue was created using the Report Issue Wizard on the Composr homesite.
This may have a greater time than benefit ratio and not worth considering.
I don't know about the stated resolution, but if there are a lot of issues we need to find/fix them somehow.
This needs to be considered for get_option and $GET_OPTION as well.

Automated response: Many missing addon guards

This hotfix adds guards for addons based on get_option . There is no guarantee we got all of them.

The addon_guards test has been modified to pick up on get_option (and ignore ones whose second parameter (missing_ok) is true).

We still need to account for templates sometime. Also, the test should ideally be modified to be more concise... scan by function instead of by entire file (e.g. if one addon_installed check is detected, it determines the entire file as good even if the guard may actually be needed in another function).

A hotfix (a TAR of files to upload) has been uploaded to this issue. Only apply this hotfix if you absolutely need it and cannot wait until the next release of Composr (releases are more reliable and strictly tested). As of Composr version 11, the recommended way to apply a hotfix is by following the same steps as an upgrade (https://baseurl/upgrader.php, use the hotfix on the step “Transfer across new/updated files”). The upgrader will automatically skip files belonging to addons you do not have installed or that are newer on disk than in the hotfix. Otherwise, you can manually extract and replace these files (do not replace if your on-disk file is newer than the one in the hotfix). Always take backups of your site or at least files you are replacing before applying a hotfix. Not sure how to extract TAR files to your Windows computer? Try 7-zip (http://www.7-zip.org/).
This addon_guards test has been made much more smart. While it is not perfect, it did catch many missing guards. Therefore, beta5 should be much more stable handling conditions where some addons are not installed.

The modifications to addon_guards include the following:
- Primarily, it now uses the phpdoc.php API function to parse code based on class and function. That way, we can check for guards by function and not by entire file.
- The test is much more smart with smart exceptions to define cases where a class might define its guards in a specific function to be applied to all functions in the class (assumed). For example, info.
- The test checks for, and fails on, use of !addon_installed when we should use !addon_installed__messaged.
- The test checks for, and fails on, use of positive assertions for cohesion (instead, for stability, we should be using negative assertions towards the top of a function with a return).
- When checking implicit code calls, the test keeps track of which addon guards are active by tokenising the code and storing the active guards in an array "stack", popping out as we close out of code blocks. Additionally, this check assumes negative assertions will always return, therefore it treats it as a positive assertion on the parent code block (e.g. one level up in the stack).

Many, many fixes were implemented thanks to the changes to this test and what it detected. Again, not perfect, and the test cannot handle $missing_okay on get_option yet (nor does it check templates). But it's a big step forward.
1 guest and 0 members have recently viewed this.