Skip to content

Commit ccee57c

Browse files
committed
fix: spostamento allegati fatture
1 parent 1d5a609 commit ccee57c

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

update/2_8.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,33 @@
4545
$attachments_filenames = array_column($attachments, 'filename');
4646

4747
foreach ($files as $file) {
48-
echo $file;
4948
$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+
}
5154
}
5255

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+
5375
// Verifica presenza conti
5476
$conti_speciali_livello2 = [
5577
'Conti transitori' => [

0 commit comments

Comments
 (0)