This commit is contained in:
Pek5892 2023-09-12 12:04:50 +02:00
parent 4f7f6114e9
commit 4a203a7613
7 changed files with 75 additions and 16 deletions

View File

@ -127,6 +127,17 @@ class Check extends Model
}
*/
/**
* Rimuove tutte le check di un determinato modulo/plugin e record.
*
* @param array $data
*/
public static function deleteLinked($data)
{
database()->delete('zz_checks', $data);
}
/* Relazioni Eloquent */
public function user()

View File

@ -176,6 +176,25 @@ class Mail extends Model
$this->attributes['content'] = $value;
}
/**
* Rimuove tutte le mail di un determinato modulo/plugin e record.
*
* @param array $data
*/
public static function deleteLinked($data)
{
$templates = database()->table('em_templates')->where('id_module', $data['id_module'])->get();
$id_templates = [];
foreach($templates as $template) {
$id_templates[] = $template->id;
}
database()->table('em_emails')->where('id_record', $data['id_record'])->whereIn('id_template', $id_templates)->delete();
}
/* Relazioni Eloquent */
public function account()

View File

@ -346,12 +346,6 @@ switch ($op) {
// Azzeramento collegamento della rata contrattuale alla pianificazione
$dbo->query('UPDATE co_fatturazione_contratti SET iddocumento=0 WHERE iddocumento='.prepare($id_record));
// Eliminazione allegati collegati
Uploads::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
]);
flash()->info(tr('Fattura eliminata!'));
} catch (InvalidArgumentException $e) {
flash()->error(tr('Sono stati utilizzati alcuni serial number nel documento: impossibile procedere!'));

View File

@ -398,11 +398,6 @@ switch (post('op')) {
// Eliminazione associazione interventi e my_impianti
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
// Elimino anche eventuali file caricati
Uploads::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
]);
flash()->info(tr('Intervento eliminato!'));
} catch (InvalidArgumentException $e) {

View File

@ -289,11 +289,6 @@ switch (post('op')) {
// Eliminazione associazione interventi e my_impianti
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
// Elimino anche eventuali file caricati
Uploads::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
]);
} catch (InvalidArgumentException $e) {
}
}

View File

@ -266,6 +266,40 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
$riga->delete();
}
// Elimino eventuali file caricati
\Uploads::deleteLinked([
'id_module' => $this->getModule()->id,
'id_record' => $this->id,
]);
// Elimino eventuali note
\Models\Note::deleteLinked([
'id_module' => $this->getModule()->id,
'id_record' => $this->id,
]);
// Elimino eventuali checklist
\Modules\Checklists\Check::deleteLinked([
'id_module' => $this->getModule()->id,
'id_record' => $this->id,
]);
// Elimino eventuali email
\Modules\Emails\Mail::deleteLinked([
'id_module' => $this->getModule()->id,
'id_record' => $this->id,
]);
// Elimino eventuali campi personalizzati
$fields = database()->table('zz_fields')->where('id_module', $this->getModule()->id)->get();
$id_fields = [];
foreach($fields as $field) {
$id_fields[] = $field->id;
}
database()->table('zz_field_record')->where('id_record', $this->id)->whereIn('id_field', $id_fields)->delete();
return parent::delete();
}

View File

@ -60,6 +60,17 @@ class Note extends Model
return $model;
}
/**
* Rimuove tutte le note di un determinato modulo/plugin e record.
*
* @param array $data
*/
public static function deleteLinked($data)
{
database()->delete('zz_notes', $data);
}
/* Relazioni Eloquent */
public function user()