MC/website/integrations/mybb/test-board-key-recovery.php
2026-11-27 23:43:05 +00:00

18 lines
2.6 KiB
PHP

<?php
define('IN_MYBB',1);
function my_strlen($s){return strlen($s);}function my_substr($s,$start,$length){return substr($s,$start,$length);}
require __DIR__.'/system-board-provision.php';
final class RecoveryRows{public function __construct(public array $rows){}}
final class RecoveryDB{
public array $forums=[1=>['fid'=>1,'pid'=>0,'type'=>'c','parentlist'=>'1','name'=>'Root','description'=>'']];public array $registry=[],$groups=[];public bool $interrupt=true;
function escape_string($s){return addslashes($s);}
function fetch_array($q){return array_shift($q->rows);}
function simple_select($table,$fields='*',$where='', $options=[]){$rows=$table==='forums'?$this->forums:($table==='usergroups'?$this->groups:$this->registry);return new RecoveryRows(array_values(array_filter($rows,function($r)use($where){foreach(['kind','organisation_id','description']as $k)if(preg_match("/".$k."='([^']*)'/",$where,$m)&&($r[$k]??null)!==stripslashes($m[1]))return false;if(preg_match('/fid=(\d+)/',$where,$m)&&(int)$r['fid']!==(int)$m[1])return false;return true;})));}
function insert_query($table,$row){if($table==='dune_system_boards'){if($this->interrupt){$this->interrupt=false;throw new RuntimeException('Interrupted after native forum commit');}$row+=['member_gid'=>0,'leader_gid'=>0];$this->registry[]=$row;return 1;}if($table==='forums'){$id=count($this->forums)+1;$row['fid']=$id;$this->forums[$id]=$row;return $id;}if($table==='usergroups'){$id=count($this->groups)+14;$row['gid']=$id;$this->groups[$id]=$row;return $id;}throw new RuntimeException('Unexpected insert');}
function update_query($table,$values,$where){if($table==='forums'&&preg_match('/fid=(\d+)/',$where,$m))$this->forums[(int)$m[1]]=array_merge($this->forums[(int)$m[1]],$values);}
}
$db=new RecoveryDB();$dune_board_template=$db->forums[1];$id='11111111-1111-4111-8111-111111111111';
try{dune_provision_make_board('clan',$id,'Clan',1,'f');throw new RuntimeException('Interruption did not occur');}catch(RuntimeException $e){if($e->getMessage()!=='Interrupted after native forum commit')throw $e;}
$board=dune_provision_make_board('clan',$id,'Clan',1,'f');if((int)$board['fid']!==2||count($db->forums)!==2||count($db->registry)!==1)throw new RuntimeException('Interrupted forum was duplicated');
$org=['kind'=>'clan','id'=>$id];[$gid]=dune_provision_board_group($org,'member_gid','Members',['gid'=>2,'cancp'=>0,'issupermod'=>0]);[$again]=dune_provision_board_group($org,'member_gid','Renamed members',['gid'=>2]);if($gid!==$again||count($db->groups)!==1)throw new RuntimeException('Interrupted native group was duplicated');
echo "MyISAM interruption preserves forum/group identity without a false rollback guarantee\n";