openstamanager/update/2_4_11.php

93 lines
2.8 KiB
PHP
Raw Normal View History

2019-07-19 15:23:00 +02:00
<?php
2019-08-28 16:58:47 +02:00
// Correzione zz_operations
use Models\User;
2019-08-29 10:25:14 +02:00
use Modules\Emails\Mail;
use Modules\Emails\Template;
2019-08-28 16:58:47 +02:00
$database->query('ALTER TABLE `zz_operations` DROP FOREIGN KEY `zz_operations_ibfk_3`');
$logs = $database->fetchArray("SELECT * FROM `zz_operations` WHERE `op` = 'send-email'");
2019-10-15 16:28:48 +02:00
$database->query('UPDATE `zz_operations` SET `id_email` = NULL');
2019-08-28 16:58:47 +02:00
foreach ($logs as $log) {
$user = User::find($log['id_utente']);
2019-08-29 10:25:14 +02:00
$template = Template::find($log['id_email']);
2020-01-11 13:36:43 +01:00
if (empty($template)) {
continue;
}
2019-08-29 10:25:14 +02:00
2019-08-28 16:58:47 +02:00
$mail = Mail::build($user, $template, $log['id_record']);
2019-08-29 10:25:14 +02:00
$mail->resetPrints();
2019-08-28 16:58:47 +02:00
$options = json_decode($log['options'], true);
2019-08-29 10:25:14 +02:00
foreach ($options['receivers'] as $receiver) {
2019-08-28 16:58:47 +02:00
$mail->addReceiver($receiver);
}
2019-08-29 10:25:14 +02:00
foreach ($options['attachments'] as $upload) {
$mail->addUpload($upload);
}
foreach ($options['prints'] as $print) {
$mail->addPrint($print);
}
$sent_at = $log['created_at'] ?: date('Y-m-d H:i:s');
$mail->created_at = $sent_at;
$mail->sent_at = $sent_at;
2019-08-28 16:58:47 +02:00
$mail->save();
$database->query('UPDATE `zz_operations` SET `id_email` = '.prepare($mail->id).' WHERE `id_module` = '.prepare($log['id_module']).' AND `id_email` = '.prepare($log['id_email']).' AND `id_record` = '.prepare($log['id_record']).' AND `options` = '.prepare($log['options']).' AND `created_at` = '.prepare($log['created_at']));
}
$database->query('ALTER TABLE `zz_operations` ADD FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE SET NULL');
// Aggiunta permessi alla gestione documentale
$gruppi = $database->fetchArray('SELECT `id` FROM `zz_groups`');
$viste = $database->fetchArray('SELECT `id` FROM `do_categorie`');
$array = [];
foreach ($viste as $vista) {
foreach ($gruppi as $gruppo) {
$array[] = [
'id_gruppo' => $gruppo['id'],
'id_categoria' => $vista['id'],
];
}
}
if (!empty($array)) {
$database->insert('do_permessi', $array);
}
2019-07-19 15:23:00 +02:00
// File e cartelle deprecate
$files = [
'src/API.php',
'src/Mail.php',
'modules/utenti/api',
'modules/stato_servizi/api',
'modules/stati_preventivo/api',
'modules/stati_intervento/api',
'modules/tipi_intervento/api',
'modules/stati_contratto/api',
'modules/articoli/api',
'modules/anagrafiche/api',
'modules/interventi/api/update.php',
'modules/interventi/api/retrieve.php',
'modules/interventi/api/delete.php',
'modules/interventi/api/create.php',
'modules/aggiornamenti/api',
'plugins/exportFE/src/Connection.php',
'modules/contratti/plugins/contratti.ordiniservizio.interventi.php ',
'modules/contratti/plugins/contratti.ordiniservizio.php',
'templates/contratti_cons/body.php',
'templates/preventivi_cons/body.php',
2019-07-19 15:23:00 +02:00
];
foreach ($files as $key => $value) {
$files[$key] = realpath(base_dir().'/'.$value);
2019-07-19 15:23:00 +02:00
}
delete($files);