Exemple #1
0
 public function update($nodeid, $data, $convertWysiwygTextToBbcode = true)
 {
     $loginuser =& vB::getCurrentSession()->fetch_userinfo();
     $usercontext =& vB::getUserContext($loginuser['userid']);
     if (!$usercontext->getCanModerate($nodeid)) {
         throw new Exception('no_permission');
     }
     $existing = $this->nodeApi->getNode($nodeid);
     $this->checkPollOptions($data);
     $options = $data['options'];
     $oldnode = $this->getContent($nodeid);
     $oldnode = $oldnode[$nodeid];
     // skip the index in the parent and do it here so it can include the options
     $data['noIndex'] = true;
     if (isset($data['parseurl'])) {
         $parseurl = $data['parseurl'];
         if ($parseurl) {
             require_once DIR . '/includes/functions_newpost.php';
         }
     }
     unset($data['options'], $data['parseurl']);
     $result = parent::update($nodeid, $data, $convertWysiwygTextToBbcode);
     $oldoptionids = array();
     $optionids = array();
     foreach ($oldnode['options'] as $option) {
         $oldoptionids[$option['polloptionid']] = $option['polloptionid'];
     }
     // Save poll options
     foreach ($options as $option) {
         if (isset($parseurl) and $parseurl) {
             $option['title'] = convert_url_to_bbcode($option['title']);
         }
         if (!empty($option['polloptionid'])) {
             // Check if the polloption belongs to the poll (node)
             $polloption = $this->assertor->getRow('vBForum:polloption', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $nodeid));
             if ($polloption['nodeid'] == $nodeid) {
                 $votes = $this->assertor->getRows('vBForum:pollvote', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'polloptionid' => $option['polloptionid']));
                 $voters = array();
                 foreach ($votes as $vote) {
                     if (!in_array($vote['userid'], $voters)) {
                         $voters[] = $vote['userid'];
                     }
                 }
                 $this->assertor->assertQuery('vBForum:polloption', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'title' => $option['title'], 'votes' => count($votes), 'voters' => serialize($voters), vB_dB_Query::CONDITIONS_KEY => array('polloptionid' => $option['polloptionid'])));
                 $optionids[$option['polloptionid']] = $option['polloptionid'];
             } else {
                 throw new Exception('invalidid');
             }
         } else {
             // Insert new option
             $this->assertor->assertQuery('vBForum:polloption', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERT, 'nodeid' => $nodeid, 'title' => $option['title']));
         }
     }
     $optionstoremove = array_diff($oldoptionids, $optionids);
     if ($optionstoremove) {
         $this->assertor->assertQuery('vBForum:polloption', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'polloptionid' => $optionstoremove));
         //delete pollvotes
         $this->assertor->assertQuery('vBForum:pollvote', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'polloptionid' => $optionstoremove));
     }
     $this->updatePollCache($nodeid);
     $this->nodeApi->clearCacheEvents(array($nodeid, $existing['parentid']));
     // do the indexing after the options are added
     vB_Api::instance('Search')->index($nodeid);
     return $result;
 }
