Beispiel #1
0
 public function getPackage(Doctrine_Connection $conn = null)
 {
     $conn2 = Doctrine_Manager::connection();
     $conn2->execute("update ei_subject s left join ei_ticket t \n                            on s.package_id =t.ticket_id and s.package_ref=t.ticket_ref\n                            set s.package_id =NULL and s.package_ref=NULL\n                            where CONCAT('Package_S',s.id)!=t.name");
     $conn2->execute("update ei_subject s  left join ei_ticket t on s.package_id=t.ticket_id and s.package_ref=t.ticket_ref\n            set package_id=NULL , package_ref=NULL \n            where   t.ticket_id IS   NULL OR   t.ticket_ref is   NULL ");
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     /* Le package existe déjà mais on procède aux vérifications permettant d'avoir l'unicité d'un bug pour un package.
         En effet un Package doit être lié à un bug au plus.
        */
     if ($this->getPackageId() != null && $this->getPackageId() != 0 && $this->getPackageRef() != null && $this->getPackageRef() != 0) {
         $package_bugs_links = $conn->fetchAll("select t.ticket_id , t.ticket_ref, s.id  \n                        from  ei_ticket t \n                        inner join  ei_subject s on s.package_id=t.ticket_id and s.package_ref=t.ticket_ref\n                        where t.ticket_id= " . $this->getPackageId() . " and t.ticket_ref=" . $this->getPackageRef());
     } else {
         $package_bugs_links = array();
     }
     if (count($package_bugs_links) == 0) {
         //Le ticket du bug est null ou n'existe pas : on le crée par le web service
         //Si le package du bug est   null
         if ($this->getPackageId() != null && $this->getPackageRef() != null) {
             $conn->execute("update ei_subject set package_id=NULL And package_ref=NULL where package_id=" . $this->getPackageId() . " And package_ref=" . $this->getPackageRef());
         }
         /* On recharge le projet si nécessaire */
         $ei_project = $this->getEiProject();
         if ($ei_project->needsReload()) {
             $xml = $ei_project->downloadKalFonctions();
             if ($xml != null) {
                 $ei_project->transactionToLoadObjectsOfProject($xml);
             }
         }
         /* Préparation des données de création du web service de création de l'intervention */
         $guard = MyFunction::getGuard();
         $data = array('package_name' => 'Package_S' . $this->getId(), 'guard_id' => $guard->getId());
         /* Création de l'intervention */
         $pack = EiTicket::createDistantPackage($this->getEiProject(), json_encode($data));
         if (is_array($pack) && isset($pack['package_id']) && isset($pack['package_ref'])) {
             return array("package_id" => $pack['package_id'], "package_ref" => $pack['package_ref']);
         } else {
             //Echec de la création de l'intervention du bug.
             throw new Exception("Fatal error . Failed to create  intervention package! Contact administrator...");
             //$conn->execute("update ei_subject set package_id=" . $pack['package_id'] . " , package_ref=" . $pack['package_ref'] . " , updated_at='" . date('Y-m-d H:i:s') . "' where id=" . $this->getId());
             //$package = Doctrine_Core::getTable('EiTicket')->findOneByTicketIdAndTicketRef($pack['package_id'], $pack['package_ref']);
         }
     } elseif (count($package_bugs_links) > 1) {
         //Le ticket est lié à plusieurs bugs : On génère une exception et on alerte l'administrateur
         throw new Exception("Fatal error . Many interventions for a package! Contact administrator...");
     } else {
         //Le package du bug/intervention est bien définit et l'objet EiTicket associé existe.
         return array("package_id" => $this->getPackageId(), "package_ref" => $this->getPackageRef());
     }
 }