/** * Purge fake content from the database * TODO: Implement MultiRedirect support * TODO: This is horribly inefficient (rewrite this as an IN() query and manually construct data) * * @param array $values Generator form values */ protected function _purgeContent($values) { foreach ($values['content_types'] as $class) { $fakes = \IPS\faker\Faker::allFake($class); foreach ($fakes as $fake) { try { $obj = $class::load($fake->content_id); $obj->delete(); } catch (\OutOfRangeException $e) { } $fake->delete(); } } }
/** * Return a random fake member account (or guest account if none exist) * * @return \IPS\Member */ public function fakeMember() { if ($fakes = \IPS\faker\Faker::allFake('\\IPS\\Member')) { $fakeIds = array(); foreach ($fakes as $fake) { $fakeIds[$fake->content_id] = $fake; } /* If a fake member account has been deleted, remove the map and try again */ while ($fakeIds) { $fid = array_rand($fakeIds); try { return \IPS\Member::load($fid); } catch (\UnderflowException $e) { $fake = $fakeIds[$fid]; $fake->delete(); unset($fakeIds[$fid]); } } } return $this->guest(); }