Skip to content

refactor deployment#610

Merged
simonLeary42 merged 4 commits intomainfrom
refactor-overrides
Apr 6, 2026
Merged

refactor deployment#610
simonLeary42 merged 4 commits intomainfrom
refactor-overrides

Conversation

@simonLeary42
Copy link
Copy Markdown
Member

@simonLeary42 simonLeary42 commented Feb 11, 2026

This PR adds support for domain-specific mail and templates.

old structure:

defaults/
    config/
        config.ini.default
deployment/
    config/
        config.ini
    custom_user_mappings/
        example.csv
    mail_overrides/
        example.php
    templates_overrides/
        example.php
    overrides/
        foobar/
            config/
                config.ini

new structure:

deployment/
    config.base.ini
    config.ini
    custom_user_mappings/
        example.csv
    mail/
        example.php
    templates/
        example.php
    domain_overrides/
        foobar/
            config.ini
            mail/
                example.php
            templates/
                example.php

In the new structure, the redundant config/ directories are removed, and deployment/mail deployment/templates have matching names to resources/mail resources/templates.

  • renamed UnityConfig to UnityDeployment
  • moved custom ID mapping getter from UnityLDAP to UnityDeployment

Moved Functions

show_func() { awk '/function '"$1"'/{on=1} on && /^[[:space:]]*$/{exit} on{print}'; }

getTemplatePath

$ diff -bu <(git show origin/main:resources/lib/utils.php | show_func getTemplatePath) <(cat ./resources/lib/UnityDeployment.php | show_func getTemplatePath)
--- /dev/fd/63	2026-04-06 10:06:45
+++ /dev/fd/62	2026-04-06 10:06:45
@@ -1,9 +1,20 @@
-function getTemplatePath(string $basename): string
-{
-    $template_path = __DIR__ . "/../templates/$basename";
-    $override_path = __DIR__ . "/../../deployment/templates_overrides/$basename";
-    if (file_exists($override_path)) {
-        return $override_path;
+    public static function getTemplatePath(string $basename): string
+    {
+        $deployment = __DIR__ . "/../../deployment/";
+        if (($host = $_SERVER["HTTP_HOST"] ?? null) !== null) {
+            $domain_override_template = "$deployment/domain_overrides/$host/templates/$basename";
+            if (file_exists($domain_override_template)) {
+                return $domain_override_template;
     }
-    return $template_path;
-}
+        }
+        $deployment_template = "$deployment/templates/$basename";
+        if (file_exists($deployment_template)) {
+            return $deployment_template;
+        }
+        $output = __DIR__ . "/../templates/$basename";
+        if (file_exists($output)) {
+            return $output;
+        } else {
+            throw new \Exception("no such template: '$basename'");
+        }
+    }

getCustomIDMappings

$ diff -bu <(git show origin/main:resources/lib/UnityLDAP.php | show_func getCustomIDMappings) <(cat ./resources/lib/UnityDeployment.php | show_func getCustomIDMappings) | delta
--- /dev/fd/63  2026-04-06 10:16:17
+++ /dev/fd/62  2026-04-06 10:16:17
@@ -1,10 +1,14 @@
-    private function getCustomIDMappings(): array
+    public static function getCustomIDMappings(): array
     {
         $output = [];
-        $dir = new \DirectoryIterator($this->custom_mappings_path);
+        $dir_path = __DIR__ . "/../../" . CONFIG["ldap"]["custom_user_mappings_dir"];
+        if (!is_dir($dir_path)) {
+            throw new \Exception("custom_user_mappings directory '$dir_path' is not a directory");
+        }
+        $dir = new \DirectoryIterator($dir_path);
         foreach ($dir as $fileinfo) {
             $filename = $fileinfo->getFilename();
-            if ($fileinfo->isDot() || $filename == "README.md") {
+            if ($fileinfo->isDot()) {
                 continue;
             }
             if ($fileinfo->getExtension() !== "csv") {
@@ -19,7 +23,7 @@
                         assert(count($row) === 2);
                         assert(is_string($row[1]));
                         assert(ctype_digit($row[1]));
-                    } catch (\AssertionError $e) {
+                    } catch (AssertionError $e) {
                         throw new \Exception("bad ID mapping $filename row $i", previous: $e);
                     }
                     $output[$row[0]] = digits2int($row[1]);
@@ -30,4 +34,5 @@
             }
         }
         return $output;
-    }
+    }
+}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the deployment structure to support domain-specific configurations for templates, mail, and custom user mappings. The refactoring consolidates the UnityConfig class into a new UnityDeployment class that handles all deployment-related path resolution and configuration management.

Changes:

  • Replaced UnityConfig class with UnityDeployment class that provides unified methods for resolving templates, mail templates, custom ID mappings, and configuration files with domain-specific override support
  • Restructured the deployment directory from separate overrides/, mail_overrides/, and templates_overrides/ directories to a unified domain_overrides/<domain>/ structure
  • Updated all template and mail path references throughout the codebase to use the new UnityDeployment::getTemplatePath() and UnityDeployment::getMailPath() methods

