public function moveTmpFileToFile($userId, $insertToken, $articleId) { $valid = false; if ($userId && $insertToken) { $uploadTmpTbl = new VC_DbTable_Common("upload_tmp", "id"); $listTmpUploadFiles = $uploadTmpTbl->fetchAll("user_id = " . $userId . " AND insert_token = '" . $insertToken . "'"); $fileTbl = new VC_DbTable_Common("store_file", "id"); $articleFileTbl = new VC_DbTable_Common("store_article_file", "article_id"); foreach ($listTmpUploadFiles as $tmpFile) { $fileData = array(); $fileData['name'] = $tmpFile['file_name']; $fileData['file_name'] = $tmpFile['file_name']; $fileData['user_id'] = $userId; $fileData['file_path'] = $tmpFile['file_path']; $fileData['icon_path'] = $tmpFile['icon_path']; $fileData['upload_date'] = $tmpFile['upload_date']; $fileId = $fileTbl->insert($fileData); //Insert into article_file $articleFileTbl->insert(array('article_id' => $articleId, 'file_id' => $fileId, "user_id" => $userId)); } //Remove old file $oldFileSql = "CURDATE() - INTERVAL 2 DAY >= upload_date"; $allOldFile = $uploadTmpTbl->fetchAll($oldFileSql); foreach ($allOldFile as $oldFile) { @unlink(ROOT_PATH . '/Sources/store/public' . $oldFile->file_path); } //Remove all file by token and post time $delSql = "(user_id = " . $userId . " AND insert_token = '" . $insertToken . "') "; $delSql .= " OR CURDATE() - INTERVAL 2 DAY >= upload_date"; $uploadTmpTbl->delete($delSql); //delete file in hdd $valid = true; } return $valid; }
public function editAction() { $articleId = (int) $this->_getParam('id'); if ($articleId == 0) { throw new VC_Exception("Invalid article delete information"); } $insertTokenNamespace = new Zend_Session_Namespace("INSERT_TOKEN"); $message = ""; //Check if this article belong with this user $articleTbl = new VC_DbTable_Store_Article(); $article = $articleTbl->findByIdAndUserId($articleId, $this->userId); if ($article) { if ($this->_getParam('submit')) { if ($this->_getParam('title') && $this->_getParam('content') && $this->_getParam('tpid')) { $updateData = array(); $updateData['title'] = $this->_getParam('title'); $updateData['content'] = $this->_getParam('content'); $updateData['root_link'] = $this->_getParam('root_link'); $updateData['topic_id'] = $this->_getParam('tpid'); $articleTbl->update($updateData, "id = " . $articleId); $this->_redirect("article/view/?tpid=" . $article->topic_id . "&id=" . $articleId); } else { $message = "Bạn phải nhập đầy đủ các phần có dấu sao (*)"; } } $menuObj = new VC_Business_MenuFactory(); $groupAndTopic = $menuObj->getGroupsAndTopicsOfUser($this->userId); //echo "<pre>"; var_dump($groupAndTopic); echo "</pre>"; die; $this->view->groupAndTopic = $groupAndTopic; $this->view->message = $message; $this->view->article = $article; $this->view->insertToken = $insertTokenNamespace->insertToken; //Get all temp file uploaded of this article $uploadTmpTbl = new VC_DbTable_Common("upload_tmp", "id"); $this->view->listUploadFiles = $uploadTmpTbl->fetchAll("user_id = " . $this->userId . " AND insert_token = '" . $insertTokenNamespace->insertToken . "'"); } else { throw new VC_Exception("This article not belong with you"); } }