Exemple #1
0
 private function sortFile($file)
 {
     $directory = $this->_getDefaultDirectory();
     $sort = array('HTML', 'ATTACH', 'TPL', 'THEMES', 'ACLOUD', 'WINDID', 'REP', 'SRV', 'LIB', 'HOOK', 'EXT', 'APPS', 'CONF', 'DATA', 'SRC', 'PUBLIC');
     $strtr = array();
     $localDirectory = @(include Wind::getRealPath('CONF:directory.php', true));
     foreach ($sort as $v) {
         if ($directory[$v] == $localDirectory[$v]) {
             continue;
         }
         $search = PwSystemHelper::relative(WEKIT_PATH . $directory[$v]);
         $strtr[$search] = Wind::getRootPath($v);
     }
     $_file = ROOT_PATH . $file;
     foreach ($strtr as $search => $replace) {
         if (0 === strpos($_file, $search)) {
             $file = str_replace(ROOT_PATH, '', $replace . substr($_file, strlen($search)));
             break;
         }
     }
     return $file;
 }
 /**
  * 根据现有目录结构调整升级包目录
  *
  * @param array $fileList        	
  */
 public function sortDirectory($fileList)
 {
     $this->_log('start to sort the directory');
     $sourceDir = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target;
     $directoryFile = $sourceDir . DIRECTORY_SEPARATOR . 'conf/directory.php';
     $directory = @(include $directoryFile);
     if (!is_array($directory)) {
         return new PwError('APPCENTER:upgrade.directory.fail');
     }
     $this->_log('the remote directory is:' . var_export($directory, true));
     $root = Wind::getRealDir('ROOT:');
     $sort = array('TPL', 'THEMES', 'ACLOUD', 'WINDID', 'REP', 'SRV', 'LIB', 'HOOK', 'EXT', 'APPS', 'CONF', 'DATA', 'SRC', 'PUBLIC');
     $strtr = array();
     $localDirectory = @(include Wind::getRealPath('CONF:directory.php', true));
     foreach ($sort as $v) {
         if ($directory[$v] == $localDirectory[$v]) {
             continue;
         }
         $search = PwSystemHelper::relative(WEKIT_PATH . str_replace('/', DIRECTORY_SEPARATOR, $directory[$v]));
         $strtr[rtrim($search, '/\\')] = rtrim(Wind::getRootPath($v), '/\\');
     }
     $this->_log('way of moving directory' . var_export($strtr, true));
     if (!($sourceMd5 = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum'))) {
         return new PwError('APPCENTER:upgrade.target.hash.fail');
     }
     $sourceMd5 = PwSystemHelper::resolveMd5($sourceMd5);
     // md5sum
     $data = '';
     foreach ($sourceMd5 as $v => $md5) {
         $v = trim($v, '/');
         $v = str_replace('/', DIRECTORY_SEPARATOR, $v);
         $_v = ROOT_PATH . $v;
         $file = $v;
         foreach ($strtr as $search => $replace) {
             if (0 === strpos($_v, $search)) {
                 $file = str_replace(ROOT_PATH, '', $replace . substr($_v, strlen($search)));
                 $file = str_replace('//', '/', $file);
                 break;
             }
         }
         $data .= PwSystemHelper::md5content($md5, $file);
     }
     WindFile::write($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum', $data);
     $moveList = $newFileList = array();
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getVersionHash', 'pwversion' => $this->local));
     /* 从线上获取当前版本的所有文件md5 */
     /* $result = PwApplicationHelper::requestAcloudData($url);
     		if ($result['code'] !== '0' || !$result['info']) return new PwError(array('APPCENTER:upgrade.version.hash.fail', array($result['msg']))); */
     if (!($tmp = WindFile::read(CONF_PATH . 'md5sum'))) {
         return new PwError('APPCENTER:upgrade.hash.fail');
     }
     $md5List = PwSystemHelper::resolveMd5($tmp);
     $this->_log('obtain the md5 list of current version');
     foreach ($fileList as $v) {
         $v = trim($v, '/');
         $v = str_replace('/', DIRECTORY_SEPARATOR, $v);
         $_v = $root . $v;
         $file = $v;
         foreach ($strtr as $search => $replace) {
             if (0 === strpos($_v, $search)) {
                 $file = str_replace($root, '', $replace . substr($_v, strlen($search)));
                 $file = str_replace('//', '/', $file);
                 $moveList[$v] = $file;
                 break;
             }
         }
         $newFileList[$file] = $md5List[str_replace(DIRECTORY_SEPARATOR, '/', $file)];
     }
     $this->_log('files need to move ' . var_export($moveList, true));
     $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit'));
     $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit'));
     foreach ($moveList as $old => $new) {
         WindFolder::mkRecur(dirname($sourceDir . DIRECTORY_SEPARATOR . $new));
         copy($sourceDir . DIRECTORY_SEPARATOR . $old, $sourceDir . DIRECTORY_SEPARATOR . $new);
         WindFile::del($sourceDir . DIRECTORY_SEPARATOR . $old);
         if ('.php' === substr($old, -4) && !strncasecmp($old, 'www' . DIRECTORY_SEPARATOR, 4)) {
             $content = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . $new);
             if (strpos($content, '../../src/wekit.php')) {
                 $content = str_replace('../../src/wekit.php', $relativePath_2, $content);
             } else {
                 $content = str_replace('../src/wekit.php', $relativePath_1, $content);
             }
             // $content = str_replace('../src/wekit.php',
             // Wind::getRealPath('SRC:wekit'), $content);
             WindFile::write($sourceDir . DIRECTORY_SEPARATOR . $new, $content);
         }
     }
     // 目录文件
     if ($directory != $localDirectory) {
         $directory = array_merge($directory, $localDirectory);
         $temp = "<?php\r\n defined('WEKIT_VERSION') or exit(403);\r\n return ";
         $temp .= WindString::varToString($directory) . ";\r\n?>";
         WindFile::write($directoryFile, $temp);
     }
     Wekit::cache()->set('system_upgrade_replace', 1);
     return $newFileList;
 }