Skip to content

Commit e6708e8

Browse files
ioigoumetvdijenmonkeyiq
authored
Clear caches script and hook (#2410)
* 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 b2c53b9 commit e6708e8

8 files changed

Lines changed: 363 additions & 11 deletions

File tree

.github/workflows/php.yml

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

5858
- uses: actions/checkout@v4
5959

60+
- name: Copy config.php.dist to config.php
61+
run: cp config/config.php.dist config/config.php
62+
63+
- name: Create SimpleSAMLphp cache directory
64+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
65+
6066
- name: Get composer cache directory
6167
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
6268

@@ -123,6 +129,12 @@ jobs:
123129

124130
- uses: actions/checkout@v4
125131

132+
- name: Copy config.php.dist to config.php
133+
run: cp config/config.php.dist config/config.php
134+
135+
- name: Create SimpleSAMLphp cache directory
136+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
137+
126138
- name: Get composer cache directory
127139
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
128140

@@ -179,6 +191,12 @@ jobs:
179191
180192
- uses: actions/checkout@v4
181193

194+
- name: Copy config.php.dist to config.php
195+
run: cp config/config.php.dist config/config.php
196+
197+
- name: Create SimpleSAMLphp cache directory
198+
run: sudo mkdir -p /var/cache/simplesamlphp && sudo chmod 777 /var/cache/simplesamlphp
199+
182200
- name: Get composer cache directory
183201
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
184202

@@ -252,7 +270,7 @@ jobs:
252270
restore-keys: ${{ runner.os }}-composer-
253271

254272
- name: Install Composer dependencies
255-
run: composer install --no-progress --prefer-dist --optimize-autoloader
273+
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-scripts
256274

257275
- name: Run unit tests
258276
run: ./vendor/bin/phpunit --no-coverage

composer.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,19 @@
128128
},
129129
"scripts": {
130130
"translations:unused": "php bin/translations translations:unused",
131-
"translations:update:translatable": "php bin/translations translations:update:translatable"
131+
"translations:update:translatable": "php bin/translations translations:update:translatable",
132+
"clear-symfony-cache": [
133+
"php bin/console cache:clear --no-warmup",
134+
"php bin/console ssp-cache:clear --no-warmup"
135+
],
136+
"post-update-cmd": [
137+
"@clear-symfony-cache",
138+
"echo 'Post-update tasks completed!'"
139+
],
140+
"post-install-cmd": [
141+
"@clear-symfony-cache",
142+
"echo 'Post-install tasks completed!'"
143+
]
132144
},
133145
"version": "v2.4.0"
134146
}

config/config.php.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $config = [
5858
/*
5959
* The following settings are *filesystem paths* which define where
6060
* SimpleSAMLphp can find or write the following things:
61-
* - 'cachedir': Where SimpleSAMLphp can write its cache.
61+
* - 'cachedir': Where SimpleSAMLphp can write its cache.
6262
* - 'loggingdir': Where to write logs. MUST be set to NULL when using a logging
6363
* handler other than `file`.
6464
* - 'datadir': Storage of general data.
@@ -564,7 +564,7 @@ $config = [
564564
'exampleauth' => false,
565565
'core' => true,
566566
'admin' => true,
567-
'saml' => true
567+
'saml' => true,
568568
],
569569

570570

@@ -826,7 +826,7 @@ $config = [
826826
'language.available' => [
827827
'en', 'no', 'nn', 'se', 'da', 'de', 'sv', 'fi', 'es', 'ca', 'fr', 'it', 'nl', 'lb',
828828
'cs', 'sk', 'sl', 'lt', 'hr', 'hu', 'pl', 'pt', 'pt_BR', 'tr', 'ja', 'zh', 'zh_TW',
829-
'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st'
829+
'ru', 'et', 'he', 'id', 'sr', 'lv', 'ro', 'eu', 'el', 'af', 'zu', 'xh', 'st',
830830
],
831831
'language.rtl' => ['ar', 'dv', 'fa', 'ur', 'he'],
832832
'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)