From 0a2bb5b52c573cd59d5e9393c6d25edf80a0e423 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Thu, 17 Nov 2016 11:36:04 +0800 Subject: [PATCH] * change for upgrade. --- module/upgrade/control.php | 78 +++++++++++++--- module/upgrade/lang/en.php | 1 + module/upgrade/lang/zh-cn.php | 1 + module/upgrade/lang/zh-tw.php | 1 + module/upgrade/model.php | 119 +++++++++++++++++++------ module/upgrade/view/afterexec.html.php | 88 ++++++++++++++++++ module/upgrade/view/execute.html.php | 25 ------ 7 files changed, 246 insertions(+), 67 deletions(-) create mode 100644 module/upgrade/view/afterexec.html.php diff --git a/module/upgrade/control.php b/module/upgrade/control.php index 300e90c03e..14247046c6 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -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']) . " 0"; + } + die(json_encode($response)); + } } diff --git a/module/upgrade/lang/en.php b/module/upgrade/lang/en.php index 5aeeb7c9a9..cb7dad6b50 100644 --- a/module/upgrade/lang/en.php +++ b/module/upgrade/lang/en.php @@ -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'; diff --git a/module/upgrade/lang/zh-cn.php b/module/upgrade/lang/zh-cn.php index c93b0fa66b..6bf6bcb187 100644 --- a/module/upgrade/lang/zh-cn.php +++ b/module/upgrade/lang/zh-cn.php @@ -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'; diff --git a/module/upgrade/lang/zh-tw.php b/module/upgrade/lang/zh-tw.php index 4fa1520b11..5c3f12dcf0 100644 --- a/module/upgrade/lang/zh-tw.php +++ b/module/upgrade/lang/zh-tw.php @@ -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'; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 218e7aa48b..59d25b438a 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -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; + } } diff --git a/module/upgrade/view/afterexec.html.php b/module/upgrade/view/afterexec.html.php new file mode 100644 index 0000000000..b0e911dabf --- /dev/null +++ b/module/upgrade/view/afterexec.html.php @@ -0,0 +1,88 @@ + + * @package upgrade + * @version $Id: execute.html.php 5119 2013-07-12 08:06:42Z wyd621@gmail.com $ + */ +?> + +
+ +
+ + diff --git a/module/upgrade/view/execute.html.php b/module/upgrade/view/execute.html.php index 7d22523367..021a10ad25 100644 --- a/module/upgrade/view/execute.html.php +++ b/module/upgrade/view/execute.html.php @@ -19,31 +19,6 @@
upgrade->fail?>
', $errors);?>
- -
- upgrade->success?> - upgrade->tohome, '', "class='btn btn-sm' id='tohome'")?> -
-
-
install->promotion?>
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-