From b2434a534122305cb1cabf91f2e9719fdedae4c2 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 22 Aug 2023 09:17:27 +0800 Subject: [PATCH] * Code for task #99426. --- module/todo/js/common.ui.js | 11 +++----- module/upgrade/model.php | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/module/todo/js/common.ui.js b/module/todo/js/common.ui.js index 602189c627..5327544055 100644 --- a/module/todo/js/common.ui.js +++ b/module/todo/js/common.ui.js @@ -93,15 +93,12 @@ function togglePending() */ function loadList(type, id, todoDefaultType, objectID) { + let nameBoxClass = '.name-box'; + let nameBoxID = '#nameBox'; if(id) { - let nameBoxClass = '.name-box' + id; - let nameBoxID = '#nameBox' + id; - } - else - { - let nameBoxClass = '.name-box'; - let nameBoxID = '#nameBox'; + nameBoxClass = '.name-box' + id; + nameBoxID = '#nameBox' + id; } id = id ? id : ''; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 3e18ebc22f..3cf8ed4af0 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -9264,4 +9264,55 @@ class upgradeModel extends model return true; } + + /** + * Process once cycle. + * + * @access public + * @return void + */ + public function processOnceCycle() + { + $cycleTodos = $this->dao->select('*')->from(TABLE_TODO)->where('type')->eq('cycle')->andWhere('cycle')->eq(1)->fetchAll('id'); + $onceCycles = array(); + foreach($cycleTodos as $todo) + { + $config = json_decode($todo->config); + if($config->type != 'day') continue; + if(empty($config->specifiedDate)) continue; + if(!empty($config->cycleYear)) continue; + + $todo->config = $config; + $onceCycles[$todo->id] = $todo; + } + + $this->loadModel('todo'); + $this->loadModel('action'); + + $createdTodosByCycle = $this->dao->select('id,type,objectID')->from(TABLE_TODO)->where('type')->eq('cycle')->andWhere('objectID')->in(array_keys($onceCycles))->fetchAll('objectID'); + $today = helper::today(); + $now = helper::now(); + foreach($onceCycles as $todo) + { + if(isset($createdTodosByCycle[$todo->id])) + { + $this->dao->delete()->from(TABLE_TODO)->where('id')->eq($todo->id)->exec(); + continue; + } + + $newTodo = $this->todo->buildCycleTodo($todo); + if(isset($todo->assignedTo) && $todo->assignedTo) $newTodo->assignedDate = $now; + + $config = $todo->config; + list($year) = explode('-', $todo->date); + $newTodo->date = $year . '-' . sprintf('%02d', $config->specify->month + 1) . '-' . sprintf('%02d', $config->specify->day); + + $todoID = $this->todo->insert($newTodo); + if($todoID) $this->action->create('todo', $todoID, 'opened', '', '', $newTodo->account); + + $this->dao->delete()->from(TABLE_TODO)->where('id')->eq($todo->id)->exec(); + } + + return true; + } }