Skip to content

Commit 6f059db

Browse files
ioigoumetvdijenmonkeyiq
committed
Clear caches script and hook (simplesamlphp#2410)
I am not 100% sure about the saml module enable. I thought I would err on the side of caution leaving it in from the cherry pick. * Clear caches script and hooke * Use symofony cache:clear for each module and core * Overrirde CacheClear Symfony Command * Github Actions: Create the cache directory. * Fixing simplesamlphp cache directory * Fixing chmod permissions * Fix phpcs issues * Fix indentation * config.php.dist file * config.php.dist file * Fix failing test after adding the config.php file * Fix failing test after adding the config.php file * Clear more caches during update. Clear the symfony cache to make sure that the ssp-clear command can be found Using the name "clear-cache" for this script also gave the warning ``` A script named clear-cache would override a Composer command and has been skipped ``` * Update the docs to be more of a strong recommendation If we are playing with the cache from composer we really want to encourage the user to setup that var directory the way that symfony are wanting it to be setup. * Include .php.dist files in the sniffer * Revert previous --------- Co-authored-by: Tim van Dijen <tvdijen@gmail.com> Co-authored-by: Ben Martin <monkeyiq@users.sourceforge.net>
1 parent f48838c commit 6f059db

8 files changed

Lines changed: 363 additions & 10 deletions

File tree

.github/workflows/php.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ jobs:
6464

6565
- uses: actions/checkout@v4
6666

67+
- name: Copy config.php.dist to config.php
68+
run: cp config/config.php.dist config/config.php
69+
70+
- name: Create SimpleSAMLphp cache directory
71+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
72+
6773
- name: Get composer cache directory
6874
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
6975

@@ -142,6 +148,12 @@ jobs:
142148

143149
- uses: actions/checkout@v4
144150

151+
- name: Copy config.php.dist to config.php
152+
run: cp config/config.php.dist config/config.php
153+
154+
- name: Create SimpleSAMLphp cache directory
155+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
156+
145157
- name: Get composer cache directory
146158
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
147159

@@ -199,6 +211,12 @@ jobs:
199211
200212
- uses: actions/checkout@v4
201213

214+
- name: Copy config.php.dist to config.php
215+
run: cp config/config.php.dist config/config.php
216+
217+
- name: Create SimpleSAMLphp cache directory
218+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
219+
202220
- name: Get composer cache directory
203221
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
204222

@@ -273,7 +291,7 @@ jobs:
273291
restore-keys: ${{ runner.os }}-composer-
274292

275293
- name: Install Composer dependencies
276-
run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix
294+
run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix --no-scripts
277295

278296
- name: Run unit tests
279297
run: vendor/bin/phpunit --no-coverage

composer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@
138138
},
139139
"scripts": {
140140
"translations:unused": "php bin/translations translations:unused",
141-
"translations:update:translatable": "php bin/translations translations:update:translatable"
142-
}
141+
"translations:update:translatable": "php bin/translations translations:update:translatable",
142+
"clear-symfony-cache": [
143+
"php bin/console cache:clear --no-warmup",
144+
"php bin/console ssp-cache:clear --no-warmup"
145+
],
146+
"post-update-cmd": [
147+
"@clear-symfony-cache",
148+
"echo 'Post-update tasks completed!'"
149+
],
150+
"post-install-cmd": [
151+
"@clear-symfony-cache",
152+
"echo 'Post-install tasks completed!'"
153+
]
154+
},
143155
}

config/config.php.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ $config = [
568568

569569
'module.enable' => [
570570
'admin' => true,
571+
'saml' => true,
571572
],
572573

573574

@@ -829,7 +830,7 @@ $config = [
829830
'language.available' => [
830831
'en', 'no', 'nn', 'se', 'da', 'de', 'sv', 'fi', 'es', 'ca', 'fr', 'it', 'nl', 'lb',
831832
'cs', 'sk', 'sl', 'lt', 'hr', 'hu', 'pl', 'pt', 'pt_BR', 'tr', 'ja', 'zh', 'zh_TW',
832-
'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st'
833+
'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st',
833834
],
834835
'language.rtl' => ['ar', 'dv', 'fa', 'ur', 'he'],
835836
'language.default' => 'en',

docs/simplesamlphp-install-repo.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,28 @@ cp metadata/saml20-idp-remote.php.dist metadata/saml20-idp-remote.php
3737
cp metadata/saml20-sp-remote.php.dist metadata/saml20-sp-remote.php
3838
```
3939

40-
The default config.php has a setting `cachedir` which defaults to
41-
`/var/cache/simplesamlphp`. This directory should exist and be
42-
writable by the web server user. You may like to consider something
40+
SimpleSAMLphp uses Symfony to maintain a cache which is by default stored
41+
at `/var/cache/simplesamlphp`. You are encouraged to consider something
4342
like the ACL commands from the [Symfony
4443
website](https://symfony.com/doc/current/setup/file_permissions.html#1-using-acl-on-a-system-that-supports-setfacl-linux-bsd)
4544
to enable access to this cache directory.
4645

46+
The cache directory is stored at the location indicated by the
47+
`cachedir` option in your config.php (defaulting to
48+
`/var/cache/simplesamlphp`). This directory should exist and be
49+
writable by the web server user and the user you use to run composer.
50+
51+
Some commands which may be run from composer will want to clear this
52+
cache which leads to a situation that the cache directory will need
53+
permission to be updated by both the web server and also from your
54+
regular user account that you use to checkout the git repository and
55+
run composer.
56+
57+
This is why it is recommended to use the solution provided on the
58+
[Symfony
59+
website](https://symfony.com/doc/current/setup/file_permissions.html#1-using-acl-on-a-system-that-supports-setfacl-linux-bsd)
60+
linked above to enable access to this cache directory.
61+
4762
Install the external dependencies with Composer (you can refer to
4863
[getcomposer.org](https://getcomposer.org/) to get detailed
4964
instructions on how to install Composer itself):

phpcs.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
</description>
88

99
<file>bin</file>
10-
<file>config</file>
11-
<file>metadata</file>
1210
<file>modules</file>
1311
<file>public</file>
1412
<file>src</file>

routing/services/console.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ services:
44
# default configuration for services in *this* file
55
_defaults:
66
public: false
7+
8+
SimpleSAML\Command\SspCacheClearCommand:
9+
tags: ['console.command']
10+
arguments:
11+
$cacheClearer: '@cache_clearer'
12+
$filesystem: '@filesystem'

0 commit comments

Comments
 (0)