--- /dev/null
+<?php
+
+class AnonymousController extends ApplicationController {
+
+ public function verifIsLoggued() {
+ return true;
+ }
+
+ /** @var PdoApplianceManager */
+ private $pdoApplianceManager;
+
+ private function getPdoApplianceManager(){
+ if (! $this->pdoApplianceManager){
+ $this->pdoApplianceManager = new PdoApplianceManager();
+ }
+ return $this->pdoApplianceManager;
+ }
+
+ public function getInfoByUUIDAction(){
+ $uuid = $this->getParameters()->get("uuid");
+ $info = $this->getPdoApplianceManager()->getInfoByUUID($uuid);
+ if (!$info){
+ throw new Exception("Instance inconnue");
+ }
+
+ $libelle = array(
+ 'reference' => "Référence interne de l'instance",
+ 'manager'=>'Manager',
+ 'os' => "Système d'exploitation",
+ 'disc_infos' => "Informations sur les disques",
+ 'internal_fqdn' => "FQDN interne de l'application",
+ 'channel_key' => "Canal",
+ 'channel_libelle' => "Canal(libelle)",
+ 'type_hebergement_libelle' =>'Type hébergement (libellé)',
+ 'type_hebergement_key' => 'Type hébergement',
+ 'produit_name' => "Nom du produit",
+ 'version' => 'Version',
+ 'produit_diminutif' => "Diminutif du nom du produit",
+ 'contract_number' => "Référence du contrat",
+ 'contract_state' => "Etat du contrat",
+ 'contract_start_date' => "Date de début du contrat",
+ 'contract_end_date' => "Date de fin de contrat",
+ 'customer_reference' => "Référence client",
+ 'customer_name' => "Nom du client",
+ 'contact' => "Contact",
+ 'install_date' =>"Date de dernière mise à jour",
+ );
+
+ $result = array();
+ foreach($info as $key => $value){
+ $result[$key] = array("libelle"=>$libelle[$key],"value"=>$value);
+ }
+ return $result;
+ }
+
+ public function updateAction(){
+ $uuid = $this->getPostParameters()->get('uuid');
+ $produit = $this->getPostParameters()->get('produit');
+ $version = $this->getPostParameters()->get('version');
+ $os = $this->getPostParameters()->get('os');
+ $disques = $this->getPostParameters()->get('disques');
+
+ $appliance = $this->getPdoApplianceManager()->getByUUID($uuid);
+ if (! $appliance){
+ throw new Exception("Impossible de trouver l'instance sur le serveur !");
+ }
+
+ $pdoContractsManager = new PdoContractManager();
+ $contract = $pdoContractsManager->getContract($appliance->contract_id);
+ if (! $contract){
+ throw new Exception("Impossible de trouver le contrat correspondant à l'instance.");
+ }
+
+ if ($contract->state == Contract::STATE_RESILIE){
+ throw new Exception("Votre contrat est résilié, cette instance n'est plus maintenue.");
+ }
+
+ $pdoVersionsManager = new PdoVersionManager();
+ $version_id = $pdoVersionsManager->getIdByValue($produit,$version);
+ if (! $version_id){
+ throw new Exception("Impossible de trouver la version $version pour le produit $produit.");
+ }
+
+ $appliance->os = $os;
+ $appliance->disc_infos = $disques;
+ $this->getPdoApplianceManager()->editAppliance($appliance);
+
+ $pdoApplianceVersionManager = new PdoApplianceVersionManager();
+
+ if ($appliance->last_appliance_version_id){
+ $applianceVersion = $pdoApplianceVersionManager->get($appliance->last_appliance_version_id);
+ if ($applianceVersion->version_id == $version_id){
+ return "L'instance a déjà été mise à jour";
+ }
+ }
+ $applianceVersion = new ApplianceVersion();
+ $applianceVersion->appliance_id = $appliance->id;
+ $applianceVersion->creation_date = date("Y-m-d H:i:s");
+ $applianceVersion->version_id = $version_id;
+ $applianceVersion->nature = $appliance->last_appliance_version_id?ApplianceVersion::NATURE_VERSION:ApplianceVersion::NATURE_CREATION;
+ $applianceVersion->message = "Nouvelle instance applicative déclarée : $produit ; version : $version ";
+ $appliance->last_appliance_version_id = $pdoApplianceVersionManager->create($applianceVersion);
+
+ $this->pdoApplianceManager->editAppliance($appliance);
+
+ return "L'instance à été mise à jour";
+ }
+
+
+ /**
+ * @api {get} /index.php?action=anonymous_productExistsByName Vérifie l'existence d'un produit
+ * @apiGroup Anonymous
+ * @apiVersion 1.0.0
+ * @apiParam {String} name le nom du produit
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function productExistsByNameAction(){
+ $name = $this->getParameters()->get('name');
+ $pdoProductManager = new PdoProductManager();
+ return $pdoProductManager->existsByName($name);
+ }
+
+ /**
+ * @api {get} /index.php?action=anonymous_versionExistsByValue Vérifie l'existence d'une version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Sting} product_name Nom du produit
+ * @apiParam {Sting} version_value Valeur de la version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function versionExistsByValueAction(){
+ $product_name = $this->getParameters()->get('product_name');
+ $version_value = $this->getParameters()->get('version_value');
+ $pdoVersionManager = new PdoVersionManager();
+ return $pdoVersionManager->existsByValue($product_name,$version_value);
+ }
+
+ public function patchExistsAction(){
+ $uuid = $this->getParameters()->get("uuid");
+ $info = $this->getPdoApplianceManager()->getNextPatchByUUID($uuid);
+ return $info;
+ }
+
+
+
+}
\ No newline at end of file