|
45 | 45 | $attachments_filenames = array_column($attachments, 'filename'); |
46 | 46 |
|
47 | 47 | foreach ($files as $file) { |
48 | | - echo $file; |
49 | 48 | $filename = basename($file); |
50 | | - rename($file, $new_folder.$filename); |
| 49 | + // Sposta solo i file che hanno un record corrispondente nella tabella zz_files |
| 50 | + if (in_array($filename, $attachments_filenames)) { |
| 51 | + echo "Spostamento file: " . $file . " -> " . $new_folder.$filename . "\n"; |
| 52 | + rename($file, $new_folder.$filename); |
| 53 | + } |
51 | 54 | } |
52 | 55 |
|
| 56 | +$module = Models\Module::where('name', 'Fatture di vendita')->first(); |
| 57 | +$directory = 'files/fatture/'; |
| 58 | +$files = glob($directory.'*.{xml,pdf}', GLOB_BRACE); |
| 59 | +$new_folder = 'files/'.$module->attachments_directory.'/'; |
| 60 | +directory($new_folder); |
| 61 | + |
| 62 | +$attachments = database()->fetchArray('SELECT `filename` FROM `zz_files` WHERE `id_module` = '.$module->id); |
| 63 | +$attachments_filenames = array_column($attachments, 'filename'); |
| 64 | + |
| 65 | +foreach ($files as $file) { |
| 66 | + $filename = basename($file); |
| 67 | + // Sposta solo i file che hanno un record corrispondente nella tabella zz_files |
| 68 | + if (in_array($filename, $attachments_filenames)) { |
| 69 | + echo "Spostamento file: " . $file . " -> " . $new_folder.$filename . "\n"; |
| 70 | + rename($file, $new_folder.$filename); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | + |
53 | 75 | // Verifica presenza conti |
54 | 76 | $conti_speciali_livello2 = [ |
55 | 77 | 'Conti transitori' => [ |
|
0 commit comments