<?php
 class vB_Undo_Item_Unsubscribe extends vB_Undo_Item { use vB_Trait_NoSerialize; protected array $subscribediscussion = []; protected array $serializefields = [ 'userid', 'subscribediscussion', ]; public static function create(int $userid, array $subscribediscussion) : self { foreach ($subscribediscussion AS $__row) { if (!isset($__row['discussionid']) OR !isset($__row['emailupdate'])) { throw new Exception('invalid_data'); } } $item = new self(); $item->userid = $userid; $item->subscribediscussion = $subscribediscussion; return $item; } public function run() : mixed { if (empty($this->userid)) { return null; } $db = vB::getDbAssertor(); $nodeLib = vB_Library::instance('node'); $nodeids = []; $noperms = []; foreach ($this->subscribediscussion AS $__row) { if (!isset($__row['discussionid']) OR !isset($__row['emailupdate'])) { continue; } $__nodeid = $__row['discussionid']; $params = [ vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERT, 'userid' => $this->userid, 'discussionid' => $__nodeid, 'emailupdate' => $__row['emailupdate'], ]; $dupecheck = $db->assertQuery('vBForum:subscribediscussion', ['userid' => $this->userid, 'discussionid' => $__nodeid]); if (!$dupecheck->valid()) { $__node = $nodeLib->getNodeBare($__nodeid); $__contentLib = vB_Library_Content::getContentLib($__node['contenttypeid']); if ($__contentLib->validate($__node, vB_Library_Content::ACTION_VIEW, $__nodeid, [$__nodeid => $__node], $this->userid)) { $db->assertQuery('vBForum:subscribediscussion', $params); $nodeids[] = $__nodeid; } else { $noperms[] = $__nodeid; } } } return [ 'discussionids' => $nodeids, 'noperms' => $noperms, ]; } } 