mirror of
https://github.com/flarum/core.git
synced 2025-08-02 22:47:33 +02:00
Merge branch 'master' into 1236-database-changes
This commit is contained in:
@@ -172,8 +172,13 @@ export default class DiscussionPage extends Page {
|
|||||||
// the 'discussion' relationship linked, then sorting and splicing.
|
// the 'discussion' relationship linked, then sorting and splicing.
|
||||||
let includedPosts = [];
|
let includedPosts = [];
|
||||||
if (discussion.payload && discussion.payload.included) {
|
if (discussion.payload && discussion.payload.included) {
|
||||||
|
const discussionId = discussion.id();
|
||||||
|
|
||||||
includedPosts = discussion.payload.included
|
includedPosts = discussion.payload.included
|
||||||
.filter(record => record.type === 'posts' && record.relationships && record.relationships.discussion)
|
.filter(record => record.type === 'posts'
|
||||||
|
&& record.relationships
|
||||||
|
&& record.relationships.discussion
|
||||||
|
&& record.relationships.discussion.data.id === discussionId)
|
||||||
.map(record => app.store.getById('posts', record.id))
|
.map(record => app.store.getById('posts', record.id))
|
||||||
.sort((a, b) => a.id() - b.id())
|
.sort((a, b) => a.id() - b.id())
|
||||||
.slice(0, 20);
|
.slice(0, 20);
|
||||||
|
@@ -21,7 +21,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
use Zend\Diactoros\Response\JsonResponse;
|
use Zend\Diactoros\Response\JsonResponse;
|
||||||
|
|
||||||
class TokenController implements RequestHandlerInterface
|
class CreateTokenController implements RequestHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\User\UserRepository
|
* @var \Flarum\User\UserRepository
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
|
use Flarum\Api\Serializer\CurrentUserSerializer;
|
||||||
use Flarum\Api\Serializer\UserSerializer;
|
use Flarum\Api\Serializer\UserSerializer;
|
||||||
use Flarum\User\UserRepository;
|
use Flarum\User\UserRepository;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -55,7 +56,7 @@ class ShowUserController extends AbstractShowController
|
|||||||
$actor = $request->getAttribute('actor');
|
$actor = $request->getAttribute('actor');
|
||||||
|
|
||||||
if ($actor->id == $id) {
|
if ($actor->id == $id) {
|
||||||
$this->serializer = 'Flarum\Api\Serializer\CurrentUserSerializer';
|
$this->serializer = CurrentUserSerializer::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->users->findOrFail($id, $actor);
|
return $this->users->findOrFail($id, $actor);
|
||||||
|
@@ -25,7 +25,7 @@ return function (RouteCollection $map, RouteHandlerFactory $route) {
|
|||||||
$map->post(
|
$map->post(
|
||||||
'/token',
|
'/token',
|
||||||
'token',
|
'token',
|
||||||
$route->toController(Controller\TokenController::class)
|
$route->toController(Controller\CreateTokenController::class)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Send forgot password email
|
// Send forgot password email
|
||||||
|
@@ -11,16 +11,16 @@
|
|||||||
|
|
||||||
namespace Flarum\Database;
|
namespace Flarum\Database;
|
||||||
|
|
||||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
|
||||||
class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The database connection resolver instance.
|
* The name of the database connection to use.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
* @var ConnectionInterface
|
||||||
*/
|
*/
|
||||||
protected $resolver;
|
protected $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the migration table.
|
* The name of the migration table.
|
||||||
@@ -29,23 +29,16 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
protected $table;
|
protected $table;
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the database connection to use.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $connection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new database migration repository instance.
|
* Create a new database migration repository instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||||
* @param string $table
|
* @param string $table
|
||||||
*/
|
*/
|
||||||
public function __construct(Resolver $resolver, $table)
|
public function __construct(ConnectionInterface $connection, $table)
|
||||||
{
|
{
|
||||||
|
$this->connection = $connection;
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
$this->resolver = $resolver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +97,7 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function createRepository()
|
public function createRepository()
|
||||||
{
|
{
|
||||||
$schema = $this->getConnection()->getSchemaBuilder();
|
$schema = $this->connection->getSchemaBuilder();
|
||||||
|
|
||||||
$schema->create($this->table, function ($table) {
|
$schema->create($this->table, function ($table) {
|
||||||
$table->string('migration');
|
$table->string('migration');
|
||||||
@@ -119,7 +112,7 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function repositoryExists()
|
public function repositoryExists()
|
||||||
{
|
{
|
||||||
$schema = $this->getConnection()->getSchemaBuilder();
|
$schema = $this->connection->getSchemaBuilder();
|
||||||
|
|
||||||
return $schema->hasTable($this->table);
|
return $schema->hasTable($this->table);
|
||||||
}
|
}
|
||||||
@@ -131,37 +124,6 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
protected function table()
|
protected function table()
|
||||||
{
|
{
|
||||||
return $this->getConnection()->table($this->table);
|
return $this->connection->table($this->table);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the connection resolver instance.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\ConnectionResolverInterface
|
|
||||||
*/
|
|
||||||
public function getConnectionResolver()
|
|
||||||
{
|
|
||||||
return $this->resolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve the database connection instance.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Connection
|
|
||||||
*/
|
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->resolver->connection($this->connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the information source to gather data.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setSource($name)
|
|
||||||
{
|
|
||||||
$this->connection = $name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Database;
|
namespace Flarum\Database;
|
||||||
|
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\DatabaseSettingsRepository;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Database\Schema\Builder;
|
use Illuminate\Database\Schema\Builder;
|
||||||
|
|
||||||
@@ -100,12 +99,20 @@ abstract class Migration
|
|||||||
public static function addSettings(array $defaults)
|
public static function addSettings(array $defaults)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'up' => function (SettingsRepositoryInterface $settings) use ($defaults) {
|
'up' => function (Builder $schema) use ($defaults) {
|
||||||
|
$settings = new DatabaseSettingsRepository(
|
||||||
|
$schema->getConnection()
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($defaults as $key => $value) {
|
foreach ($defaults as $key => $value) {
|
||||||
$settings->set($key, $value);
|
$settings->set($key, $value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'down' => function (SettingsRepositoryInterface $settings) use ($defaults) {
|
'down' => function (Builder $schema) use ($defaults) {
|
||||||
|
$settings = new DatabaseSettingsRepository(
|
||||||
|
$schema->getConnection()
|
||||||
|
);
|
||||||
|
|
||||||
foreach (array_keys($defaults) as $key) {
|
foreach (array_keys($defaults) as $key) {
|
||||||
$settings->delete($key);
|
$settings->delete($key);
|
||||||
}
|
}
|
||||||
@@ -130,7 +137,9 @@ abstract class Migration
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'up' => function (ConnectionInterface $db) use ($keys) {
|
'up' => function (Builder $schema) use ($keys) {
|
||||||
|
$db = $schema->getConnection();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$instance = $db->table('permissions')->where($key)->first();
|
$instance = $db->table('permissions')->where($key)->first();
|
||||||
|
|
||||||
@@ -140,7 +149,9 @@ abstract class Migration
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'down' => function (ConnectionInterface $db) use ($keys) {
|
'down' => function (Builder $schema) use ($keys) {
|
||||||
|
$db = $schema->getConnection();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$db->table('permissions')->where($key)->delete();
|
$db->table('permissions')->where($key)->delete();
|
||||||
}
|
}
|
||||||
|
@@ -52,12 +52,4 @@ interface MigrationRepositoryInterface
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function repositoryExists();
|
public function repositoryExists();
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the information source to gather data.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setSource($name);
|
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ class MigrationServiceProvider extends AbstractServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
||||||
return new DatabaseMigrationRepository($app['db'], 'migrations');
|
return new DatabaseMigrationRepository($app['flarum.db'], 'migrations');
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
||||||
|
@@ -13,7 +13,8 @@ namespace Flarum\Database;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
use Illuminate\Database\Schema\Builder;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
class Migrator
|
class Migrator
|
||||||
@@ -33,18 +34,11 @@ class Migrator
|
|||||||
protected $files;
|
protected $files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The connection resolver instance.
|
* The database schema builder instance.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
* @var Builder
|
||||||
*/
|
*/
|
||||||
protected $resolver;
|
protected $schemaBuilder;
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the default connection.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $connection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The notes for the current operation.
|
* The notes for the current operation.
|
||||||
@@ -57,17 +51,18 @@ class Migrator
|
|||||||
* Create a new migrator instance.
|
* Create a new migrator instance.
|
||||||
*
|
*
|
||||||
* @param MigrationRepositoryInterface $repository
|
* @param MigrationRepositoryInterface $repository
|
||||||
* @param Resolver $resolver
|
* @param ConnectionInterface $connection
|
||||||
* @param Filesystem $files
|
* @param Filesystem $files
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
MigrationRepositoryInterface $repository,
|
MigrationRepositoryInterface $repository,
|
||||||
Resolver $resolver,
|
ConnectionInterface $connection,
|
||||||
Filesystem $files
|
Filesystem $files
|
||||||
) {
|
) {
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
$this->resolver = $resolver;
|
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
|
||||||
|
$this->schemaBuilder = $connection->getSchemaBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,7 +194,7 @@ class Migrator
|
|||||||
protected function runClosureMigration($migration, $direction = 'up')
|
protected function runClosureMigration($migration, $direction = 'up')
|
||||||
{
|
{
|
||||||
if (is_array($migration) && array_key_exists($direction, $migration)) {
|
if (is_array($migration) && array_key_exists($direction, $migration)) {
|
||||||
app()->call($migration[$direction]);
|
call_user_func($migration[$direction], $this->schemaBuilder);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('Migration file should contain an array with up/down.');
|
throw new Exception('Migration file should contain an array with up/down.');
|
||||||
}
|
}
|
||||||
@@ -268,34 +263,6 @@ class Migrator
|
|||||||
return $this->notes;
|
return $this->notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve the database connection instance.
|
|
||||||
*
|
|
||||||
* @param string $connection
|
|
||||||
* @return \Illuminate\Database\Connection
|
|
||||||
*/
|
|
||||||
public function resolveConnection($connection)
|
|
||||||
{
|
|
||||||
return $this->resolver->connection($connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the default connection name.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setConnection($name)
|
|
||||||
{
|
|
||||||
if (! is_null($name)) {
|
|
||||||
$this->resolver->setDefaultConnection($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->repository->setSource($name);
|
|
||||||
|
|
||||||
$this->connection = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the migration repository instance.
|
* Get the migration repository instance.
|
||||||
*
|
*
|
||||||
|
@@ -29,6 +29,10 @@ class FulltextGambit implements GambitInterface
|
|||||||
throw new LogicException('This gambit can only be applied on a DiscussionSearch');
|
throw new LogicException('This gambit can only be applied on a DiscussionSearch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The @ character crashes fulltext searches on InnoDB tables.
|
||||||
|
// See https://bugs.mysql.com/bug.php?id=74042
|
||||||
|
$bit = str_replace('@', '*', $bit);
|
||||||
|
|
||||||
$search->getQuery()
|
$search->getQuery()
|
||||||
->selectRaw('SUBSTRING_INDEX(GROUP_CONCAT(posts.id ORDER BY MATCH(posts.content) AGAINST (?) DESC), \',\', 1) as most_relevant_post_id', [$bit])
|
->selectRaw('SUBSTRING_INDEX(GROUP_CONCAT(posts.id ORDER BY MATCH(posts.content) AGAINST (?) DESC), \',\', 1) as most_relevant_post_id', [$bit])
|
||||||
->leftJoin('posts', 'posts.discussion_id', '=', 'discussions.id')
|
->leftJoin('posts', 'posts.discussion_id', '=', 'discussions.id')
|
||||||
|
@@ -16,7 +16,7 @@ use Flarum\Frontend\Event\Rendering;
|
|||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Events\Dispatcher;
|
use Illuminate\Events\Dispatcher;
|
||||||
|
|
||||||
class Assets implements Extender
|
class Assets implements ExtenderInterface
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ use Illuminate\Contracts\Container\Container;
|
|||||||
*
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
class Compat implements Extender
|
class Compat implements ExtenderInterface
|
||||||
{
|
{
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ namespace Flarum\Extend;
|
|||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
interface Extender
|
interface ExtenderInterface
|
||||||
{
|
{
|
||||||
public function __invoke(Container $container, Extension $extension = null);
|
public function __invoke(Container $container, Extension $extension = null);
|
||||||
}
|
}
|
@@ -16,7 +16,7 @@ use Flarum\Formatter\Event\Configuring;
|
|||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Events\Dispatcher;
|
use Illuminate\Events\Dispatcher;
|
||||||
|
|
||||||
class FormatterConfiguration implements Extender
|
class FormatterConfiguration implements ExtenderInterface
|
||||||
{
|
{
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ use Illuminate\Contracts\Container\Container;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class LanguagePack implements Extender
|
class LanguagePack implements ExtenderInterface
|
||||||
{
|
{
|
||||||
public function __invoke(Container $container, Extension $extension = null)
|
public function __invoke(Container $container, Extension $extension = null)
|
||||||
{
|
{
|
||||||
|
@@ -16,7 +16,7 @@ use Flarum\Extension\Extension;
|
|||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class Locales implements Extender
|
class Locales implements ExtenderInterface
|
||||||
{
|
{
|
||||||
protected $directory;
|
protected $directory;
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ use Flarum\Extension\Extension;
|
|||||||
use Flarum\Http\RouteHandlerFactory;
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class Routes implements Extender
|
class Routes implements ExtenderInterface
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
@@ -21,8 +21,13 @@ class ExtensionServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->bind('flarum.extensions', ExtensionManager::class);
|
$this->app->singleton(ExtensionManager::class);
|
||||||
|
$this->app->alias(ExtensionManager::class, 'flarum.extensions');
|
||||||
|
|
||||||
|
// Boot extensions when the app is booting. This must be done as a boot
|
||||||
|
// listener on the app rather than in the service provider's boot method
|
||||||
|
// below, so that extensions have a chance to register things on the
|
||||||
|
// container before the core boot code runs.
|
||||||
$this->app->booting(function (Container $app) {
|
$this->app->booting(function (Container $app) {
|
||||||
$app->make('flarum.extensions')->extend($app);
|
$app->make('flarum.extensions')->extend($app);
|
||||||
});
|
});
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
namespace Flarum\Forum\Controller;
|
namespace Flarum\Forum\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Client;
|
use Flarum\Api\Client;
|
||||||
use Flarum\Api\Controller\TokenController;
|
use Flarum\Api\Controller\CreateTokenController;
|
||||||
use Flarum\Http\AccessToken;
|
use Flarum\Http\AccessToken;
|
||||||
use Flarum\Http\Rememberer;
|
use Flarum\Http\Rememberer;
|
||||||
use Flarum\Http\SessionAuthenticator;
|
use Flarum\Http\SessionAuthenticator;
|
||||||
@@ -67,7 +67,7 @@ class LogInController implements RequestHandlerInterface
|
|||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$params = array_only($body, ['identification', 'password']);
|
$params = array_only($body, ['identification', 'password']);
|
||||||
|
|
||||||
$response = $this->apiClient->send(TokenController::class, $actor, [], $params);
|
$response = $this->apiClient->send(CreateTokenController::class, $actor, [], $params);
|
||||||
|
|
||||||
if ($response->getStatusCode() === 200) {
|
if ($response->getStatusCode() === 200) {
|
||||||
$data = json_decode($response->getBody());
|
$data = json_decode($response->getBody());
|
||||||
|
@@ -90,6 +90,8 @@ class UserRepository
|
|||||||
*/
|
*/
|
||||||
public function getIdsForUsername($string, User $actor = null)
|
public function getIdsForUsername($string, User $actor = null)
|
||||||
{
|
{
|
||||||
|
$string = $this->escapeLikeString($string);
|
||||||
|
|
||||||
$query = User::where('username', 'like', '%'.$string.'%')
|
$query = User::where('username', 'like', '%'.$string.'%')
|
||||||
->orderByRaw('username = ? desc', [$string])
|
->orderByRaw('username = ? desc', [$string])
|
||||||
->orderByRaw('username like ? desc', [$string.'%']);
|
->orderByRaw('username like ? desc', [$string.'%']);
|
||||||
@@ -112,4 +114,15 @@ class UserRepository
|
|||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape special characters that can be used as wildcards in a LIKE query.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function escapeLikeString($string)
|
||||||
|
{
|
||||||
|
return str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], $string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,15 +11,15 @@
|
|||||||
|
|
||||||
namespace Flarum\Tests\Api\Controller;
|
namespace Flarum\Tests\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\TokenController;
|
use Flarum\Api\Controller\CreateTokenController;
|
||||||
use Flarum\Http\AccessToken;
|
use Flarum\Http\AccessToken;
|
||||||
use Flarum\Tests\Test\Concerns\RetrievesAuthorizedUsers;
|
use Flarum\Tests\Test\Concerns\RetrievesAuthorizedUsers;
|
||||||
|
|
||||||
class TokenControllerTest extends ApiControllerTestCase
|
class CreateTokenControllerTest extends ApiControllerTestCase
|
||||||
{
|
{
|
||||||
use RetrievesAuthorizedUsers;
|
use RetrievesAuthorizedUsers;
|
||||||
|
|
||||||
protected $controller = TokenController::class;
|
protected $controller = CreateTokenController::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
Reference in New Issue
Block a user