示例#1
0
 public function setIsEnable($_state)
 {
     if (version_compare(jeedom::version(), $this->getRequire()) == -1 && $_state == 1) {
         throw new Exception('Votre version de jeedom n\'est pas assez récente pour activer ce plugin');
     }
     $alreadyActive = config::byKey('active', $this->getId(), 0);
     if ($_state == 1) {
         if (config::byKey('jeeNetwork::mode') != 'master' && $this->getAllowRemote() != 1) {
             throw new Exception('Vous ne pouvez pas activer ce plugin sur un Jeedom configuré en esclave');
         }
         market::checkPayment($this->getId());
         config::save('active', $_state, $this->getId());
     }
     if ($_state == 0) {
         foreach (eqLogic::byType($this->getId()) as $eqLogic) {
             $eqLogic->setConfiguration('previousIsEnable', $eqLogic->getIsEnable());
             $eqLogic->setConfiguration('previousIsVisible', $eqLogic->getIsVisible());
             $eqLogic->setIsEnable(0);
             $eqLogic->setIsVisible(0);
             $eqLogic->save();
         }
     }
     if ($alreadyActive == 0 && $_state == 1) {
         foreach (eqLogic::byType($this->getId()) as $eqLogic) {
             $eqLogic->setIsEnable($eqLogic->getConfiguration('previousIsEnable', 1));
             $eqLogic->setIsVisible($eqLogic->getConfiguration('previousIsVisible', 1));
             $eqLogic->save();
         }
     }
     try {
         if ($_state == 1) {
             if ($alreadyActive == 1) {
                 $out = $this->callInstallFunction('update');
             } else {
                 $out = $this->callInstallFunction('install');
             }
         } else {
             if ($alreadyActive == 1) {
                 $out = $this->callInstallFunction('remove');
             }
         }
         if (isset($out) && trim($out) != '') {
             log::add($this->getId(), 'info', "Installation/remove/update result : " . $out);
         }
     } catch (Exception $e) {
         config::save('active', $alreadyActive, $this->getId());
         log::add('plugin', 'error', $e->getMessage());
         throw $e;
     }
     if ($_state == 0) {
         config::save('active', $_state, $this->getId());
     }
     if ($alreadyActive == 0) {
         $this->start();
     }
     return true;
 }