Browse Source

v8-2771 move remaining constants to the new env manager system

Olivier Massot 4 years ago
parent
commit
b5ede9902f

+ 5 - 15
ot_core/Classes/Service/OpentalentEnvService.php

@@ -2,15 +2,13 @@
 
 namespace Opentalent\OtCore\Service;
 
-use http\Exception\RuntimeException;
-
 /**
- * Return the current opentalent environment variables
+ * Manage the opentalent environment variables
  *
  * To override the default values for a specific environment, set the new values as
  * global variables as $GLOBALS['OT']['YOUR_VAR']
  *
- * A goot place to do that is in the AdditionalConfiguration.php file of your typo3 installation,
+ * A good place to do that is in the AdditionalConfiguration.php file of your typo3 installation,
  * by adding for example:
  *
  *     $GLOBALS['OT']['DB_HOST'] = 'db';
@@ -18,18 +16,10 @@ use http\Exception\RuntimeException;
  */
 class OpentalentEnvService
 {
-    const DEFAULT = [
-        'API_BASE_URI' => 'https://api.opentalent.fr',
-        'DB_HOST' => 'prod-back',
-        'DB_USER' => 'dbcloner',
-        'DB_PASSWORD' => 'wWZ4hYcrmHLW2mUK',
-        'FRAMES_BASE_URI' => 'https://frames.opentalent.fr'
-    ];
-
     public static function get($varname) {
-        if (!array_key_exists($varname, self::DEFAULT)) {
-            throw new \RuntimeException('Unexisting environment variable requested: ' . $varname);
+        if (!array_key_exists($varname, $GLOBALS['OT'])) {
+            throw new \RuntimeException('Unexisting OT environment variable requested: ' . $varname);
         }
-        return $GLOBALS['OT'][$varname] ?? self::DEFAULT[$varname];
+        return $GLOBALS['OT'][$varname];
     }
 }

+ 16 - 0
ot_core/ext_localconf.php

@@ -30,3 +30,19 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Backend\Middleware\Backe
 
 
 $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['createDemandObjectFromSettings'] = ['Opentalent\OtTemplating\News\NewsFilter->createDemandObjectFromSettings'];
+
+// Opentalent environment variables
+// An array containing all or part of these variables could have been set in AdditionalConfiguration.php,
+// in this case we merge them so the predefined vars are not overriden.
+// (do not forget to clear the cache after any update there)
+$GLOBALS['OT'] = array_merge([
+    'API_BASE_URI' => 'https://api.opentalent.fr',
+    'DB_HOST' => 'prod-back',
+    'DB_USER' => 'dbcloner',
+    'DB_PASSWORD' => 'wWZ4hYcrmHLW2mUK',
+    'FRAMES_BASE_URI' => 'https://frames.opentalent.fr',
+    'WEBSITE' => 'https://opentalent.fr',
+    'DASHBOARD_URL' => 'https://admin.opentalent.fr/#/dashboard',
+    'LOGIN_PAGE_URL' => 'https://admin.opentalent.fr/#/login',
+    'FILE_STORAGE_URL' => 'https://api.opentalent.fr/app.php/_internal/secure/files/'
+], ($GLOBALS['OT'] ?? []));

+ 0 - 6
ot_templating/Configuration/TypoScript/constants.txt

@@ -11,14 +11,8 @@ plugin.tx_ottemplating {
     }
     settings {
         opentalent {
-            website = https://opentalent.fr
             logoPath = EXT:ot_templating/Resources/Public/media/logo-opentalent.png
-            fileStorageUrl = https://api.opentalent.fr/app.php/_internal/secure/files/
-            dashboardUrl = https://admin.opentalent.fr/#/dashboard
-            loginPageUrl = https://admin.opentalent.fr/#/login
-            logoutUrl = .
         }
-
         organization {
             # >> Ces paramètres doivent être redéfinis dans le gabarit du site
             id = 0

+ 0 - 6
ot_templating/Configuration/TypoScript/setup.txt

@@ -76,12 +76,7 @@ plugin.tx_ottemplating {
         layoutRootPaths.0 = {$layoutRootPath}
     }
     settings {
-        opentalentWebsite = {$plugin.tx_ottemplating.settings.opentalent.website}
         opentalentLogoPath = {$plugin.tx_ottemplating.settings.opentalent.logoPath}
-        opentalentFileStorageUrl = {$plugin.tx_ottemplating.settings.opentalent.fileStorageUrl}
-        opentalentDashboardUrl = {$plugin.tx_ottemplating.settings.opentalent.dashboardUrl}
-        opentalentLoginPageUrl = {$plugin.tx_ottemplating.settings.opentalent.loginPageUrl}/{$plugin.tx_ottemplating.settings.organization.id}
-        opentalentLogoutUrl = {$plugin.tx_ottemplating.settings.opentalent.logoutUrl}
         structureId = {$plugin.tx_ottemplating.settings.organization.id}
         structureLogoId = {$plugin.tx_ottemplating.settings.organization.logoid}
         structureName = {$plugin.tx_ottemplating.settings.organization.name}
@@ -110,7 +105,6 @@ plugin.tx_ottemplating {
         staticDonors = {$plugin.tx_ottemplating.settings.donors.static}
         eventsLimit = {$plugin.tx_ottemplating.settings.events.limit}
         eventsPeriod = {$plugin.tx_ottemplating.settings.events.period}
-
     }
 }
 

+ 1 - 1
ot_templating/Resources/Private/Partials/Classic/Footer.html

@@ -50,7 +50,7 @@
     </ul>
 
     <div class="logo-ot">
-        <a href="{settings.opentalentWebsite}" target="_blank" title="Opentalent">
+        <a href="{ot:request.getOtEnvVar(argument: 'WEBSITE')}" target="_blank" title="Opentalent">
             <f:image src="EXT:ot_templating/Resources/Public/media/logo-opentalent.png" height="40" />
         </a>
     </div>

+ 2 - 2
ot_templating/Resources/Private/Partials/Classic/UserToolbar.html

@@ -17,7 +17,7 @@
 
                 <ul class="dropdown-menu">
                     <li>
-                        <a href="{settings.opentalentDashboardUrl}" target="_blank">
+                        <a href="{ot:request.getOtEnvVar(argument: 'DASHBOARD_URL')}" target="_blank">
                             <f:translate key="member-area-of-my-structure"/>
                         </a>
                     </li>
@@ -75,7 +75,7 @@
 
                 </f:then>
                 <f:else>
-                    <a href="{settings.opentalentLoginPageUrl}" target="_blank">
+                    <a href="{ot:request.getOtEnvVar(argument: 'LOGIN_PAGE_URL')}" target="_blank">
                         <i class="fas fa-power-off"></i> <f:translate key="login"/>
                     </a>
                 </f:else>

+ 1 - 1
ot_templating/Resources/Private/Partials/Modern/Modals.html

@@ -131,7 +131,7 @@
             </div>
             <div class="modal-footer">
                 <button type="button" class="button gray" data-dismiss="modal">Fermer</button>
-                <a href="{settings.opentalentWebsite}" class="button opentalent-bg no-border" target="_blank">opentalent.fr</a>
+                <a href="{ot:request.getOtEnvVar(argument: 'WEBSITE')}" class="button opentalent-bg no-border" target="_blank">opentalent.fr</a>
             </div>
         </div>
     </div>

+ 2 - 2
ot_templating/Resources/Private/Partials/Modern/UserToolbar.html

@@ -12,7 +12,7 @@
                 <span><f:translate key="welcome"/> <b>{feuser.username}</b>!</span>
             </li>
             <li>
-                <a href="{settings.opentalentDashboardUrl}">
+                <a href="{ot:request.getOtEnvVar(argument: 'DASHBOARD_URL')}">
                     <f:translate key="member-area-of-my-structure"/>
                 </a>
             </li>
@@ -36,7 +36,7 @@
                         </a>
                     </f:then>
                     <f:else>
-                        <a href="{settings.opentalentLoginPageUrl}"
+                        <a href="{ot:request.getOtEnvVar(argument: 'LOGIN_PAGE_URL')}"
                            target="_blank"
                            class="{f:if(condition: '{ot:loginFailed()}', then: 'trigger-on-load')}"
                         >