* change for upgrade.

This commit is contained in:
wangyidong
2016-11-17 11:36:04 +08:00
parent b4fd8e184f
commit 0a2bb5b52c
7 changed files with 246 additions and 67 deletions
+64 -14
View File
@@ -103,21 +103,40 @@ class upgrade extends control
$this->view->title = $this->lang->upgrade->result;
$this->view->position[] = $this->lang->upgrade->common;
if(!$this->upgrade->isError())
{
$this->app->loadLang('install');
$this->view->result = 'success';
}
else
{
$this->view->result = 'fail';
$this->view->errors = $this->upgrade->getError();
}
$this->display();
if($this->view->result == 'fail') die();
if(!$this->upgrade->isError()) $this->locate(inlink('afterExec', "fromVersion=$fromVersion"));
@unlink($this->app->getAppRoot() . 'www/install.php');
@unlink($this->app->getAppRoot() . 'www/upgrade.php');
$this->view->result = 'fail';
$this->view->errors = $this->upgrade->getError();
$this->display();
}
/**
* After execute.
*
* @param string $fromVersion
* @param string $processed
* @access public
* @return void
*/
public function afterExec($fromVersion, $processed = 'no')
{
if($processed == 'no')
{
$this->view->title = $this->lang->upgrade->result;
$this->view->position[] = $this->lang->upgrade->common;
$needProcess = $this->upgrade->checkProcess($fromVersion);
$this->view->needProcess = $needProcess;
$this->view->fromVersion = $fromVersion;
$this->display();
}
if(empty($needProcess) or $processed == 'yes')
{
$this->loadModel('setting')->updateVersion($this->config->version);
@unlink($this->app->getAppRoot() . 'www/install.php');
@unlink($this->app->getAppRoot() . 'www/upgrade.php');
}
}
/**
@@ -164,4 +183,35 @@ class upgrade extends control
$this->view->data = $data;
$this->display();
}
/**
* Ajax update file.
*
* @param string $type
* @param int $lastID
* @access public
* @return void
*/
public function ajaxUpdateFile($type = '', $lastID = 0)
{
$result = $this->upgrade->updateFileObjectID($type, $lastID);
$response = array();
if($result['type'] == 'finish')
{
$response['result'] = 'finished';
$response['type'] = $type;
$response['count'] = $result['count'];
$response['message'] = 'Finished';
}
else
{
$response['result'] = 'continue';
$response['next'] = inlink('ajaxUpdateFile', "type={$result['type']}&lastID={$result['lastID']}");
$response['count'] = $result['count'];
$response['type'] = $type;
$response['nextType'] = $result['type'];
$response['message'] = strtoupper($result['type']) . " <span class='{$result['type']}-num'>0</span>";
}
die(json_encode($response));
}
}
+1
View File
@@ -42,6 +42,7 @@ $lang->upgrade->toVersion = 'Upgrade to Version';
$lang->upgrade->confirm = 'Confirm SQL';
$lang->upgrade->sureExecute = 'Execute';
$lang->upgrade->forbiddenExt = 'Extension is not compatible with the upgraded version. It has been deactivated:';
$lang->upgrade->updateFile = 'Need to update the attachment information.';
$lang->upgrade->fromVersions['0_3beta'] = '0.3 BETA';
$lang->upgrade->fromVersions['0_4beta'] = '0.4 BETA';
+1
View File
@@ -42,6 +42,7 @@ $lang->upgrade->toVersion = '升级到';
$lang->upgrade->confirm = '确认要执行的SQL语句';
$lang->upgrade->sureExecute = '确认执行';
$lang->upgrade->forbiddenExt = '以下插件与新版本不兼容,已经自动禁用:';
$lang->upgrade->updateFile = '需要更新附件信息。';
$lang->upgrade->fromVersions['0_3beta'] = '0.3 BETA';
$lang->upgrade->fromVersions['0_4beta'] = '0.4 BETA';
+1
View File
@@ -42,6 +42,7 @@ $lang->upgrade->toVersion = '升級到';
$lang->upgrade->confirm = '確認要執行的SQL語句';
$lang->upgrade->sureExecute = '確認執行';
$lang->upgrade->forbiddenExt = '以下插件與新版本不兼容,已經自動禁用:';
$lang->upgrade->updateFile = '需要更新附件信息。';
$lang->upgrade->fromVersions['0_3beta'] = '0.3 BETA';
$lang->upgrade->fromVersions['0_4beta'] = '0.4 BETA';
+91 -28
View File
@@ -153,9 +153,6 @@ class upgradeModel extends model
$this->adjustDocModule();
$this->moveDocContent();
$this->adjustPriv8_3();
$this->updateFileObjectID();
default: if(!$this->isError()) $this->setting->updateVersion($this->config->version);
}
$this->deletePatch();
@@ -1271,15 +1268,35 @@ class upgradeModel extends model
* @access public
* @return bool
*/
public function updateFileObjectID()
public function updateFileObjectID($type = '', $lastID = 0)
{
$smtm = $this->dao->select('id,objectType,objectID,comment')->from(TABLE_ACTION)->where('comment')->ne('')->query();
while($action = $smtm->fetch())
$limit = 100;
if(empty($type)) $type = 'comment';
$result['type'] = $type;
$result['lastID'] = 0;
if($type == 'comment')
{
$files = array();
preg_match_all('/"data\/upload\/.*1\/([0-9]{6}\/[^"]+)"/', $action->comment, $output);
foreach($output[1] as $path)$files[$path] = $path;
$this->dao->update(TABLE_FILE)->set('objectType')->eq($action->objectType)->set('objectID')->eq($action->objectID)->set('extra')->eq('editor')->where('pathname')->in($files)->exec();
$comments = $this->dao->select('id,objectType,objectID,comment')->from(TABLE_ACTION)->where('comment')->like('%data/upload/%')->andWhere('id')->gt($lastID)->orderBy('id')->limit($limit)->fetchAll('id');
foreach($comments as $comment)
{
$files = array();
preg_match_all('/"data\/upload\/.*1\/([0-9]{6}\/[^"]+)"/', $action->comment, $output);
foreach($output[1] as $path)$files[$path] = $path;
$this->dao->update(TABLE_FILE)->set('objectType')->eq($action->objectType)->set('objectID')->eq($action->objectID)->set('extra')->eq('editor')->where('pathname')->in($files)->exec();
}
if(count($comments) < $limit)
{
$result['type'] = 'doc';
$result['count'] = count($comments);
$result['lastID'] = 0;
}
else
{
$result['type'] = 'comment';
$result['count'] = count($comments);
$result['lastID'] = $comment->id;
}
return $result;
}
$editors['doc'] = array('table' => TABLE_DOCCONTENT, 'fields' => 'doc,`content`,`digest`');
@@ -1292,31 +1309,63 @@ class upgradeModel extends model
$editors['testtask'] = array('table' => TABLE_TESTTASK, 'fields' => 'id,`desc`,`report`');
$editors['todo'] = array('table' => TABLE_TODO, 'fields' => 'id,`desc`');
$editors['task'] = array('table' => TABLE_TASK, 'fields' => 'id,`desc`');
foreach($editors as $objectType => $editor)
$editors['build'] = array('table' => TABLE_BUILD, 'fields' => 'id,`desc`');
$editor = $editors[$type];
$fields = explode(',', $editor['fields']);
$cond = array();
foreach($fields as $field)
{
$smtm = $this->dao->select($editor['fields'])->from($editor['table'])->query();
while($object = $smtm->fetch())
if(strpos($field, '`') !== false) $cond[] = $field . " like '%data/upload/%'";
if(strpos($field, '`') === false) $idField = $field;
}
$objects = $this->dao->select($editor['fields'])->from($editor['table'])
->where($idField)->gt($lastID)
->beginIF($cond)->andWhere('(' . join(' OR ', $cond) . ')')->fi()
->orderBy($idField)
->limit($limit)
->fetchAll($idField);
foreach($objects as $object)
{
$files = array();
$objectID = 0;
foreach($fields as $field)
{
$files = array();
$objectID = 0;
$fields = explode(',', $editor['fields']);
foreach($fields as $field)
if(strpos($field, '`') === false)
{
if(strpos($field, '`') === false)
$objectID = $object->$field;
}
else
{
$field = trim($field, '`');
preg_match_all('/"\/?data\/upload\/.*1\/([0-9]{6}\/[^"]+)"/', $object->$field, $output);
foreach($output[1] as $path)$files[$path] = $path;
}
}
if($files) $this->dao->update(TABLE_FILE)->set('objectType')->eq($type)->set('objectID')->eq($objectID)->set('extra')->eq('editor')->where('pathname')->in($files)->exec();
}
if(count($objects) < $limit)
{
$editorKeys = array_keys($editors);
foreach($editorKeys as $i => $objectType)
{
if($type == $objectType)
{
$objectID = $object->$field;
}
else
{
$field = trim($field, '`');
preg_match_all('/"\/?data\/upload\/.*1\/([0-9]{6}\/[^"]+)"/', $object->$field, $output);
foreach($output[1] as $path)$files[$path] = $path;
$nextType = isset($editorKeys[$i + 1]) ? $editorKeys[$i + 1] : '';
break;
}
}
if($files) $this->dao->update(TABLE_FILE)->set('objectType')->eq($objectType)->set('objectID')->eq($objectID)->set('extra')->eq('editor')->where('pathname')->in($files)->exec();
$result['type'] = empty($nextType) ? 'finish' : $nextType;
$result['count'] = count($objects);
$result['lastID'] = 0;
}
}
return true;
else
{
$result['type'] = $type;
$result['count'] = count($objects);
$result['lastID'] = $object->id;
}
return $result;
}
/**
@@ -1419,4 +1468,18 @@ class upgradeModel extends model
$statusFile = $this->app->getAppRoot() . 'www' . DIRECTORY_SEPARATOR . 'ok.txt';
return (!file_exists($statusFile) or (time() - filemtime($statusFile)) > 3600) ? $statusFile : false;
}
/**
* Check weither process or not.
*
* @access public
* @return array
*/
public function checkProcess()
{
$fromVersion = $this->config->installedVersion;
$needProcess = array();
if(strpos($fromVersion, 'pro') === false ? $fromVersion < '8.3' : $fromVersion < 'pro5.4') $needProcess['updateFile'] = true;
return $needProcess;
}
}
+88
View File
@@ -0,0 +1,88 @@
<?php
/**
* The html template file of execute method of upgrade module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package upgrade
* @version $Id: execute.html.php 5119 2013-07-12 08:06:42Z wyd621@gmail.com $
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<div class='container'>
<div class='modal-dialog'>
<div class='modal-header'>
<strong><?php echo $lang->upgrade->result;?></strong>
</div>
<div class='modal-body'>
<div class='alert alert-success mgb-10'>
<strong><?php echo $lang->upgrade->success?></strong>
<span class='pull-right'><?php echo html::a('index.php', $lang->upgrade->tohome, '', "class='btn btn-sm' id='tohome'")?></span>
</div>
<div class='panel adbox'>
<div class='panel-heading'><strong><?php echo $lang->install->promotion?></strong></div>
<div class='panel-body'>
<div class='col-md-4'>
<a class="card ad" href="http://www.chanzhi.org" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/chanzhi.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/chanzhi.png'?>" alt=""></div>
</a>
</div>
<div class='col-md-4'>
<a class="card ad" href="http://www.ranzhico.com" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/ranzhi.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/ranzhi.png'?>" alt=""></div>
</a>
</div>
<div class='col-md-4'>
<a class="card ad" href="http://www.yidouio.com" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/yidou.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/yidou.png'?>" alt=""></div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
<?php
foreach($needProcess as $processKey => $value) echo 'var ' . $processKey . "Finish = false;\n";
$needUpdateFile = strpos($config->installedVersion, 'pro') === false ? $config->installedVersion < '8.3' : $config->installedVersion < 'pro5.4';
if($needUpdateFile):?>
$(function()
{
$('a#tohome').hide();
$('.adbox').before("<div id='resultBox' class='alert alert-info'><p><?php echo $lang->upgrade->updateFile;?></p></div>");
updateFile('<?php echo inlink('ajaxUpdateFile')?>');
})
function updateFile(link)
{
$.getJSON(link, function(response)
{
if(response.result == 'finished')
{
$('#resultBox li span.' + response.type + '-num').html(num + response.count);
updateFileFinish = true;
$('#resultBox').append("<li class='text-success'>" + response.message + "</li>");
<?php
$condition = array();
foreach($needProcess as $processKey => $value) $condition[] = $processKey . 'Finish == true';
$condition = join(' && ', $condition);
?>
if(<?php echo $condition?>) $.get('<?php echo inlink('afterExec', "fromVersion=$fromVersion&processed=yes")?>');
$('a#tohome').show();
}
else
{
if($('#resultBox li span.' + response.type + '-num').size() == 0 || response.type != response.nextType)
{
$('#resultBox').append("<li class='text-success'>" + response.message + "</li>");
}
var num = parseInt($('#resultBox li span.' + response.type + '-num').html());
$('#resultBox li span.' + response.type + '-num').html(num + response.count);
updateFile(response.next);
}
});
}
<?php endif;?>
</script>
<?php include '../../common/view/footer.lite.html.php';?>
-25
View File
@@ -19,31 +19,6 @@
<?php if($result == 'fail'):?>
<div class='alert alert-danger mgb-10'><strong><?php echo $lang->upgrade->fail?></strong></div>
<pre><?php echo join('<br />', $errors);?></pre>
<?php else:?>
<div class='alert alert-success mgb-10'>
<strong><?php echo $lang->upgrade->success?></strong>
<span class='pull-right'><?php echo html::a('index.php', $lang->upgrade->tohome, '', "class='btn btn-sm' id='tohome'")?></span>
</div>
<div class='panel adbox'>
<div class='panel-heading'><strong><?php echo $lang->install->promotion?></strong></div>
<div class='panel-body'>
<div class='col-md-4'>
<a class="card ad" href="http://www.chanzhi.org" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/chanzhi.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/chanzhi.png'?>" alt=""></div>
</a>
</div>
<div class='col-md-4'>
<a class="card ad" href="http://www.ranzhico.com" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/ranzhi.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/ranzhi.png'?>" alt=""></div>
</a>
</div>
<div class='col-md-4'>
<a class="card ad" href="http://www.yidouio.com" target="_blank">
<div class="img-wrapper" style="background-image:url(<?php echo $defaultTheme . 'images/main/yidou.png'?>)"><img src="<?php echo $defaultTheme . 'images/main/yidou.png'?>" alt=""></div>
</a>
</div>
</div>
</div>
<?php endif;?>
</div>
</div>