예제 #1
0
 public static function checkAllUpdate($_filter = '', $_findNewObject = true)
 {
     $findCore = false;
     $marketObject = array('logical_id' => array(), 'version' => array());
     if ($_findNewObject) {
         self::findNewUpdateObject();
     }
     $updates = self::all($_filter);
     if (is_array($updates)) {
         foreach (self::all($_filter) as $update) {
             if ($update->getType() == 'core') {
                 if ($findCore) {
                     $update->remove();
                     continue;
                 }
                 $findCore = true;
                 $update->setType('core');
                 $update->setLogicalId('jeedom');
                 if (method_exists('jeedom', 'version')) {
                     $update->setLocalVersion(jeedom::version());
                 } else {
                     $update->setLocalVersion(getVersion('jeedom'));
                 }
                 $update->save();
                 $update->checkUpdate();
             } else {
                 if ($update->getStatus() != 'hold') {
                     $marketObject['logical_id'][] = array('logicalId' => $update->getLogicalId(), 'type' => $update->getType());
                     $marketObject['version'][] = $update->getConfiguration('version', 'stable');
                     $marketObject[$update->getType() . $update->getLogicalId()] = $update;
                 }
             }
         }
     }
     if (!$findCore) {
         $update = new update();
         $update->setType('core');
         $update->setLogicalId('jeedom');
         if (method_exists('jeedom', 'version')) {
             $update->setLocalVersion(jeedom::version());
         } else {
             $update->setLocalVersion(getVersion('jeedom'));
         }
         $update->save();
         $update->checkUpdate();
     }
     $markets_infos = market::getInfo($marketObject['logical_id'], $marketObject['version']);
     foreach ($markets_infos as $logicalId => $market_info) {
         $update = $marketObject[$logicalId];
         if (is_object($update)) {
             $update->setStatus($market_info['status']);
             $update->setConfiguration('market_owner', $market_info['market_owner']);
             $update->setConfiguration('market', $market_info['market']);
             $update->setRemoteVersion($market_info['datetime']);
             $update->save();
         }
     }
     config::save('update::lastCheck', date('Y-m-d H:i:s'));
 }
예제 #2
0
 public function save()
 {
     $cache = cache::byKey('market::info::' . $this->getLogicalId());
     if (is_object($cache)) {
         $cache->remove();
     }
     $market = self::getJsonRpc();
     $params = utils::o2a($this);
     if (isset($params['changelog'])) {
         unset($params['changelog']);
     }
     switch ($this->getType()) {
         case 'plugin':
             $cibDir = dirname(__FILE__) . '/../../tmp/' . $this->getLogicalId();
             if (file_exists($cibDir)) {
                 rrmdir($cibDir);
             }
             mkdir($cibDir);
             $exclude = array('tmp');
             rcopy(realpath(dirname(__FILE__) . '/../../plugins/' . $this->getLogicalId()), $cibDir, true, $exclude, true);
             $tmp = dirname(__FILE__) . '/../../tmp/' . $this->getLogicalId() . '.zip';
             if (file_exists($tmp)) {
                 if (!unlink($tmp)) {
                     throw new Exception(__('Impossible de supprimer : ', __FILE__) . $tmp . __('. Vérifiez les droits', __FILE__));
                 }
             }
             if (!create_zip($cibDir, $tmp)) {
                 throw new Exception(__('Echec de création de l\'archive zip', __FILE__));
             }
             break;
         default:
             $type = $this->getType();
             if (!class_exists($type) || !method_exists($type, 'shareOnMarket')) {
                 throw new Exception(__('Aucune fonction correspondante à : ', __FILE__) . $type . '::shareOnMarket');
             }
             $tmp = $type::shareOnMarket($this);
             break;
     }
     if (!file_exists($tmp)) {
         throw new Exception(__('Impossible de trouver le fichier à envoyer : ', __FILE__) . $tmp);
     }
     $file = array('file' => '@' . realpath($tmp));
     if (!$market->sendRequest('market::save', $params, 30, $file)) {
         throw new Exception($market->getError());
     }
     $update = update::byTypeAndLogicalId($this->getType(), $this->getLogicalId());
     if (!is_object($update)) {
         $update = new update();
         $update->setLogicalId($this->getLogicalId());
         $update->setType($this->getType());
     }
     $update->setConfiguration('version', 'beta');
     $update->setLocalVersion(date('Y-m-d H:i:s', strtotime('+10 minute' . date('Y-m-d H:i:s'))));
     $update->save();
     $update->checkUpdate();
 }