Exemple #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();
 }
Exemple #2
0
        $configRemove[] = array('key' => $value['key'], 'plugin' => $value['plugin']);
    }
    try {
        $update->save();
    } catch (Exception $ex) {
    }
}
$sql = 'SELECT * 
        FROM config 
        WHERE `key` = "installVersionDate"';
$values = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL);
foreach ($values as $value) {
    $update = new update();
    if ($value['plugin'] != '') {
        $update->setLogicalId($value['plugin']);
        $update->setLocalVersion($value['value']);
        $update->setType('plugin');
        try {
            $update->save();
            $configRemove[] = array('key' => "installVersionDate", 'plugin' => $value['plugin']);
        } catch (Exception $ex) {
        }
    }
}
foreach ($configRemove as $remove) {
    if (isset($remove['plugin'])) {
        config::remove($remove['key'], $remove['plugin']);
    } else {
        config::remove($remove['key']);
    }
}
 public static function install_from_file($version, $revision, $ufile, $ulog)
 {
     global $DB;
     // remove old update files (will be there if a previous update fails)
     file_put_contents($ulog, "remove old update folder\n", FILE_APPEND);
     core_remove_folder(NAVIGATE_PATH . '/updates/update');
     // decompress
     file_put_contents($ulog, "create new folder\n", FILE_APPEND);
     mkdir(NAVIGATE_PATH . '/updates/update');
     $zip = new ZipArchive();
     file_put_contents($ulog, "open zip file\n", FILE_APPEND);
     if ($zip->open($ufile) === TRUE) {
         file_put_contents($ulog, "extract zip file\n", FILE_APPEND);
         $zip->extractTo(NAVIGATE_PATH . '/updates/update');
         $zip->close();
     } else {
         file_put_contents($ulog, "zip extraction failed\n", FILE_APPEND);
         @unlink($ufile);
         core_remove_folder(NAVIGATE_PATH . '/updates/update');
         return false;
     }
     // chmod files (may fail, but not fatal error)
     file_put_contents($ulog, "chmod update (may fail in Windows)... ", FILE_APPEND);
     $chmod_status = core_chmodr(NAVIGATE_PATH . '/updates/update', 0755);
     file_put_contents($ulog, $chmod_status . "\n", FILE_APPEND);
     // do file changes
     file_put_contents($ulog, "parse file changes\n", FILE_APPEND);
     $hgchanges = file_get_contents(NAVIGATE_PATH . '/updates/update/changes.txt');
     $hgchanges = explode("\n", $hgchanges);
     foreach ($hgchanges as $change) {
         file_put_contents($ulog, $change . "\n", FILE_APPEND);
         $change = trim($change);
         if (empty($change)) {
             continue;
         }
         $change = explode(" ", $change, 2);
         // new, removed and modified files
         // M = modified
         // A = added
         // R = removed
         // C = clean
         // ! = missing (deleted by non-hg command, but still tracked)
         // ? = not tracked
         // I = ignored
         //   = origin of the previous file listed as A (added)
         $file = str_replace('\\', '/', $change[1]);
         //if(substr($file, 0, strlen('plugins/'))=='plugins/') continue;
         if (substr($file, 0, strlen('setup/')) == 'setup/') {
             continue;
         }
         switch ($change[0]) {
             case 'A':
                 // added a new file
             // added a new file
             case 'M':
                 // modified file
                 if (!file_exists(NAVIGATE_PATH . '/updates/update/' . $file)) {
                     file_put_contents($ulog, "file doesn't exist!\n", FILE_APPEND);
                     return false;
                 }
                 @mkdir(dirname(NAVIGATE_PATH . '/' . $file), 0777, true);
                 if (!@copy(NAVIGATE_PATH . '/updates/update/' . $file, NAVIGATE_PATH . '/' . $file)) {
                     file_put_contents($ulog, "cannot copy file!\n", FILE_APPEND);
                     return false;
                 }
                 break;
             case 'R':
                 // remove file
                 @unlink(NAVIGATE_PATH . '/' . $file);
                 break;
             default:
                 // all other cases
                 // IGNORE the change, as we are now only getting the modified files
         }
     }
     // process SQL updates
     file_put_contents($ulog, "process sql update\n", FILE_APPEND);
     if (file_exists(NAVIGATE_PATH . '/updates/update/update.sql')) {
         $sql = file_get_contents(NAVIGATE_PATH . '/updates/update/update.sql');
         // execute SQL in a transaction
         // http://php.net/manual/en/pdo.transactions.php
         try {
             // can't do it in one step => SQLSTATE[HY000]: General error: 2014
             $sql = explode("\n\n", $sql);
             //file_put_contents($ulog, "begin transaction\n", FILE_APPEND);
             //$DB->beginTransaction();
             foreach ($sql as $sqlline) {
                 $sqlline = trim($sqlline);
                 if (empty($sqlline)) {
                     continue;
                 }
                 file_put_contents($ulog, "execute sql:\n" . $sqlline . "\n", FILE_APPEND);
                 if (!$DB->execute($sqlline)) {
                     file_put_contents($ulog, "execute failed: " . $DB->get_last_error() . "\n", FILE_APPEND);
                     //throw new Exception($DB->get_last_error());
                 }
                 // force commit changes (slower but safer... no --> SQLSTATE[HY000]: General error: 2014)
                 $DB->disconnect();
                 $DB->connect();
             }
             //file_put_contents($ulog, "commit transaction\n", FILE_APPEND);
             //$DB->commit();
         } catch (Exception $e) {
             file_put_contents($ulog, "transaction error: \n" . $e->getMessage() . "\n", FILE_APPEND);
             //$DB->rollBack();
             return false;
         }
     } else {
         file_put_contents($ulog, "no SQL found\n", FILE_APPEND);
     }
     // add the update row to know which navigate revision is currently installed
     file_put_contents($ulog, "insert new version row on updates\n", FILE_APPEND);
     $urow = new update();
     $urow->id = 0;
     $urow->version = $version;
     $urow->revision = $revision;
     $urow->date_updated = time();
     $urow->status = 'ok';
     $urow->changelog = '';
     try {
         $ok = $urow->insert();
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     if ($error) {
         file_put_contents($ulog, "execute insert failed:\n" . $DB->get_last_error() . "\n", FILE_APPEND);
     }
     if (file_exists(NAVIGATE_PATH . '/updates/update/update-post.php')) {
         include_once NAVIGATE_PATH . '/updates/update/update-post.php';
     }
     file_put_contents($ulog, "update finished!\n", FILE_APPEND);
     $urow->changelog = file_get_contents($ulog);
     $urow->save();
     @unlink($ufile);
     update::cache_clean();
     return true;
 }
Exemple #4
0
    public static function findNewUpdateObject()
    {
        foreach (plugin::listPlugin() as $plugin) {
            $plugin_id = $plugin->getId();
            $update = self::byTypeAndLogicalId('plugin', $plugin_id);
            if (!is_object($update)) {
                $update = new update();
                $update->setLogicalId($plugin_id);
                $update->setType('plugin');
                $update->setLocalVersion(date('Y-m-d H:i:s'));
                $update->save();
            }
            $find = array();
            if (method_exists($plugin_id, 'listMarketObject')) {
                foreach ($plugin_id::listMarketObject() as $logical_id) {
                    $find[$logical_id] = true;
                    $update = self::byTypeAndLogicalId($plugin_id, $logical_id);
                    if (!is_object($update)) {
                        $update = new update();
                        $update->setLogicalId($logical_id);
                        $update->setType($plugin_id);
                        $update->setLocalVersion(date('Y-m-d H:i:s'));
                        $update->save();
                    }
                }
                foreach (self::byType($plugin_id) as $update) {
                    if (!isset($find[$update->getLogicalId()])) {
                        $update->remove();
                    }
                }
            } else {
                $values = array('type' => $plugin_id);
                $sql = 'DELETE FROM `update`
						WHERE type=:type';
                DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW);
            }
        }
    }