* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ global $mod_strings; global $sugar_config; if (!isset($_REQUEST['record'])) { sugar_die($mod_strings['ERR_DELETE_RECORD']); } $focus = BeanFactory::getBean('KBDocuments', $_REQUEST['record']); if (!$focus->ACLAccess('Delete')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //Retrieve all related kbdocument revisions. $kbdocrevs = KBDocument::get_kbdocument_revisions($_REQUEST['record']); //Loop through kbdocument revisions and delete one by one. if (!empty($kbdocrevs) && is_array($kbdocrevs)) { foreach ($kbdocrevs as $key => $thiskbid) { $thiskbversion = BeanFactory::getBean('KBDocumentRevisions', $thiskbid); //Check for related documentrevision and delete. if ($thiskbversion->document_revision_id != null) { $docrev_id = $thiskbversion->document_revision_id; $thisdocrev = BeanFactory::getBean('DocumentRevisions', $docrev_id); UploadFile::unlink_file($docrev_id, $thisdocrev->filename); UploadFile::unlink_file($docrev_id); //mark version deleted $thisdocrev->mark_deleted($thisdocrev->id); } //Also check for related kbcontent and delete. if ($thiskbversion->kbcontent_id != null) {
//PARAMN_ are node level parameters. $json = getJSONobj(); $selectedArticles = $json->decode(html_entity_decode($_REQUEST['selectedArticles'])); if (isset($selectedArticles['jsonObject']) && $selectedArticles['jsonObject'] != null) { $selectedArticles = $selectedArticles['jsonObject']; } foreach ($selectedArticles as $articleId) { if (!empty($articleId)) { //retrieve article $kbarticle = BeanFactory::getBean('KBDocuments', $articleId); $deleted = 1; //also retrieve children and check if there is any article linked $kbarticle->deleted = 1; $kbarticle->save(); //also delete related $kbdocrevs = KBDocument::get_kbdocument_revisions($articleId); if (!empty($kbdocrevs) && is_array($kbdocrevs)) { foreach ($kbdocrevs as $key => $thiskbid) { $thiskbversion = BeanFactory::getBean('KBDocumentRevisions', $thiskbid); $docrev_ids = KBDocumentRevision::get_docrevs($thiskbid); foreach ($docrev_ids as $key => $thisdocrevid) { $thisdocrev = BeanFactory::getBean('DocumentRevisions', $thisdocrevid); UploadFile::unlink_file($thisdocrevid, $thisdocrev->filename); //mark version deleted $thisdocrev->mark_deleted($thisdocrev->id); //also retrieve the content if ($thisdocrev->file_ext == null && $thisdocrev->file_mime_type == null) { //this is content retrieve and mark it delete } } //mark kbdoc revision deleted