Reviewed changes

Copilot reviewed 26 out of 31 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
resources/lib/UnityDeployment.php New class that consolidates deployment configuration and path resolution logic with domain-specific override support
resources/lib/UnityConfig.php Removed old configuration class
resources/lib/UnityLDAP.php Removed custom ID mappings logic (moved to UnityDeployment); removed unused RuntimeException import
resources/lib/UnityMailer.php Updated to use UnityDeployment::getMailPath() for mail template resolution
resources/lib/utils.php Removed getTemplatePath() function (moved to UnityDeployment)
resources/config.php Simplified to use UnityDeployment::getConfig() instead of UnityConfig
resources/autoload.php Updated to load UnityDeployment instead of UnityConfig
test/phpunit-bootstrap.php Updated to load UnityDeployment instead of UnityConfig
webroot/index.php Updated all template includes to use UnityDeployment::getTemplatePath()
webroot/panel/*.php Updated all template includes to use UnityDeployment::getTemplatePath()
webroot/admin/*.php Updated all template includes to use UnityDeployment::getTemplatePath()
deployment/README.md New comprehensive documentation for the deployment directory structure
deployment/config.base.ini Moved from defaults/config/config.ini.default and removed obsolete custom_user_mappings_dir setting
deployment/templates/example.php Example placeholder for deployment-specific templates
deployment/mail/example.php Example placeholder for deployment-specific mail templates
deployment/templates_overrides/README.md Removed (replaced by deployment/README.md)
deployment/mail_overrides/README.md Removed (replaced by deployment/README.md)
deployment/overrides/README.md Removed (replaced by deployment/README.md)
deployment/config/README.md Removed (replaced by deployment/README.md)
deployment/custom_user_mappings/README.md Removed (replaced by deployment/README.md)
deployment/domain_overrides/*/config.ini Updated domain-specific configurations to new structure
deployment/domain_overrides/phpunit/custom_user_mappings/test.csv Moved from test/custom_user_mappings/
.gitignore Simplified to ignore only deployment/config/config.ini (but contains a bug - path is incorrect)
.pre-commit-config.yaml Removed resources/config.php from exclusion list as it's now properly formatted

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread resources/lib/UnityDeployment.php Outdated
Comment thread resources/lib/UnityDeployment.php
Comment thread resources/lib/UnityDeployment.php Outdated
Comment thread resources/lib/UnityDeployment.php Outdated
Comment thread resources/lib/UnityDeployment.php Outdated
Comment thread resources/lib/UnityDeployment.php
Comment thread resources/lib/UnityDeployment.php Outdated
Comment thread resources/lib/UnityDeployment.php Outdated
@simonLeary42 simonLeary42 force-pushed the refactor-overrides branch 5 times, most recently from d085b95 to c788d32 Compare February 11, 2026 15:45
@simonLeary42
Copy link
Copy Markdown
Member Author

simonLeary42 commented Mar 16, 2026

  • TODO make it so that development config overrides live under test/

@simonLeary42
Copy link
Copy Markdown
Member Author

simonLeary42 commented Apr 3, 2026

  • TODO: domain_overrides/phpunit/custom_user_mappings exists but custom_user_mappings do not automatically detect domain overrides

@simonLeary42
Copy link
Copy Markdown
Member Author

simonLeary42 commented Apr 3, 2026

TODO: update status.php for UnityDeployment::getTemplatePath

@simonLeary42 simonLeary42 force-pushed the refactor-overrides branch 3 times, most recently from 19bffe5 to 4a28aa0 Compare April 3, 2026 20:50
@simonLeary42
Copy link
Copy Markdown
Member Author

TODO can we have a test case for domain override template / mail?

@simonLeary42 simonLeary42 force-pushed the refactor-overrides branch 10 times, most recently from bd9847e to 5f4a085 Compare April 6, 2026 13:59
rename UnityConfig -> UnityDeployment

no more readme file in custom_user_mappings/

UnityDeployment::

mail_overrides -> mail

fix missing phpunit custom user mappings file

remove custom user mappings from deployment readme

change back location of phpunit custom user mappings

mail templates are .html.twig now

remove duplicate line from gitignore

remove unused gitignore

changelog

remove unnecessary gitignore

sort

remove more, sort more

update changelog

UnityMailer accept domain override mail

fclose

named argument

fix pathnames

no config/

look for mail in mail/

condense code

?: -> ??

reorder .gitignore

put back util

reorder functions

revert
@simonLeary42 simonLeary42 marked this pull request as ready for review April 6, 2026 14:36
@simonLeary42 simonLeary42 merged commit d9aa506 into main Apr 6, 2026
3 checks passed
@simonLeary42 simonLeary42 deleted the refactor-overrides branch April 6, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants