/**
  * Uses installation meta data to download and install the updated installation files.
  * @param string $origMeta Unique ID of the meta data file containing installation information
  */
 public static function update($origMeta)
 {
     $meta = self::getMetaPath($origMeta);
     if (empty($meta)) {
         throw new InvalidArgumentException('Parameter $origMeta must be a path to an installation meta data file');
     }
     $instOld = Installation::getInstallation(json_decode(file_get_contents($meta), true));
     $updt = self::getUpdateData($instOld);
     if (empty($updt)) {
         throw new InstallationException("Failed to download update data");
     }
     if (!is_url($updt['url'])) {
         throw new InstallationException("No download URL specified in update data");
     }
     // Already throws exceptions
     $zip = self::download($updt['url']);
     // Simply install the update.
     $id = self::install($zip);
     // Remove the temporarily downloaded files.
     unlink($zip);
     // Remove the old meta file
     unlink(jailpath(DIAMONDMVC_ROOT . DS . 'registry', $origMeta));
     // If we're updating the Diamond itself, it already delivers its own meta data file. Unlink the new one.
     if ($origMeta === 'diamondmvc.json') {
         unlink(jailpath(DIAMONDMVC_ROOT . DS . 'registry', "{$id}.json"));
     } else {
         $path = self::getMetaPath($id);
         $instNew = Installation::getInstallation(json_decode(file_get_contents($path), true));
         $files = array_merge($instOld->getFiles(), $instNew->getFiles());
         natsort($files);
         $instNew->setFiles($files);
     }
     return $id;
 }
예제 #2
0
파일: system.php 프로젝트: Zyr93/DiamondMVC
 protected function action_installation()
 {
     if (!Permissions::has('sys_access') or !Permissions::has('sys_installations_view')) {
         return $this->redirectForbidden();
     }
     $lang = i18n::load('diamondmvc-backend');
     $this->title = $lang->get('TITLE', 'ControllerSystem.Installation');
     if (!isset($_REQUEST['id'])) {
         $this->result = array('success' => false, 'msg' => $lang->get('ERROR_MISSING_ARGUMENTS'));
         return;
     }
     $path = jailpath(DIAMONDMVC_ROOT . DS . 'registry', $_REQUEST['id'] . '.json');
     if (!file_exists($path)) {
         $this->result = array('success' => false, 'msg' => $lang->get('ERROR_NO_META', 'ControllerSystem.Installation'));
         return;
     }
     $json = json_decode(file_get_contents($path), true);
     $meta = Installation::getInstallation($json);
     $this->result = array('success' => true, 'meta' => $meta, 'id' => $_REQUEST['id']);
 }