Attempting to Add Project for the Default project, even when the Default project is disabled, results in error msg 'The project code (...) already has an entry in the "Default" project.' As I understand it, adding this kind of project should be allowed.
Here's my take on where the bug lies.
File: optimizely.admin.inc
Line: 184
The condition for the "if" statement is equivalent to just "$query_count > 0" for the following reasons.
If the clause ($query_count is > 0) is true, then the remaining part of the overall condition is never evaluated since the || is already true.
If the clause ($query_count > 0) is false, then $query_count must be 0. In that case the remaining part of the overall condition must also be false because ($query_count >= 2) will be false.
The overall condition is quite complicated and needs to be revisited.
One possible simplication is to do something like the following because in this scenario I think it would be easier to construct the correct logic by thinking about when it's okay to add the project rather than not-okay.
$okay = ($query_count == 0) || ( ... );
if (! $okay) { ... }
Comments
Comment #1
DeeZone commentedComment #2
DeeZone commentedI think the goal is to only ever have one entry that's based on the default project ID / Optimizely account ID. The goal is to keep the default project entries simple with a single entry - enable or disable with the default "*" wild card path or something more specific. Having more than one entry with the default project ID / Optimizely account ID would, I suspect, lead to confusion due to duplicate paths.
If you disagree please make further arguments to adjust the functionality. As for the quality of the code behind this functionality, I agree that it needs to be refactored to make the logic less complicated.