Exemple #2
0
 /**
  * 	updates a record
  *
  *	@param int $nodeid
  *	@param array $data -- The data for the node to be updated
  *	@param boolean $convertWysiwygTextToBbcode
  *
  * 	@return boolean
  */
 public function update($nodeid, $data, $convertWysiwygTextToBbcode = true)
 {
     // TODO: Permission check
     //		$loginuser = &vB::getCurrentSession()->fetch_userinfo();
     //		$usercontext = &vB::getUserContext($loginuser['userid']);
     //		if (!$usercontext->hasPermission('forumpermissions', 'canpostvideo'))
     //		{
     //			throw new Exception('no_permission');
     //		}
     $currentNode = vB_Library::instance('Node')->getNodeBare($nodeid);
     if ($currentNode['contenttypeid'] != vB_Types::instance()->getContentTypeID($this->contenttype)) {
         parent::changeContentType($nodeid, $currentNode['contenttypeid'], $this->contenttype);
         $data['contenttypeid'] = vB_Types::instance()->getContentTypeID($this->contenttype);
     }
     if (isset($data['videoitems'])) {
         $newvideoitems = $this->checkVideoData($data);
         unset($data['videoitems']);
     }
     $result = parent::update($nodeid, $data, $convertWysiwygTextToBbcode);
     // do not process videoitems if they are not provided
     if (!isset($data['videoitems'])) {
         return $result;
     }
     // Get a list of current video items
     $videoitems = $this->fetchVideoItems($nodeid);
     $oldvideoitemids = array();
     $newvideoitemids = array();
     foreach ($videoitems as $item) {
         $oldvideoitemids[$item['videoitemid']] = $item['videoitemid'];
     }
     foreach ($newvideoitems as $item) {
         $newvideoitemids[$item['videoitemid']] = $item['videoitemid'];
         $newvideoitemdata[$item['videoitemid']] = $item;
     }
     $itemstoremove = array_diff($oldvideoitemids, $newvideoitemids);
     $itemstoupdate = array_intersect($oldvideoitemids, $newvideoitemids);
     $itemstoinsert = array_diff($newvideoitemids, $oldvideoitemids);
     // Save video items
     foreach ($itemstoinsert as $itemid) {
         $this->assertor->assertQuery("videoitem", array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERT, 'nodeid' => $nodeid, 'provider' => $newvideoitemdata[$itemid]['provider'], 'code' => $newvideoitemdata[$itemid]['code'], 'url' => $newvideoitemdata[$itemid]['url']));
     }
     foreach ($itemstoupdate as $itemid) {
         $this->assertor->assertQuery("videoitem", array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'nodeid' => $nodeid, 'provider' => $newvideoitemdata[$itemid]['provider'], 'code' => $newvideoitemdata[$itemid]['code'], 'url' => $newvideoitemdata[$itemid]['url'], vB_dB_Query::CONDITIONS_KEY => array('videoitemid' => $itemid)));
     }
     foreach ($itemstoremove as $itemid) {
         $this->assertor->assertQuery("videoitem", array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'videoitemid' => $itemid));
     }
     // do the indexing after the options are added
     vB_Api::instance('Search')->index($nodeid);
     vB_Cache::instance(vB_Cache::CACHE_FAST)->event("nodeChg_{$nodeid}");
     vB_Cache::instance()->event("nodeChg_{$nodeid}");
     return $result;
 }
Exemple #3
0
 public function update($nodeid, $data, $convertWysiwygTextToBbcode = true)
 {
     $this->validateLinkData($data, __FUNCTION__);
     $currentNode = vB_Library::instance('Node')->getNodeBare($nodeid);
     // adjust refcounts if the image has changed (or been added/removed)
     if ($currentNode['filedataid'] != $data['filedataid']) {
         // decrement refcount for the previous image (if it had one)
         if ($currentNode['filedataid'] > 0) {
             vB::getDbAssertor()->assertQuery('updateFiledataRefCount', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'countChange' => -1, 'filedataid' => $currentNode["filedataid"]));
         }
         // increment refcount for the new image (if it has one)
         if ($data['filedataid'] > 0) {
             vB::getDbAssertor()->assertQuery('updateFiledataRefCount', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'countChange' => 1, 'filedataid' => $data["filedataid"]));
         }
     } else {
         // Auto-correct: set refcount to 1 if it's 0. This problem can be encountered
         // in databases that existed before VBV-11243 was fixed.
         vB::getDbAssertor()->update('filedata', array('refcount' => 1), array('filedataid' => $currentNode['filedataid'], 'refcount' => 0));
     }
     if ($currentNode['contenttypeid'] != vB_Types::instance()->getContentTypeID($this->contenttype)) {
         parent::changeContentType($nodeid, $currentNode['contenttypeid'], $this->contenttype);
         $data['contenttypeid'] = vB_Types::instance()->getContentTypeID($this->contenttype);
     }
     return parent::update($nodeid, $data, $convertWysiwygTextToBbcode);
 }