/** * 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; }
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); }