예제 #1
0
 /**
  * 在线升级
  *
  * 只有管理员token才能调用
  *
  * @param string token , 必填  
  * @param string password
  * @return msg array( 'msg'=>ok )
  * @author EasyChen
  */
 function upgrade()
 {
     if ($_SESSION['level'] != '9') {
         return self::send_error(LR_API_FORBIDDEN, __('API_MESSAGE_ONLY_ADMIN'));
     }
     $url = c('teamtoy_url') . '/?a=last_version&domain=' . c('site_domain') . '&uid=' . uid();
     if (c('dev_version')) {
         $url = $url . '&dev=1';
     }
     $info = json_decode(file_get_contents($url), true);
     if (!isset($info['url'])) {
         return self::send_error(LR_API_UPGRADE_ERROR, __('API_MESSAGE_UPGARDE_INFO_DATA_ERROR'));
     }
     $url = t($info['url']);
     $vid = intval($info['version']);
     if ($vid < 1) {
         return self::send_error(LR_API_UPGRADE_ERROR, __('API_MESSAGE_UPGARDE_INFO_DATA_ERROR'));
     }
     if ($vid == local_version()) {
         return self::send_error(LR_API_UPGRADE_ABORT, __('API_MESSAGE_UPGARDE_ALREADY_LATEST'));
     }
     $zip_tmp = SAE_TMP_PATH . DS . 'teamtoy2-' . intval($vid) . '.zip';
     if (@copy($url, $zip_tmp)) {
         include_once AROOT . 'lib' . DS . 'dUnzip2.inc.php';
         $zip = new dUnzip2($zip_tmp);
         $zip->debug = false;
         $zip->unzipAll(AROOT);
         @chmod(AROOT, 0755);
         if (isset($info['post_script'])) {
             $pscript = t($info['post_script']);
         } else {
             $pscript = false;
         }
         if (local_version() == $vid) {
             if ($pscript) {
                 send_notice(uid(), __('API_TEXT_ALREADY_UPGARDE_TO', array($vid, c('site_url') . $pscript)), 0);
             }
             return self::send_result(array('msg' => 'ok', 'post_script' => $pscript));
         } else {
             return self::send_error(LR_API_UPGRADE_ERROR, __('API_MESSAGE_UPGARDE_FILE_UNZIP_ERROR'));
         }
     } else {
         return self::send_error(LR_API_UPGRADE_ERROR, __('API_MESSAGE_UPGARDE_FILE_FETCH_ERROR'));
     }
 }
예제 #2
0
파일: api.class.php 프로젝트: ramo01/1kapp
 /**
  * 在线升级
  *
  * 只有管理员token才能调用
  *
  * @param string token , 必填  
  * @param string password
  * @return msg array( 'msg'=>ok )
  * @author EasyChen
  */
 function upgrade()
 {
     if ($_SESSION['level'] != '9') {
         return $this->send_error(LR_API_FORBIDDEN, 'ONLY ADMIN CAN DO THIS');
     }
     $url = c('teamtoy_url') . '/?a=last_version&domain=' . c('site_domain') . '&uid=' . uid();
     if (c('dev_version')) {
         $url = $url . '&dev=1';
     }
     $info = json_decode(file_get_contents($url), true);
     if (!isset($info['url'])) {
         return $this->send_error(LR_API_UPGRADE_ERROR, ' JSON DATA ERROR');
     }
     $url = t($info['url']);
     $vid = intval($info['version']);
     if ($vid < 1) {
         return $this->send_error(LR_API_UPGRADE_ERROR, ' JSON DATA ERROR');
     }
     if ($vid == local_version()) {
         return $this->send_error(LR_API_UPGRADE_ABORT, ' ALREADY LATEST VERSION');
     }
     $zip_tmp = SAE_TMP_PATH . DS . 'teamtoy2-' . intval($vid) . '.zip';
     if (@copy($url, $zip_tmp)) {
         include_once AROOT . 'lib' . DS . 'dUnzip2.inc.php';
         $zip = new dUnzip2($zip_tmp);
         $zip->debug = false;
         $zip->unzipAll(AROOT);
         @chmod(AROOT, 0755);
         if (isset($info['post_script'])) {
             $pscript = t($info['post_script']);
         } else {
             $pscript = false;
         }
         if (local_version() == $vid) {
             if ($pscript) {
                 send_notice(uid(), 'TeamToy代码已经更新到' . $vid . ',<a href="' . c('site_url') . $pscript . '">请立即升级数据表</a>', 0);
             }
             return $this->send_result(array('msg' => 'ok', 'post_script' => $pscript));
         } else {
             return $this->send_error(LR_API_UPGRADE_ERROR, ' FILE UNZIP ERROR');
         }
     } else {
         return $this->send_error(LR_API_UPGRADE_ERROR, ' COPY REMOTE FILE ERROR');
     }
 }