From 7b03a2f3e5a6f2efe96f334a9618fc838c1985d7 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 19 Jul 2019 16:51:52 +0200 Subject: [PATCH] Miglioramenti minori --- core.php | 15 +++++++++++++++ modules/anagrafiche/api/v1/Anagrafiche.php | 3 ++- modules/articoli/api/v1/Articoli.php | 3 ++- modules/articoli/api/v1/Movimenti.php | 3 ++- modules/interventi/api/v1/Articoli.php | 3 ++- modules/interventi/api/v1/Firma.php | 3 ++- modules/interventi/api/v1/Interventi.php | 3 ++- modules/interventi/api/v1/Sessioni.php | 9 +++++---- modules/interventi/api/v1/Sync.php | 7 ++++--- .../stati_contratto/api/v1/StatiContratti.php | 3 ++- .../api/v1/StatiInterventi.php | 3 ++- .../api/v1/StatiPreventivi.php | 3 ++- modules/stato_servizi/api/v1/FolderSize.php | 3 ++- .../tipi_intervento/api/v1/TipiInterventi.php | 3 ++- modules/utenti/api/v1/Login.php | 5 +++-- modules/utenti/api/v1/Logout.php | 5 +++-- src/API/Common/Allegato.php | 3 ++- src/API/Manager.php | 2 ++ src/API/Resource.php | 19 +++++++++++++++++++ update/2_4_11.sql | 1 - 20 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 src/API/Resource.php diff --git a/core.php b/core.php index c9f46becd..19d36896b 100644 --- a/core.php +++ b/core.php @@ -281,3 +281,18 @@ $list = array_merge($files, $custom_files); foreach ($list as $file) { include_once $file; } + +// Inclusione dei file vendor/autoload.php di Composer +$files = glob(__DIR__.'/{modules,plugins}/*/vendor/autoload.php', GLOB_BRACE); +$custom_files = glob(__DIR__.'/{modules,plugins}/*/custom/vendor/autoload.php', GLOB_BRACE); +foreach ($custom_files as $key => $value) { + $index = array_search(str_replace('custom/', '', $value), $files); + if ($index !== false) { + unset($files[$index]); + } +} + +$list = array_merge($files, $custom_files); +foreach ($list as $file) { + include_once $file; +} diff --git a/modules/anagrafiche/api/v1/Anagrafiche.php b/modules/anagrafiche/api/v1/Anagrafiche.php index a8e143552..3b448cf1d 100644 --- a/modules/anagrafiche/api/v1/Anagrafiche.php +++ b/modules/anagrafiche/api/v1/Anagrafiche.php @@ -6,10 +6,11 @@ use API\Interfaces\CreateInterface; use API\Interfaces\DeleteInterface; use API\Interfaces\RetrieveInterface; use API\Interfaces\UpdateInterface; +use API\Resource; use Modules; use Modules\Anagrafiche\Anagrafica; -class Anagrafiche implements RetrieveInterface, CreateInterface, UpdateInterface, DeleteInterface +class Anagrafiche extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface, DeleteInterface { public function retrieve($request) { diff --git a/modules/articoli/api/v1/Articoli.php b/modules/articoli/api/v1/Articoli.php index 42a2837d2..decb33bfc 100644 --- a/modules/articoli/api/v1/Articoli.php +++ b/modules/articoli/api/v1/Articoli.php @@ -3,8 +3,9 @@ namespace Modules\Articoli\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; -class Articoli implements RetrieveInterface +class Articoli extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/articoli/api/v1/Movimenti.php b/modules/articoli/api/v1/Movimenti.php index 8ccc29b60..d3dcc5db0 100644 --- a/modules/articoli/api/v1/Movimenti.php +++ b/modules/articoli/api/v1/Movimenti.php @@ -3,9 +3,10 @@ namespace Modules\Articoli\API\v1; use API\Interfaces\CreateInterface; +use API\Resource; use Modules\Articoli\Articolo; -class Movimenti implements CreateInterface +class Movimenti extends Resource implements CreateInterface { public function create($request) { diff --git a/modules/interventi/api/v1/Articoli.php b/modules/interventi/api/v1/Articoli.php index fd066cabc..2462ac12b 100644 --- a/modules/interventi/api/v1/Articoli.php +++ b/modules/interventi/api/v1/Articoli.php @@ -4,11 +4,12 @@ namespace Modules\Interventi\API\v1; use API\Interfaces\CreateInterface; use API\Interfaces\RetrieveInterface; +use API\Resource; use Modules\Articoli\Articolo as ArticoloOriginale; use Modules\Interventi\Components\Articolo; use Modules\Interventi\Intervento; -class Articoli implements RetrieveInterface, CreateInterface +class Articoli extends Resource implements RetrieveInterface, CreateInterface { public function retrieve($request) { diff --git a/modules/interventi/api/v1/Firma.php b/modules/interventi/api/v1/Firma.php index b28d4d2ab..26b28c5b9 100644 --- a/modules/interventi/api/v1/Firma.php +++ b/modules/interventi/api/v1/Firma.php @@ -3,8 +3,9 @@ namespace Modules\Interventi\API\v1; use API\Interfaces\UpdateInterface; +use API\Resource; -class Firma implements UpdateInterface +class Firma extends Resource implements UpdateInterface { public function update($request) { diff --git a/modules/interventi/api/v1/Interventi.php b/modules/interventi/api/v1/Interventi.php index 8cc147f44..a123fb709 100644 --- a/modules/interventi/api/v1/Interventi.php +++ b/modules/interventi/api/v1/Interventi.php @@ -5,12 +5,13 @@ namespace Modules\Interventi\API\v1; use API\Interfaces\CreateInterface; use API\Interfaces\RetrieveInterface; use API\Interfaces\UpdateInterface; +use API\Resource; use Modules\Anagrafiche\Anagrafica; use Modules\Interventi\Intervento; use Modules\Interventi\Stato; use Modules\TipiIntervento\Tipo as TipoSessione; -class Interventi implements RetrieveInterface, CreateInterface, UpdateInterface +class Interventi extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface { public function retrieve($request) { diff --git a/modules/interventi/api/v1/Sessioni.php b/modules/interventi/api/v1/Sessioni.php index 941ddae82..c3574ea04 100644 --- a/modules/interventi/api/v1/Sessioni.php +++ b/modules/interventi/api/v1/Sessioni.php @@ -5,12 +5,13 @@ namespace Modules\Interventi\API\v1; use API\Interfaces\CreateInterface; use API\Interfaces\DeleteInterface; use API\Interfaces\RetrieveInterface; +use API\Resource; -class Sessioni implements RetrieveInterface, CreateInterface, DeleteInterface +class Sessioni extends Resource implements RetrieveInterface, CreateInterface, DeleteInterface { public function retrieve($request) { - $user = auth()->getUser(); + $user = $this->getUser(); $query = 'SELECT id, idtecnico AS id_tecnico, idintervento AS id_intervento, orario_inizio, orario_fine FROM in_interventi_tecnici WHERE `idintervento` = :id_intervento'; @@ -31,7 +32,7 @@ class Sessioni implements RetrieveInterface, CreateInterface, DeleteInterface public function create($request) { - $user = auth()->getUser(); + $user = $this->getUser(); $data = $request['data']; add_tecnico($data['id_intervento'], $user['idanagrafica'], $data['orario_inizio'], $data['orario_fine']); @@ -40,7 +41,7 @@ class Sessioni implements RetrieveInterface, CreateInterface, DeleteInterface public function delete($request) { $database = database(); - $user = auth()->getUser(); + $user = $this->getUser(); $database->query('DELETE FROM `in_interventi_tecnici` WHERE `idintervento` = :id_intervento AND `idtecnico` = :id_tecnico', [ ':id_intervento' => $request['id_intervento'], diff --git a/modules/interventi/api/v1/Sync.php b/modules/interventi/api/v1/Sync.php index aa45628dd..06c6ee8c2 100644 --- a/modules/interventi/api/v1/Sync.php +++ b/modules/interventi/api/v1/Sync.php @@ -4,17 +4,18 @@ namespace Modules\Interventi\API\v1; use API\Interfaces\RetrieveInterface; use API\Interfaces\UpdateInterface; +use API\Resource; use Carbon\Carbon; use DateTime; use iCalEasyReader; use Update; -class Sync implements RetrieveInterface, UpdateInterface +class Sync extends Resource implements RetrieveInterface, UpdateInterface { public function retrieve($request) { $database = database(); - $user = auth()->getUser(); + $user = $this->getUser(); // Normalizzazione degli interventi a database $database->query('UPDATE in_interventi_tecnici SET summary = (SELECT ragione_sociale FROM an_anagrafiche INNER JOIN in_interventi ON an_anagrafiche.idanagrafica=in_interventi.idanagrafica WHERE in_interventi.id=in_interventi_tecnici.idintervento) WHERE summary IS NULL'); @@ -63,7 +64,7 @@ class Sync implements RetrieveInterface, UpdateInterface public function update($request) { $database = database(); - $user = auth()->getUser(); + $user = $this->getUser(); // Normalizzazione degli interventi a database $database->query('UPDATE in_interventi_tecnici SET summary = (SELECT ragione_sociale FROM an_anagrafiche INNER JOIN in_interventi ON an_anagrafiche.idanagrafica=in_interventi.idanagrafica WHERE in_interventi.id=in_interventi_tecnici.idintervento) WHERE summary IS NULL'); diff --git a/modules/stati_contratto/api/v1/StatiContratti.php b/modules/stati_contratto/api/v1/StatiContratti.php index ee2dc1f4b..10bc80bbf 100644 --- a/modules/stati_contratto/api/v1/StatiContratti.php +++ b/modules/stati_contratto/api/v1/StatiContratti.php @@ -3,8 +3,9 @@ namespace Modules\StatiContratto\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; -class StatiContratti implements RetrieveInterface +class StatiContratti extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/stati_intervento/api/v1/StatiInterventi.php b/modules/stati_intervento/api/v1/StatiInterventi.php index 247b57258..f335e3f18 100644 --- a/modules/stati_intervento/api/v1/StatiInterventi.php +++ b/modules/stati_intervento/api/v1/StatiInterventi.php @@ -3,8 +3,9 @@ namespace Modules\StatiIntervento\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; -class StatiInterventi implements RetrieveInterface +class StatiInterventi extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/stati_preventivo/api/v1/StatiPreventivi.php b/modules/stati_preventivo/api/v1/StatiPreventivi.php index 185ee2372..bb340a949 100644 --- a/modules/stati_preventivo/api/v1/StatiPreventivi.php +++ b/modules/stati_preventivo/api/v1/StatiPreventivi.php @@ -3,8 +3,9 @@ namespace Modules\StatiPreventivo\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; -class StatiPreventivi implements RetrieveInterface +class StatiPreventivi extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/stato_servizi/api/v1/FolderSize.php b/modules/stato_servizi/api/v1/FolderSize.php index 5ae29dd42..e339635f1 100644 --- a/modules/stato_servizi/api/v1/FolderSize.php +++ b/modules/stato_servizi/api/v1/FolderSize.php @@ -3,10 +3,11 @@ namespace Modules\StatoServizi\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; use App; use Util\FileSystem; -class FolderSize implements RetrieveInterface +class FolderSize extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/tipi_intervento/api/v1/TipiInterventi.php b/modules/tipi_intervento/api/v1/TipiInterventi.php index 69cf93f82..59edf2805 100644 --- a/modules/tipi_intervento/api/v1/TipiInterventi.php +++ b/modules/tipi_intervento/api/v1/TipiInterventi.php @@ -3,8 +3,9 @@ namespace Modules\TipiIntervento\API\v1; use API\Interfaces\RetrieveInterface; +use API\Resource; -class TipiInterventi implements RetrieveInterface +class TipiInterventi extends Resource implements RetrieveInterface { public function retrieve($request) { diff --git a/modules/utenti/api/v1/Login.php b/modules/utenti/api/v1/Login.php index 6838fe91b..d5b5acd8c 100644 --- a/modules/utenti/api/v1/Login.php +++ b/modules/utenti/api/v1/Login.php @@ -3,10 +3,11 @@ namespace Modules\Utenti\API\v1; use API\Interfaces\CreateInterface; +use API\Resource; use Auth; use Update; -class Login implements CreateInterface +class Login extends Resource implements CreateInterface { public function create($request) { @@ -14,7 +15,7 @@ class Login implements CreateInterface // Controllo sulle credenziali if (auth()->attempt($request['username'], $request['password'])) { - $user = auth()->getUser(); + $user = $this->getUser(); $token = auth()->getToken(); // Informazioni da restituire tramite l'API diff --git a/modules/utenti/api/v1/Logout.php b/modules/utenti/api/v1/Logout.php index 5a0852e2f..68a8fb95b 100644 --- a/modules/utenti/api/v1/Logout.php +++ b/modules/utenti/api/v1/Logout.php @@ -3,13 +3,14 @@ namespace Modules\Utenti\API\v1; use API\Interfaces\CreateInterface; +use API\Resource; -class Logout implements CreateInterface +class Logout extends Resource implements CreateInterface { public function create($request) { $database = database(); - $user = auth()->getUser(); + $user = $this->getUser(); if (!empty($request['token']) && !empty($user)) { // Cancellazione della chiave diff --git a/src/API/Common/Allegato.php b/src/API/Common/Allegato.php index 44df0f3ad..952f07c35 100644 --- a/src/API/Common/Allegato.php +++ b/src/API/Common/Allegato.php @@ -3,10 +3,11 @@ namespace Api\Common; use API\Interfaces\CreateInterface; +use API\Resource; use Modules; use Uploads; -class Allegato implements CreateInterface +class Allegato extends Resource implements CreateInterface { public function create($request) { diff --git a/src/API/Manager.php b/src/API/Manager.php index 44cb680c2..9fbe91141 100644 --- a/src/API/Manager.php +++ b/src/API/Manager.php @@ -186,7 +186,9 @@ class Manager $object = new $class(); $method = $this->type; + $object->open($request); $response = $object->{$method}($request); + $object->close($request, $response); return $response; } diff --git a/src/API/Resource.php b/src/API/Resource.php new file mode 100644 index 000000000..4147624fa --- /dev/null +++ b/src/API/Resource.php @@ -0,0 +1,19 @@ +getUser(); + } +} diff --git a/update/2_4_11.sql b/update/2_4_11.sql index a779d4c36..9b29694f5 100644 --- a/update/2_4_11.sql +++ b/update/2_4_11.sql @@ -111,4 +111,3 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e (NULL, 'v1', 'update', 'sessione_intervento', 'Modules\\Interventi\\API\\v1\\Sessioni', '1'), (NULL, 'v1', 'retrieve', 'articoli_intervento', 'Modules\\Interventi\\API\\v1\\Articoli', '1'), (NULL, 'v1', 'create', 'articolo_intervento', 'Modules\\Interventi\\API\\v1\\Articoli', '1'); -