Fix bug on initial install settings of Group Analytics, a=chros

Chris Pollett [2022-11-23 20:Nov:rd]
Fix bug on initial install settings of Group Analytics, a=chros
Filename
src/configs/Config.php
src/controllers/components/SystemComponent.php
src/models/ProfileModel.php
src/views/elements/SecurityElement.php
diff --git a/src/configs/Config.php b/src/configs/Config.php
index 0a0135034..07a36625b 100755
--- a/src/configs/Config.php
+++ b/src/configs/Config.php
@@ -557,6 +557,9 @@ if (file_exists(WORK_DIRECTORY . PROFILE_FILE_NAME)) {
     nsdefine('TOPBAR_COLOR', "#F5F5FF");
     nsdefine('MONETIZATION_TYPE', "no_monetization");
     nsdefine('AD_LOCATION','none');
+    nsdefine('SEARCH_ANALYTICS_MODE', true);
+    nsdefine('GROUP_ANALYTICS_MODE', true);
+    nsdefine('DIFFERENTIAL_PRIVACY', false);
 }

 /** ignore */
diff --git a/src/controllers/components/SystemComponent.php b/src/controllers/components/SystemComponent.php
index d3b74fb53..fd1cc4e9a 100755
--- a/src/controllers/components/SystemComponent.php
+++ b/src/controllers/components/SystemComponent.php
@@ -846,7 +846,7 @@ EOD;
             'SESSION_NAME' => "yioopbiscuit",
             'CSRF_TOKEN' => "YIOOP_TOKEN",
             'DIFFERENTIAL_PRIVACY' => false,
-            'GROUP_ANALYTICS_MODE' => false
+            'GROUP_ANALYTICS_MODE' => true
         ];
         $data = [];
         $data['AUTOLOGOUT_TIMES'] = [
@@ -1313,10 +1313,10 @@ EOD;
                         $profile['NAME_SERVER'] = C\BASE_URL;
                         $data['NAME_SERVER'] = $profile['NAME_SERVER'];
                         $profile['AUTH_KEY'] = L\crawlHash(
-                            $data['WORK_DIRECTORY'].time());
+                            $data['WORK_DIRECTORY'] . time());
                         $data['AUTH_KEY'] = $profile['AUTH_KEY'];
                         $robot_instance = str_replace(".", "_",
-                            $_SERVER['SERVER_NAME'] ?? '')."-".time();
+                            $_SERVER['SERVER_NAME'] ?? '') . "-" . time();
                         $profile['ROBOT_INSTANCE'] = $robot_instance;
                         $data['ROBOT_INSTANCE'] = $profile['ROBOT_INSTANCE'];
                         if ($profile_model->updateProfile(
diff --git a/src/models/ProfileModel.php b/src/models/ProfileModel.php
index 82e3235f2..e301f3be3 100755
--- a/src/models/ProfileModel.php
+++ b/src/models/ProfileModel.php
@@ -537,6 +537,7 @@ EOT;
             'AUTOLOGOUT' => C\ONE_HOUR,
             'BACKGROUND_COLOR' => "#FFF",
             'COOKIE_LIFETIME' => C\ONE_YEAR,
+            'DIFFERENTIAL_PRIVACY' => false,
             'CSRF_TOKEN' => "YIOOP_TOKEN",
             'FAVICON' => "favicon.ico",
             'FOREGROUND_COLOR' => "#FFF",
@@ -581,7 +582,7 @@ EOT;
                     } elseif (isset($old_profile_data[$field])) {
                         $profile[$field] = $old_profile_data[$field];
                     } elseif (nsdefined($field)) {
-                        $profile[$field] =  constant(C\NS_CONFIGS .$field);
+                        $profile[$field] =  constant(C\NS_CONFIGS . $field);
                     } else {
                         $profile[$field] = "";
                     }
diff --git a/src/views/elements/SecurityElement.php b/src/views/elements/SecurityElement.php
index 6b3691f15..55e1843ed 100755
--- a/src/views/elements/SecurityElement.php
+++ b/src/views/elements/SecurityElement.php
@@ -116,6 +116,9 @@ class SecurityElement extends Element
                     tl('security_element_differential_privacy')?></b></label>
                 </td><td>
                 <?php
+                if (empty($data['DIFFERENTIAL_PRIVACY'])) {
+                    $data['DIFFERENTIAL_PRIVACY'] = 0;
+                }
                 $this->view->helper("options")->render("privacy-mode",
                     "DIFFERENTIAL_PRIVACY", $data['PRIVACY_MODES'],
                     $data['DIFFERENTIAL_PRIVACY']);
@@ -127,6 +130,9 @@ class SecurityElement extends Element
                 </label>
                 </td><td>
                 <?php
+                if (empty($data['GROUP_ANALYTICS_MODE'])) {
+                    $data['GROUP_ANALYTICS_MODE'] = 0;
+                }
                 $this->view->helper("options")->render("group-analytics-mode",
                     "GROUP_ANALYTICS_MODE", $data['GROUP_ANALYTICS_MODES'],
                     $data['GROUP_ANALYTICS_MODE']);
@@ -139,6 +145,9 @@ class SecurityElement extends Element
                 </label>
                 </td><td>
                 <?php
+                if (empty($data['SEARCH_ANALYTICS_MODE'])) {
+                    $data['SEARCH_ANALYTICS_MODE'] = 0;
+                }
                 $this->view->helper("options")->render("search-analytics-mode",
                     "SEARCH_ANALYTICS_MODE", $data['SEARCH_ANALYTICS_MODES'],
                     $data['SEARCH_ANALYTICS_MODE']);
ViewGit