public static function reassign($user, $posts)
{
if (!is_int($user)) {
$u = User::get($user);
$user = $u->id;
}
// safety checks
if ($user == 0 || empty($posts)) {
return false;
}
switch (true) {
case is_integer(reset($posts)):
break;
case reset($posts) instanceof Post:
$ids = array();
foreach ($posts as $post) {
$ids[] = $post->id;
}
$posts = $ids;
break;
default:
return false;
}
$ids = implode(',', $posts);
// allow plugins the opportunity to prevent the reassignment now that we've verified the user and posts
$allow = true;
$allow = Plugins::filter('posts_reassign_allow', $allow, $user, $posts);
if (!$allow) {
return false;
}
// actually perform the reassignment
Plugins::act('posts_reassign_before', array($user, $posts));
$results = DB::query("UPDATE {posts} SET user_id=? WHERE id IN ({$ids})", array($user));
Plugins::act('posts_reassign_after', array($user, $posts));
return $results;
}