コード例 #1
0
ファイル: channel.php プロジェクト: cedwards-reisys/nexus-web
 protected static function updateContentRoute($oldRouteInfo, $newRouteInfo)
 {
     $db = vB::getDbAssertor();
     $events = array();
     $events[] = "vB_ChannelStructure_chg";
     // invalidate vB_ChTree... record so that channels' routes are updated
     // update redirect301 fields
     $updateIds = $db->assertQuery('get_update_route_301', array('oldrouteid' => $oldRouteInfo['routeid']));
     if (!empty($updateIds)) {
         $routeIds = array();
         foreach ($updateIds as $route) {
             $routeid = $route['routeid'];
             $events[] = "routeChg_{$routeid}";
             $routeIds[] = $routeid;
         }
         $db->update('routenew', array('redirect301' => $newRouteInfo['routeid'], 'name' => vB_dB_Query::VALUE_ISNULL), array('routeid' => $routeIds));
     }
     // update routeid in nodes table
     $updateIds = $db->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('nodeid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $oldRouteInfo['routeid'])));
     if (!empty($updateIds)) {
         $nodeIds = array();
         foreach ($updateIds as $node) {
             $nodeid = $node['nodeid'];
             // this does not affect parents, so we don't need to clear they cache
             $events[] = "nodeChg_{$nodeid}";
             $nodeIds[] = $nodeid;
         }
         $db->update('vBForum:node', array('routeid' => $newRouteInfo['routeid']), array('nodeid' => $nodeIds));
     }
     // don't modify the routeid for default pages, as it will still be used
     $updateIds = $db->assertQuery('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('pageid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $oldRouteInfo['routeid'], 'pagetype' => vB_Page::TYPE_CUSTOM)));
     if (!empty($updateIds)) {
         $pageIds = array();
         foreach ($updateIds as $page) {
             $pageid = $page['pageid'];
             $events[] = "pageChg_{$pageid}";
             $pageIds[] = $pageid;
         }
         $db->update('page', array('routeid' => $newRouteInfo['routeid']), array('pageid' => $pageIds));
     }
     /* The code below implies that multiple conversation routes could exist under a single channel. However, I don't know
      *	when this might be the case. When moving channels/topics, the routes are untouched. Topic redirects are handled by
      *	the redirect & node tables.
      */
     // update conversation generic route
     $routes = $db->getRows('routenew', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'class', 'value' => array('vB5_Route_Conversation', 'vB5_Route_Article')), array('field' => 'prefix', 'value' => $oldRouteInfo['prefix']), array('field' => 'contentid', 'value' => $oldRouteInfo['channelid']), array('field' => 'redirect301', 'operator' => vB_dB_Query::OPERATOR_ISNULL))));
     foreach ($routes as $route) {
         $events[] = "routeChg_{$route['routeid']}";
         //if the old route has a name, clear it.  Only one route should ever have a name and it belongs to the route
         //we are about to create.
         if ($route['name']) {
             $db->update('routenew', array('name' => vB_dB_Query::VALUE_ISNULL), array('routeid' => $route['routeid']));
         }
         // create new conversation route using most of the old route's data
         $newConversationRoute = $route;
         unset($newConversationRoute['routeid']);
         unset($newConversationRoute['redirect301']);
         $newConversationRoute['prefix'] = $newRouteInfo['prefix'];
         // special case, if prefix is empty (i.e. this is a new home page) then we must leave out the leading '/',
         // or selectBestRoute will not be able to match the path (which never has a leading '/') to regex.
         $newConversationRoute['regex'] = ($newRouteInfo['prefix'] === '' ? '' : preg_quote($newRouteInfo['prefix']) . '/') . vB5_Route_Conversation::REGEXP;
         // save the new route. If you need to call validInput(), be sure to unset prefix first, otherwise it'll think it's
         // a custom conversation url (as opposed to custom channel url, which this is)
         $newConversationRouteid = vB5_Route_Conversation::saveRoute($newConversationRoute);
         if (is_array($newConversationRouteid)) {
             $newConversationRouteid = (int) array_pop($newConversationRouteid);
         }
         // then update old convo route's redirect301
         $db->update('routenew', array('redirect301' => $newConversationRouteid), array('routeid' => $route['routeid']));
         // update routeids for conversation nodes
         // Copied from the channel node updates above.
         $updateIds = $db->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('nodeid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $route['routeid'])));
         if (!empty($updateIds)) {
             $nodeIds = array();
             foreach ($updateIds as $node) {
                 $nodeid = $node['nodeid'];
                 // this does not affect parents, so we don't need to clear they cache
                 $events[] = "nodeChg_{$nodeid}";
                 $nodeIds[] = $nodeid;
             }
             // if there are ever cases of multiple conversation routes per channel, and they're sizable, it might be
             // worth creating a method query to handle all node updates at once instead of per conversation route.
             $db->update('vBForum:node', array('routeid' => $newConversationRouteid), array('nodeid' => $nodeIds));
         }
     }
     vB_Cache::allCacheEvent($events);
 }