diff options
author | polo <ordipolo@gmx.fr> | 2025-08-22 15:19:06 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-08-22 15:19:06 +0200 |
commit | b02b44d1da7e9ddd7a341d29a597accfbb78155c (patch) | |
tree | 2e5761c2295d4102a336d940c90f3e07f1d27835 /bin/copy_directory.php | |
parent | 72087acf0a7e5947a01314621e18b22b5b878919 (diff) | |
download | cms-b02b44d1da7e9ddd7a341d29a597accfbb78155c.zip |
Amélioration de copy_directory.phpmain
Diffstat (limited to 'bin/copy_directory.php')
-rw-r--r-- | bin/copy_directory.php | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/bin/copy_directory.php b/bin/copy_directory.php index 2c001c0..20e4821 100644 --- a/bin/copy_directory.php +++ b/bin/copy_directory.php | |||
@@ -1,11 +1,18 @@ | |||
1 | <?php | 1 | <?php |
2 | // bin/copy_directory.php | 2 | // bin/copy_directory.php |
3 | // | 3 | // |
4 | // appel dans le composer.json | 4 | // usage : php bin/copy_directory.php source destination |
5 | // appel dans le composer.json à l'intallation et lors des MAJ | ||
5 | 6 | ||
6 | function copyDirectory($source, $destination) { | 7 | function copyDirectory(string $source, string $destination): void |
7 | if (!is_dir($destination)) { | 8 | { |
8 | mkdir($destination, 0777, true); | 9 | if (!is_dir($source)) { |
10 | fwrite(STDERR, "Erreur rencontrée dans bin/copy_directory.php: le dossier source '$source' n'est pas un répertoire valide.\n"); | ||
11 | exit(1); | ||
12 | } | ||
13 | |||
14 | if(!is_dir($destination)){ | ||
15 | mkdir($destination, 0755, true); | ||
9 | } | 16 | } |
10 | 17 | ||
11 | $iterator = new RecursiveIteratorIterator( | 18 | $iterator = new RecursiveIteratorIterator( |
@@ -13,13 +20,21 @@ function copyDirectory($source, $destination) { | |||
13 | RecursiveIteratorIterator::SELF_FIRST | 20 | RecursiveIteratorIterator::SELF_FIRST |
14 | ); | 21 | ); |
15 | 22 | ||
16 | foreach ($iterator as $item) { | 23 | foreach($iterator as $item){ |
17 | if ($item->isDir()) { | 24 | $targetPath = $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName(); |
18 | mkdir($destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); | 25 | if($item->isDir()){ |
19 | } else { | 26 | if(!is_dir($targetPath)){ |
20 | copy($item, $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); | 27 | mkdir($targetPath, 0755); |
28 | } | ||
29 | } | ||
30 | else{ | ||
31 | copy($item, $targetPath); // copy() écrase la cible, c'est ce qu'on veut | ||
21 | } | 32 | } |
22 | } | 33 | } |
23 | } | 34 | } |
24 | 35 | ||
36 | if ($argc != 3){ // nombre de paramètres | ||
37 | fwrite(STDERR, "Erreur rencontrée dans bin/copy_directory.php. Usage:\nphp bin/copy_directory.php <source> <destination>\n"); | ||
38 | exit(1); | ||
39 | } | ||
25 | copyDirectory($argv[1], $argv[2]); | 40 | copyDirectory($argv[1], $argv[2]); |