/** * Undelete a set of nodes * @param array $nodeids * @param boolean is rebuild needed * @throws vB_Exception_Api * @return array - the nodeids that have been deleted */ public function undeleteNodes($nodeids, $needRebuild = false) { if (empty($nodeids)) { return false; } $errors = array(); $events = array(); $loginfo = array(); $counts = $updates = array(); $nodeids = array_unique($nodeids); $assertor = vB::getDbAssertor(); $result = $assertor->assertQuery('vBForum:node', array('nodeid' => $nodeids, 'deleteuserid' => 0, 'deletereason' => '', 'unpublishdate' => 0, 'showpublished' => 1, vB_db_Query::TYPE_KEY => vB_db_Query::QUERY_UPDATE)); if (!empty($result['errors'])) { $errors[] = $result['errors']; } $searchAPI = vB_Api::instanceInternal('Search'); foreach ($nodeids as $nodeid) { $events[] = $nodeid; $result = $this->publishChildren($nodeid); if (!empty($result['errors'])) { $errors[] = $result['errors']; } // Clear cache for this node or user post count won't update vB_Cache::allCacheEvent('nodeChg_' . $nodeid); $node = $this->getNode($nodeid); // Update user post count (un(soft)delete) vB_Library_Content::getContentLib($node['contenttypeid'])->incrementUserPostCount($node); $loginfo[] = array('nodeid' => $node['nodeid'], 'nodetitle' => $node['title'], 'nodeusername' => $node['authorname'], 'nodeuserid' => $node['userid']); $parents = $this->fetchClosureParent($nodeid); foreach ($parents as $parent) { $nodeInfo = $this->getNodeBare($parent['parent']); if ($nodeInfo['contenttypeid'] == $this->channelTypeId) { $result = $this->fixNodeLast($parent['parent']); } else { $result = $assertor->assertQuery('vBForum:updateLastData', array('parentid' => $parent['parent'], 'timenow' => vB::getRequest()->getTimeNow())); } if (!empty($result['errors'])) { $errors[] = $result['errors']; } switch ($parent['depth']) { case 0: // Actual node. vB_Node::fixNodeCount($parent['parent']); break; case 1: // Immediate parent. $parentinfo = $this->getNodeBare($parent['parent']); $counts = array('totalcount' => $parentinfo['totalcount'], 'totalunpubcount' => $parentinfo['totalunpubcount']); vB_Node::fixNodeCount($parent['parent']); $parentinfo = $this->getNodeBare($parent['parent']); $counts = array('totalcount' => $parentinfo['totalcount'] - $counts['totalcount'], 'totalunpubcount' => $parentinfo['totalunpubcount'] - $counts['totalunpubcount']); break; default: // Higher parents. $updates['totalcount'][$parent['parent']] = $counts['totalcount']; $updates['totalunpubcount'][$parent['parent']] = $counts['totalunpubcount']; break; } } $assertor->assertQuery('vBForum:updateNodeTotals', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'updates' => $updates)); $searchAPI->attributeChanged($nodeid); } $searchAPI->purgeCacheForCurrentUser(); if ($needRebuild) { vB::getUserContext()->rebuildGroupAccess(); vB_Channel::rebuildChannelTypes(); } $this->clearCacheEvents($nodeids); $this->clearChildCache($nodeids); if (!empty($errors)) { return array('errors' => $errors); } vB_Library_Admin::logModeratorAction($loginfo, 'node_restored_by_x'); return $nodeids; }