Beispiel #1
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();
 }