Merge pull request #22297 from civicrm/5.45
[civicrm-core.git] / tools / scripts / composer / pear-exception-fix.sh
1 #!/bin/bash
2
3 ## Cleanup the vendor tree. The main issue here is that civi Civi is
4 ## deployed as a module inside a CMS, so all its source-code gets published.
5 ## Some libraries distribute admin tools and sample files which should not
6 ## be published.
7 ##
8 ## This script should be idempotent -- if you rerun it several times, it
9 ## should always produce the same post-condition.
10
11 ## Replace a line in a file
12 ## This is a bit like 'sed -i', but dumber and more cross-platform.
13 function simple_replace() {
14 php -r 'file_put_contents($argv[1], preg_replace($argv[2], $argv[3], file_get_contents($argv[1])));' "$@"
15 }
16
17
18 # add in class_exists test as per CRM-8921.
19 if ! grep -q 'CRM-8921' vendor/pear/pear_exception/PEAR/Exception.php; then
20 simple_replace vendor/pear/pear_exception/PEAR/Exception.php '^\<\?php^' '<?php if (class_exists("'"PEAR_Exception"'")) return; /* CRM-8921 */'
21 fi