From e56c8ee2a190123ff0e0813b98540039bcf1bbab Mon Sep 17 00:00:00 2001 From: ovclas Date: Wed, 8 Jun 2011 02:26:45 +0000 Subject: [PATCH] issue 27 comment status refactoring git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8460 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- addons/blogapi/blogapi.addon.php | 4 +- modules/document/document.class.php | 41 ++++++++++++++++++- modules/document/document.controller.php | 36 +++++++++++++--- modules/document/document.item.php | 4 +- modules/document/queries/insertDocument.xml | 3 +- modules/document/queries/updateDocument.xml | 3 +- .../queries/updateDocumentCommentStatus.xml | 12 ++++++ .../updateDocumentsAllowCommentTrackback.xml | 2 +- modules/document/schemas/documents.xml | 3 +- .../importer/importer.admin.controller.php | 3 +- modules/importer/ttimport.class.php | 6 +-- modules/module/module.model.php | 14 +++++++ 12 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 modules/document/queries/updateDocumentCommentStatus.xml diff --git a/addons/blogapi/blogapi.addon.php b/addons/blogapi/blogapi.addon.php index c17ecb9ed..5dfd4c6a2 100644 --- a/addons/blogapi/blogapi.addon.php +++ b/addons/blogapi/blogapi.addon.php @@ -243,7 +243,7 @@ $obj->content = str_replace($uploaded_target_path,sprintf('/files/attach/images/%s/%s%s', $this->module_srl, getNumberingPath($document_srl,3), $filename), $obj->content); $oDocumentController = &getController('document'); - $obj->allow_comment = 'Y'; + $obj->commentStatus = 'ALLOW'; $obj->allow_trackback = 'Y'; $output = $oDocumentController->insertDocument($obj); @@ -403,7 +403,7 @@ $post->publish = 1; $post->userid = $oDocument->get('user_id'); $post->mt_allow_pings = 0; - $post->mt_allow_comments = $oDocument->allowComment()=='Y'?1:0; + $post->mt_allow_comments = $oDocument->allowComment()?1:0; $posts[] = $post; } $content = getXmlRpcResponse($posts); diff --git a/modules/document/document.class.php b/modules/document/document.class.php index df5881cf0..aede49cb2 100644 --- a/modules/document/document.class.php +++ b/modules/document/document.class.php @@ -106,6 +106,9 @@ //2011. 05. 23 adding status column to document if(!$oDB->isColumnExists('documents', 'status')) return true; + //2011. 06. 07 check comment status update + if($oDB->isColumnExists('documents', 'allow_comment') || $oDB->isColumnExists('documents', 'lock_comment')) return true; + return false; } @@ -251,8 +254,42 @@ $oDB->dropColumn('documents', 'is_secret'); } - return new Object(0,'success_updated'); + //2011. 06. 07 merge column, allow_comment and lock_comment + if($oDB->isColumnExists('documents', 'allow_comment') || $oDB->isColumnExists('documents', 'lock_comment')) + { + $oDB->addColumn('documents', 'comment_status', 'varchar', 20, 'ALLOW'); + $columnList = array('module_srl'); + $moduleSrlList = $oModuleModel->getModuleSrlList(null, $columnList); + $args->commentStatus = 'DENY'; + $isSuccessUpdated = true; + + // allow_comment='Y', lock_comment='Y' + $args->allowComment = 'Y'; + $args->lockComment = 'Y'; + $output = executeQuery('document.updateDocumentCommentStatus', $args); + if(!$output->toBool()) $isSuccessUpdated = false; + + // allow_comment='N', lock_comment='Y' + $args->allowComment = 'N'; + $args->lockComment = 'Y'; + $output = executeQuery('document.updateDocumentCommentStatus', $args); + if(!$output->toBool()) $isSuccessUpdated = false; + + // allow_comment='N', lock_comment='N' + $args->allowComment = 'N'; + $args->lockComment = 'N'; + $output = executeQuery('document.updateDocumentCommentStatus', $args); + if(!$output->toBool()) $isSuccessUpdated = false; + + if($isSuccessUpdated) + { + $oDB->dropColumn('documents', 'allow_comment'); + $oDB->dropColumn('documents', 'lock_comment'); + } + } + + return new Object(0,'success_updated'); } /** @@ -278,7 +315,7 @@ function getConfigStatus($key) { - if(array_key_exists($key, $this->statusList)) return $this->statusList[$key]; + if(array_key_exists(strtolower($key), $this->statusList)) return $this->statusList[$key]; else $this->getDefaultStatus(); } } diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index f0f08ec9e..301a63a0f 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -141,8 +141,8 @@ class documentController extends document { $oDB = &DB::getInstance(); $oDB->begin(); // List variables - if($obj->allow_comment!='Y') $obj->allow_comment = 'N'; - if($obj->lock_comment!='Y') $obj->lock_comment = 'N'; + if(!$obj->commentStatus) $obj->commentStatus = 'DENY'; + if($obj->commentStatus == 'DENY') $this->_checkCommentStatusForOldVersion(&$obj); if($obj->allow_trackback!='Y') $obj->allow_trackback = 'N'; if($obj->homepage && !preg_match('/^[a-z]+:\/\//i',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; if($obj->notify_message != 'Y') $obj->notify_message = 'N'; @@ -201,6 +201,9 @@ class documentController extends document { $obj->lang_code = Context::getLangType(); // Insert data into the DB + debugPrint($obj->status); + if(!$obj->status) $this->_checkDocumentStatusForOldVersion(&$obj); + debugPrint($obj->status); $output = executeQuery('document.insertDocument', $obj); if(!$output->toBool()) { $oDB->rollback(); @@ -275,8 +278,8 @@ class documentController extends document { $obj->ipaddress = $source_obj->get('ipaddress'); } // List variables - if($obj->allow_comment!='Y') $obj->allow_comment = 'N'; - if($obj->lock_comment!='Y') $obj->lock_comment = 'N'; + if(!$obj->commentStatus) $obj->commentStatus = 'DENY'; + if($obj->commentStatus == 'DENY') $this->_checkCommentStatusForOldVersion(&$obj); if($obj->allow_trackback!='Y') $obj->allow_trackback = 'N'; if($obj->homepage && !preg_match('/^[a-z]+:\/\//i',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; if($obj->notify_message != 'Y') $obj->notify_message = 'N'; @@ -544,8 +547,8 @@ class documentController extends document { $oTrashVO->setRemoverSrl($logged_info->member_srl); $oTrashVO->setRegdate(date('YmdHis')); - $oTrashController = &getController('trash'); - $output = $oTrashController->insertTrash($oTrashVO); + $oTrashAdminController = &getAdminController('trash'); + $output = $oTrashAdminController->insertTrash($oTrashVO); if (!$output->toBool()) { $oDB->rollback(); return $output; @@ -1683,5 +1686,26 @@ class documentController extends document { $this->setMessage('success_saved'); $this->add('document_srl', $obj->document_srl); } + + /** + * @brief for old version, comment allow status check. + **/ + function _checkCommentStatusForOldVersion(&$obj) + { + if(!isset($obj->allow_comment)) $obj->allow_comment = 'N'; + if(!isset($obj->lock_comment)) $obj->lock_comment = 'N'; + + if($obj->allow_comment == 'Y' && $obj->lock_comment == 'N') $obj->commentStatus = 'ALLOW'; + else $obj->commentStatus = 'DENY'; + } + + /** + * @brief for old version, document status check. + **/ + function _checkDocumentStatusForOldVersion(&$obj) + { + if(!$obj->status && $obj->is_secret == 'Y') $obj->status = $this->getConfigStatus('secret'); + if(!$obj->status && $obj->is_secret != 'Y') $obj->status = $this->getConfigStatus('public'); + } } ?> diff --git a/modules/document/document.item.php b/modules/document/document.item.php index d787b0358..00c1767bb 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -90,7 +90,7 @@ function allowComment() { if(!$this->isExists()) return true; - return $this->get('allow_comment') == 'Y' ? true : false; + return $this->get('comment_status') == 'ALLOW' ? true : false; } function allowTrackback() { @@ -113,7 +113,7 @@ } function isLocked() { - return $this->get('lock_comment') == 'Y' ? true : false; + return $this->get('comment_status') == 'ALLOW' ? false : true; } function isEditable() { diff --git a/modules/document/queries/insertDocument.xml b/modules/document/queries/insertDocument.xml index f6e3cdd0a..c7d537ebe 100644 --- a/modules/document/queries/insertDocument.xml +++ b/modules/document/queries/insertDocument.xml @@ -33,10 +33,9 @@ - - + diff --git a/modules/document/queries/updateDocument.xml b/modules/document/queries/updateDocument.xml index 27df14679..47411ad8b 100644 --- a/modules/document/queries/updateDocument.xml +++ b/modules/document/queries/updateDocument.xml @@ -26,11 +26,10 @@ - - + diff --git a/modules/document/queries/updateDocumentCommentStatus.xml b/modules/document/queries/updateDocumentCommentStatus.xml new file mode 100644 index 000000000..e06829015 --- /dev/null +++ b/modules/document/queries/updateDocumentCommentStatus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/modules/document/queries/updateDocumentsAllowCommentTrackback.xml b/modules/document/queries/updateDocumentsAllowCommentTrackback.xml index f425d8934..bf2733dab 100644 --- a/modules/document/queries/updateDocumentsAllowCommentTrackback.xml +++ b/modules/document/queries/updateDocumentsAllowCommentTrackback.xml @@ -3,7 +3,7 @@
- + diff --git a/modules/document/schemas/documents.xml b/modules/document/schemas/documents.xml index 6ec6a2e9c..1f45a3a7d 100644 --- a/modules/document/schemas/documents.xml +++ b/modules/document/schemas/documents.xml @@ -29,9 +29,8 @@ - - +
diff --git a/modules/importer/importer.admin.controller.php b/modules/importer/importer.admin.controller.php index ed3101602..d6877e312 100644 --- a/modules/importer/importer.admin.controller.php +++ b/modules/importer/importer.admin.controller.php @@ -559,8 +559,7 @@ if(!$obj->last_update) $obj->last_update = $obj->regdate; $obj->ipaddress = base64_decode($xmlDoc->post->ipaddress->body); $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->allow_comment = base64_decode($xmlDoc->post->allow_comment->body)!='N'?'Y':'N'; - $obj->lock_comment = base64_decode($xmlDoc->post->lock_comment->body)=='Y'?'Y':'N'; + $obj->commentStatus = base64_decode($xmlDoc->post->allow_comment->body)!='N'?'ALLOW':'DENY'; $obj->allow_trackback = base64_decode($xmlDoc->post->allow_trackback->body)!='N'?'Y':'N'; $obj->notify_message = base64_decode($xmlDoc->post->is_notice->body); // Change content information (attachment) diff --git a/modules/importer/ttimport.class.php b/modules/importer/ttimport.class.php index b1a03c891..15698a8da 100644 --- a/modules/importer/ttimport.class.php +++ b/modules/importer/ttimport.class.php @@ -117,7 +117,7 @@ $obj->title = $xmlDoc->post->title->body; $obj->content = $xmlDoc->post->content->body; $obj->password = md5($xmlDoc->post->password->body); - $obj->allow_comment = $xmlDoc->post->acceptcomment->body=='1'?'Y':'N'; + $obj->commentStatus = $xmlDoc->post->acceptcomment->body=='1'?'ALLOW':'DENY'; $obj->allow_trackback = $xmlDoc->post->accepttrackback->body=='1'?'Y':'N'; //$obj->allow_comment = $xmlDoc->post->acceptComment->body=='1'?'Y':'N'; //$obj->allow_trackback = $xmlDoc->post->acceptTrackback->body=='1'?'Y':'N'; @@ -144,7 +144,6 @@ $obj->homepage = $member_info->homepage; $obj->ipaddress = $_REMOTE['SERVER_ADDR']; $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->lock_comment = 'N'; $obj->notify_message = 'N'; // Change content information (attachment) $obj->content = str_replace('[##_ATTACH_PATH_##]/','',$obj->content); @@ -282,7 +281,7 @@ $obj->title = cut_str(strip_tags($obj->content),20,'...'); if ($obj->title == '') $obj->title = 'Untitled'; - $obj->allow_comment = 'Y'; + $obj->commentStatus = 'ALLOW'; $obj->allow_trackback = 'N'; $obj->regdate = date("YmdHis",$val->written->body); $obj->last_update = date("YmdHis", $val->written->body); @@ -307,7 +306,6 @@ } $obj->ipaddress = $val->commenter->ip->body; $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->lock_comment = 'N'; $obj->notify_message = 'N'; $obj->trackback_count = 0; diff --git a/modules/module/module.model.php b/modules/module/module.model.php index 2f1d9e8a0..217b7cad8 100644 --- a/modules/module/module.model.php +++ b/modules/module/module.model.php @@ -227,6 +227,20 @@ return $mid_list; } + /** + * @brief Get a complete list of module_srl, which is created in the DB + **/ + function getModuleSrlList($args = null, $columnList = array()) + { + $output = executeQueryArray('module.getMidList', $args, $columnList); + if(!$output->toBool()) return $output; + + $list = $output->data; + if(!$list) return; + + return $list; + } + /** * @brief Return an array of module_srl corresponding to a mid list **/