private static function putEvents($newEvents) { $pool = array(); foreach ($newEvents as $event) { $class = get_class($event); if (!isset($pool[$class])) { $pool[$class] = array(); } $pool[$class][] = $event; } foreach ($pool as $class => $list) { $class::saveEvents($class, $list); } User::flushCreateCache(); }
/** * Flush the user create cache inserting the users into the database * @param null|array $users A list of the users to insert into the db. If null the internal cache is flushed */ public static function flushCreateCache($users = null) { if (is_null($users)) { User::flushCreateCache(User::$createCache); } else { if (count($users) > 500) { $chunks = array_chunk($users, 500); foreach ($chunks as $chunk) { User::flushCreateCache($chunk); } } else { if (count($users) > 0) { $sql = "INSERT INTO users (id, username, client_id) VALUES "; $chunks = array(); foreach ($users as $user) { $chunks[] = "(" . $user->id . ", " . DB::$DB->quote($user->username) . ", " . $user->client_id . ")"; } $sql .= implode(", ", $chunks); DB::$DB->query($sql); } } } }