Added "use ..." statements

This version ditches backwards compatibility with PHP earlier than 5.6.
This commit is contained in:
Marcin Kurczewski 2014-10-08 14:47:47 +02:00
parent 5bc73d220e
commit 632bac8661
140 changed files with 1673 additions and 1076 deletions

View file

@ -1,7 +1,8 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Router;
abstract class AbstractController abstract class AbstractController
{ {
abstract function registerRoutes(\Szurubooru\Router $router); abstract function registerRoutes(Router $router);
} }

View file

@ -1,5 +1,14 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Controllers\ViewProxies\TokenViewProxy;
use Szurubooru\Controllers\ViewProxies\UserViewProxy;
use Szurubooru\FormData\LoginFormData;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Router;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\TokenService;
use Szurubooru\Services\UserService;
final class AuthController extends AbstractController final class AuthController extends AbstractController
{ {
@ -12,13 +21,13 @@ final class AuthController extends AbstractController
private $tokenViewProxy; private $tokenViewProxy;
public function __construct( public function __construct(
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\UserService $userService, UserService $userService,
\Szurubooru\Services\TokenService $tokenService, TokenService $tokenService,
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Helpers\InputReader $inputReader, InputReader $inputReader,
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy, UserViewProxy $userViewProxy,
\Szurubooru\Controllers\ViewProxies\TokenViewProxy $tokenViewProxy) TokenViewProxy $tokenViewProxy)
{ {
$this->authService = $authService; $this->authService = $authService;
$this->userService = $userService; $this->userService = $userService;
@ -29,7 +38,7 @@ final class AuthController extends AbstractController
$this->tokenViewProxy = $tokenViewProxy; $this->tokenViewProxy = $tokenViewProxy;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->post('/api/login', [$this, 'login']); $router->post('/api/login', [$this, 'login']);
$router->put('/api/login', [$this, 'login']); $router->put('/api/login', [$this, 'login']);
@ -39,7 +48,7 @@ final class AuthController extends AbstractController
{ {
if (isset($this->inputReader->userNameOrEmail) and isset($this->inputReader->password)) if (isset($this->inputReader->userNameOrEmail) and isset($this->inputReader->password))
{ {
$formData = new \Szurubooru\FormData\LoginFormData($this->inputReader); $formData = new LoginFormData($this->inputReader);
$this->authService->loginFromCredentials($formData); $this->authService->loginFromCredentials($formData);
$user = $this->authService->getLoggedInUser(); $user = $this->authService->getLoggedInUser();

View file

@ -1,5 +1,19 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Controllers\ViewProxies\CommentViewProxy;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Router;
use Szurubooru\SearchServices\Filters\CommentFilter;
use Szurubooru\SearchServices\Filters\PostFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementRangedValue;
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\CommentService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class CommentController extends AbstractController class CommentController extends AbstractController
{ {
@ -12,13 +26,13 @@ class CommentController extends AbstractController
private $inputReader; private $inputReader;
public function __construct( public function __construct(
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\Services\CommentService $commentService, CommentService $commentService,
\Szurubooru\Controllers\ViewProxies\CommentViewProxy $commentViewProxy, CommentViewProxy $commentViewProxy,
\Szurubooru\Controllers\ViewProxies\PostViewProxy $postViewProxy, PostViewProxy $postViewProxy,
\Szurubooru\Helpers\InputReader $inputReader) InputReader $inputReader)
{ {
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
$this->authService = $authService; $this->authService = $authService;
@ -29,7 +43,7 @@ class CommentController extends AbstractController
$this->inputReader = $inputReader; $this->inputReader = $inputReader;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/comments', [$this, 'getComments']); $router->get('/api/comments', [$this, 'getComments']);
$router->get('/api/comments/:postNameOrId', [$this, 'getPostComments']); $router->get('/api/comments/:postNameOrId', [$this, 'getPostComments']);
@ -40,19 +54,19 @@ class CommentController extends AbstractController
public function getComments() public function getComments()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_COMMENTS); $this->privilegeService->assertPrivilege(Privilege::LIST_COMMENTS);
$filter = new \Szurubooru\SearchServices\Filters\PostFilter(); $filter = new PostFilter();
$filter->setPageSize(10); $filter->setPageSize(10);
$filter->setPageNumber($this->inputReader->page); $filter->setPageNumber($this->inputReader->page);
$filter->setOrder([ $filter->setOrder([
\Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME => PostFilter::ORDER_LAST_COMMENT_TIME =>
\Szurubooru\SearchServices\Filters\PostFilter::ORDER_DESC]); PostFilter::ORDER_DESC]);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementRangedValue()); $requirement->setValue(new RequirementRangedValue());
$requirement->getValue()->setMinValue(1); $requirement->getValue()->setMinValue(1);
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT); $requirement->setType(PostFilter::REQUIREMENT_COMMENT_COUNT);
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
$result = $this->postService->getFiltered($filter); $result = $this->postService->getFiltered($filter);
@ -77,17 +91,17 @@ class CommentController extends AbstractController
public function getPostComments($postNameOrId) public function getPostComments($postNameOrId)
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_COMMENTS); $this->privilegeService->assertPrivilege(Privilege::LIST_COMMENTS);
$post = $this->postService->getByNameOrId($postNameOrId); $post = $this->postService->getByNameOrId($postNameOrId);
$filter = new \Szurubooru\SearchServices\Filters\CommentFilter(); $filter = new CommentFilter();
$filter->setOrder([ $filter->setOrder([
\Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ID => CommentFilter::ORDER_ID =>
\Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ASC]); CommentFilter::ORDER_ASC]);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); $requirement->setValue(new RequirementSingleValue($post->getId()));
$requirement->setType(\Szurubooru\SearchServices\Filters\CommentFilter::REQUIREMENT_POST_ID); $requirement->setType(CommentFilter::REQUIREMENT_POST_ID);
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
$result = $this->commentService->getFiltered($filter); $result = $this->commentService->getFiltered($filter);
@ -97,7 +111,7 @@ class CommentController extends AbstractController
public function addComment($postNameOrId) public function addComment($postNameOrId)
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::ADD_COMMENTS); $this->privilegeService->assertPrivilege(Privilege::ADD_COMMENTS);
$post = $this->postService->getByNameOrId($postNameOrId); $post = $this->postService->getByNameOrId($postNameOrId);
$comment = $this->commentService->createComment($post, $this->inputReader->text); $comment = $this->commentService->createComment($post, $this->inputReader->text);
@ -110,8 +124,8 @@ class CommentController extends AbstractController
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
($comment->getUser() and $this->privilegeService->isLoggedIn($comment->getUser())) ($comment->getUser() and $this->privilegeService->isLoggedIn($comment->getUser()))
? \Szurubooru\Privilege::EDIT_OWN_COMMENTS ? Privilege::EDIT_OWN_COMMENTS
: \Szurubooru\Privilege::EDIT_ALL_COMMENTS); : Privilege::EDIT_ALL_COMMENTS);
$comment = $this->commentService->updateComment($comment, $this->inputReader->text); $comment = $this->commentService->updateComment($comment, $this->inputReader->text);
return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig()); return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig());
@ -123,8 +137,8 @@ class CommentController extends AbstractController
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($comment->getUser()) $this->privilegeService->isLoggedIn($comment->getUser())
? \Szurubooru\Privilege::DELETE_OWN_COMMENTS ? Privilege::DELETE_OWN_COMMENTS
: \Szurubooru\Privilege::DELETE_ALL_COMMENTS); : Privilege::DELETE_ALL_COMMENTS);
return $this->commentService->deleteComment($comment); return $this->commentService->deleteComment($comment);
} }
@ -133,7 +147,7 @@ class CommentController extends AbstractController
{ {
return return
[ [
\Szurubooru\Controllers\ViewProxies\CommentViewProxy::FETCH_OWN_SCORE => true, CommentViewProxy::FETCH_OWN_SCORE => true,
]; ];
} }
} }

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Controllers\ViewProxies\UserViewProxy;
use Szurubooru\Router;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\FavoritesService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class FavoritesController extends AbstractController class FavoritesController extends AbstractController
{ {
@ -10,11 +16,11 @@ class FavoritesController extends AbstractController
private $userViewProxy; private $userViewProxy;
public function __construct( public function __construct(
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\Services\FavoritesService $favoritesService, FavoritesService $favoritesService,
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy) UserViewProxy $userViewProxy)
{ {
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
$this->authService = $authService; $this->authService = $authService;
@ -23,7 +29,7 @@ class FavoritesController extends AbstractController
$this->userViewProxy = $userViewProxy; $this->userViewProxy = $userViewProxy;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/posts/:postNameOrId/favorites', [$this, 'getFavoriteUsers']); $router->get('/api/posts/:postNameOrId/favorites', [$this, 'getFavoriteUsers']);
$router->post('/api/posts/:postNameOrId/favorites', [$this, 'addFavorite']); $router->post('/api/posts/:postNameOrId/favorites', [$this, 'addFavorite']);

View file

@ -1,17 +1,18 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Dao\GlobalParamDao;
use Szurubooru\Router;
final class GlobalParamController extends AbstractController final class GlobalParamController extends AbstractController
{ {
private $globalParamDao; private $globalParamDao;
public function __construct( public function __construct(GlobalParamDao $globalParamDao)
\Szurubooru\Dao\GlobalParamDao $globalParamDao)
{ {
$this->globalParamDao = $globalParamDao; $this->globalParamDao = $globalParamDao;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/globals', [$this, 'getGlobals']); $router->get('/api/globals', [$this, 'getGlobals']);
} }

View file

@ -1,5 +1,12 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Controllers\ViewProxies\SnapshotViewProxy;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Router;
use Szurubooru\SearchServices\Parsers\SnapshotSearchParser;
use Szurubooru\Services\HistoryService;
use Szurubooru\Services\PrivilegeService;
final class HistoryController extends AbstractController final class HistoryController extends AbstractController
{ {
@ -10,11 +17,11 @@ final class HistoryController extends AbstractController
private $snapshotViewProxy; private $snapshotViewProxy;
public function __construct( public function __construct(
\Szurubooru\Services\HistoryService $historyService, HistoryService $historyService,
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\SearchServices\Parsers\SnapshotSearchParser $snapshotSearchParser, SnapshotSearchParser $snapshotSearchParser,
\Szurubooru\Helpers\InputReader $inputReader, InputReader $inputReader,
\Szurubooru\Controllers\ViewProxies\SnapshotViewProxy $snapshotViewProxy) SnapshotViewProxy $snapshotViewProxy)
{ {
$this->historyService = $historyService; $this->historyService = $historyService;
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
@ -23,14 +30,14 @@ final class HistoryController extends AbstractController
$this->snapshotViewProxy = $snapshotViewProxy; $this->snapshotViewProxy = $snapshotViewProxy;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/history', [$this, 'getFiltered']); $router->get('/api/history', [$this, 'getFiltered']);
} }
public function getFiltered() public function getFiltered()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY); $this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY);
$filter = $this->snapshotSearchParser->createFilterFromInputReader($this->inputReader); $filter = $this->snapshotSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize(50); $filter->setPageSize(50);

View file

@ -1,5 +1,10 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Helpers\HttpHelper;
use Szurubooru\Router;
use Szurubooru\Services\FileService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\ThumbnailService;
final class PostContentController extends AbstractController final class PostContentController extends AbstractController
{ {
@ -9,10 +14,10 @@ final class PostContentController extends AbstractController
private $thumbnailService; private $thumbnailService;
public function __construct( public function __construct(
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Helpers\HttpHelper $httpHelper, HttpHelper $httpHelper,
\Szurubooru\Services\ThumbnailService $thumbnailService) ThumbnailService $thumbnailService)
{ {
$this->postService = $postService; $this->postService = $postService;
$this->fileService = $fileService; $this->fileService = $fileService;
@ -20,7 +25,7 @@ final class PostContentController extends AbstractController
$this->thumbnailService = $thumbnailService; $this->thumbnailService = $thumbnailService;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/posts/:postName/content', [$this, 'getPostContent']); $router->get('/api/posts/:postName/content', [$this, 'getPostContent']);
$router->get('/api/posts/:postName/thumbnail/:size', [$this, 'getPostThumbnail']); $router->get('/api/posts/:postName/thumbnail/:size', [$this, 'getPostThumbnail']);

View file

@ -1,5 +1,22 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Config;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\Controllers\ViewProxies\SnapshotViewProxy;
use Szurubooru\Entities\Post;
use Szurubooru\FormData\PostEditFormData;
use Szurubooru\FormData\UploadFormData;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Helpers\TypeHelper;
use Szurubooru\Privilege;
use Szurubooru\Router;
use Szurubooru\SearchServices\Filters\PostFilter;
use Szurubooru\SearchServices\Parsers\PostSearchParser;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
final class PostController extends AbstractController final class PostController extends AbstractController
{ {
@ -13,14 +30,14 @@ final class PostController extends AbstractController
private $snapshotViewProxy; private $snapshotViewProxy;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\SearchServices\Parsers\PostSearchParser $postSearchParser, PostSearchParser $postSearchParser,
\Szurubooru\Helpers\InputReader $inputReader, InputReader $inputReader,
\Szurubooru\Controllers\ViewProxies\PostViewProxy $postViewProxy, PostViewProxy $postViewProxy,
\Szurubooru\Controllers\ViewProxies\SnapshotViewProxy $snapshotViewProxy) SnapshotViewProxy $snapshotViewProxy)
{ {
$this->config = $config; $this->config = $config;
$this->authService = $authService; $this->authService = $authService;
@ -32,7 +49,7 @@ final class PostController extends AbstractController
$this->snapshotViewProxy = $snapshotViewProxy; $this->snapshotViewProxy = $snapshotViewProxy;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->post('/api/posts', [$this, 'createPost']); $router->post('/api/posts', [$this, 'createPost']);
$router->get('/api/posts', [$this, 'getFiltered']); $router->get('/api/posts', [$this, 'getFiltered']);
@ -47,7 +64,7 @@ final class PostController extends AbstractController
public function getByNameOrId($postNameOrId) public function getByNameOrId($postNameOrId)
{ {
if ($postNameOrId !== 'featured') if ($postNameOrId !== 'featured')
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_POSTS); $this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS);
$post = $this->getByNameOrIdWithoutProxy($postNameOrId); $post = $this->getByNameOrIdWithoutProxy($postNameOrId);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
@ -55,14 +72,14 @@ final class PostController extends AbstractController
public function getHistory($postNameOrId) public function getHistory($postNameOrId)
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY); $this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY);
$post = $this->getByNameOrIdWithoutProxy($postNameOrId); $post = $this->getByNameOrIdWithoutProxy($postNameOrId);
return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))]; return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))];
} }
public function getFiltered() public function getFiltered()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_POSTS); $this->privilegeService->assertPrivilege(Privilege::LIST_POSTS);
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader); $filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize($this->config->posts->postsPerPage); $filter->setPageSize($this->config->posts->postsPerPage);
@ -78,13 +95,13 @@ final class PostController extends AbstractController
public function createPost() public function createPost()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS); $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS);
$formData = new \Szurubooru\FormData\UploadFormData($this->inputReader); $formData = new UploadFormData($this->inputReader);
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS); $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS);
if ($formData->anonymous) if ($formData->anonymous)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS_ANONYMOUSLY); $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS_ANONYMOUSLY);
$post = $this->postService->createPost($formData); $post = $this->postService->createPost($formData);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
@ -93,22 +110,22 @@ final class PostController extends AbstractController
public function updatePost($postNameOrId) public function updatePost($postNameOrId)
{ {
$post = $this->postService->getByNameOrId($postNameOrId); $post = $this->postService->getByNameOrId($postNameOrId);
$formData = new \Szurubooru\FormData\PostEditFormData($this->inputReader); $formData = new PostEditFormData($this->inputReader);
if ($formData->content !== null) if ($formData->content !== null)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_CONTENT); $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_CONTENT);
if ($formData->thumbnail !== null) if ($formData->thumbnail !== null)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_THUMBNAIL); $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_THUMBNAIL);
if ($formData->safety !== null) if ($formData->safety !== null)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SAFETY); $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SAFETY);
if ($formData->source !== null) if ($formData->source !== null)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SOURCE); $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SOURCE);
if ($formData->tags !== null) if ($formData->tags !== null)
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_TAGS); $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_TAGS);
$this->postService->updatePost($post, $formData); $this->postService->updatePost($post, $formData);
$post = $this->postService->getByNameOrId($postNameOrId); $post = $this->postService->getByNameOrId($postNameOrId);
@ -139,12 +156,12 @@ final class PostController extends AbstractController
{ {
return return
[ [
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_RELATIONS => true, PostViewProxy::FETCH_RELATIONS => true,
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true, PostViewProxy::FETCH_TAGS => true,
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_USER => true, PostViewProxy::FETCH_USER => true,
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_HISTORY => true, PostViewProxy::FETCH_HISTORY => true,
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_OWN_SCORE => true, PostViewProxy::FETCH_OWN_SCORE => true,
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_FAVORITES => true, PostViewProxy::FETCH_FAVORITES => true,
]; ];
} }
@ -152,7 +169,7 @@ final class PostController extends AbstractController
{ {
return return
[ [
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true, PostViewProxy::FETCH_TAGS => true,
]; ];
} }
@ -163,33 +180,33 @@ final class PostController extends AbstractController
if (!$userSettings) if (!$userSettings)
return; return;
if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY))) if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY)))
{ {
$values = []; $values = [];
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->safe)) if (!TypeHelper::toBool($userSettings->listPosts->safe))
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; $values[] = Post::POST_SAFETY_SAFE;
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->sketchy)) if (!TypeHelper::toBool($userSettings->listPosts->sketchy))
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY; $values[] = Post::POST_SAFETY_SKETCHY;
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->unsafe)) if (!TypeHelper::toBool($userSettings->listPosts->unsafe))
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE; $values[] = Post::POST_SAFETY_UNSAFE;
if (count($values)) if (count($values))
{ {
$requirementValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); $requirementValue = new RequirementCompositeValue();
$requirementValue->setValues($values); $requirementValue->setValues($values);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY); $requirement->setType(PostFilter::REQUIREMENT_SAFETY);
$requirement->setValue($requirementValue); $requirement->setValue($requirementValue);
$requirement->setNegated(true); $requirement->setNegated(true);
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
} }
} }
if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE))) if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE)))
{ {
$requirementValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); $requirementValue = new RequirementCompositeValue();
$requirementValue->setValues([$currentUser->getName(), -1]); $requirementValue->setValues([$currentUser->getName(), -1]);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE); $requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
$requirement->setValue($requirementValue); $requirement->setValue($requirementValue);
$requirement->setNegated(true); $requirement->setNegated(true);
$filter->addRequirement($requirement); $filter->addRequirement($requirement);

View file

@ -1,7 +1,15 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Entities\Entity;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Router;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\CommentService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\ScoreService;
class ScoreController extends AbstractController final class ScoreController extends AbstractController
{ {
private $privilegeService; private $privilegeService;
private $authService; private $authService;
@ -11,12 +19,12 @@ class ScoreController extends AbstractController
private $inputReader; private $inputReader;
public function __construct( public function __construct(
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\Services\CommentService $commentService, CommentService $commentService,
\Szurubooru\Services\ScoreService $scoreService, ScoreService $scoreService,
\Szurubooru\Helpers\InputReader $inputReader) InputReader $inputReader)
{ {
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
$this->authService = $authService; $this->authService = $authService;
@ -26,7 +34,7 @@ class ScoreController extends AbstractController
$this->inputReader = $inputReader; $this->inputReader = $inputReader;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/posts/:postNameOrId/score', [$this, 'getPostScore']); $router->get('/api/posts/:postNameOrId/score', [$this, 'getPostScore']);
$router->post('/api/posts/:postNameOrId/score', [$this, 'setPostScore']); $router->post('/api/posts/:postNameOrId/score', [$this, 'setPostScore']);
@ -58,7 +66,7 @@ class ScoreController extends AbstractController
return $this->setScore($comment); return $this->setScore($comment);
} }
private function setScore(\Szurubooru\Entities\Entity $entity) private function setScore(Entity $entity)
{ {
$this->privilegeService->assertLoggedIn(); $this->privilegeService->assertLoggedIn();
$score = intval($this->inputReader->score); $score = intval($this->inputReader->score);
@ -67,7 +75,7 @@ class ScoreController extends AbstractController
return ['score' => $result->getScore()]; return ['score' => $result->getScore()];
} }
private function getScore(\Szurubooru\Entities\Entity $entity) private function getScore(Entity $entity)
{ {
$this->privilegeService->assertLoggedIn(); $this->privilegeService->assertLoggedIn();
$user = $this->authService->getLoggedInUser(); $user = $this->authService->getLoggedInUser();

View file

@ -1,5 +1,12 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Controllers\ViewProxies\TagViewProxy;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Router;
use Szurubooru\SearchServices\Parsers\TagSearchParser;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\TagService;
final class TagController extends AbstractController final class TagController extends AbstractController
{ {
@ -10,11 +17,11 @@ final class TagController extends AbstractController
private $inputReader; private $inputReader;
public function __construct( public function __construct(
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\TagService $tagService, TagService $tagService,
\Szurubooru\Controllers\ViewProxies\TagViewProxy $tagViewProxy, TagViewProxy $tagViewProxy,
\Szurubooru\SearchServices\Parsers\TagSearchParser $tagSearchParser, TagSearchParser $tagSearchParser,
\Szurubooru\Helpers\InputReader $inputReader) InputReader $inputReader)
{ {
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
$this->tagService = $tagService; $this->tagService = $tagService;
@ -23,14 +30,14 @@ final class TagController extends AbstractController
$this->inputReader = $inputReader; $this->inputReader = $inputReader;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/tags', [$this, 'getTags']); $router->get('/api/tags', [$this, 'getTags']);
} }
public function getTags() public function getTags()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_TAGS); $this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
$filter = $this->tagSearchParser->createFilterFromInputReader($this->inputReader); $filter = $this->tagSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize(50); $filter->setPageSize(50);

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Entities\User;
use Szurubooru\Helpers\HttpHelper;
use Szurubooru\Router;
use Szurubooru\Services\FileService;
use Szurubooru\Services\ThumbnailService;
use Szurubooru\Services\UserService;
final class UserAvatarController extends AbstractController final class UserAvatarController extends AbstractController
{ {
@ -9,10 +15,10 @@ final class UserAvatarController extends AbstractController
private $thumbnailService; private $thumbnailService;
public function __construct( public function __construct(
\Szurubooru\Services\UserService $userService, UserService $userService,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Helpers\HttpHelper $httpHelper, HttpHelper $httpHelper,
\Szurubooru\Services\ThumbnailService $thumbnailService) ThumbnailService $thumbnailService)
{ {
$this->userService = $userService; $this->userService = $userService;
$this->fileService = $fileService; $this->fileService = $fileService;
@ -20,7 +26,7 @@ final class UserAvatarController extends AbstractController
$this->thumbnailService = $thumbnailService; $this->thumbnailService = $thumbnailService;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->get('/api/users/:userName/avatar/:size', [$this, 'getAvatarByName']); $router->get('/api/users/:userName/avatar/:size', [$this, 'getAvatarByName']);
} }
@ -38,17 +44,17 @@ final class UserAvatarController extends AbstractController
switch ($user->getAvatarStyle()) switch ($user->getAvatarStyle())
{ {
case \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR: case User::AVATAR_STYLE_GRAVATAR:
$hash = md5(strtolower(trim($user->getEmail() ? $user->getEmail() : $user->getId() . $user->getName()))); $hash = md5(strtolower(trim($user->getEmail() ? $user->getEmail() : $user->getId() . $user->getName())));
$url = 'https://www.gravatar.com/avatar/' . $hash . '?d=retro&s=' . $size; $url = 'https://www.gravatar.com/avatar/' . $hash . '?d=retro&s=' . $size;
$this->serveFromUrl($url); $this->serveFromUrl($url);
break; break;
case \Szurubooru\Entities\User::AVATAR_STYLE_BLANK: case User::AVATAR_STYLE_BLANK:
$this->serveBlankFile($size); $this->serveBlankFile($size);
break; break;
case \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL: case User::AVATAR_STYLE_MANUAL:
$this->serveFromFile($user->getCustomAvatarSourceContentPath(), $size); $this->serveFromFile($user->getCustomAvatarSourceContentPath(), $size);
break; break;

View file

@ -1,5 +1,16 @@
<?php <?php
namespace Szurubooru\Controllers; namespace Szurubooru\Controllers;
use Szurubooru\Config;
use Szurubooru\Controllers\ViewProxies\UserViewProxy;
use Szurubooru\FormData\RegistrationFormData;
use Szurubooru\FormData\UserEditFormData;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Router;
use Szurubooru\SearchServices\Parsers\UserSearchParser;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\TokenService;
use Szurubooru\Services\UserService;
final class UserController extends AbstractController final class UserController extends AbstractController
{ {
@ -12,13 +23,13 @@ final class UserController extends AbstractController
private $userViewProxy; private $userViewProxy;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\UserService $userService, UserService $userService,
\Szurubooru\Services\TokenService $tokenService, TokenService $tokenService,
\Szurubooru\SearchServices\Parsers\UserSearchParser $userSearchParser, UserSearchParser $userSearchParser,
\Szurubooru\Helpers\InputReader $inputReader, InputReader $inputReader,
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy) UserViewProxy $userViewProxy)
{ {
$this->config = $config; $this->config = $config;
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
@ -29,7 +40,7 @@ final class UserController extends AbstractController
$this->userViewProxy = $userViewProxy; $this->userViewProxy = $userViewProxy;
} }
public function registerRoutes(\Szurubooru\Router $router) public function registerRoutes(Router $router)
{ {
$router->post('/api/users', [$this, 'createUser']); $router->post('/api/users', [$this, 'createUser']);
$router->get('/api/users', [$this, 'getFiltered']); $router->get('/api/users', [$this, 'getFiltered']);
@ -44,14 +55,14 @@ final class UserController extends AbstractController
public function getByNameOrEmail($userNameOrEmail) public function getByNameOrEmail($userNameOrEmail)
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_USERS); $this->privilegeService->assertPrivilege(Privilege::VIEW_USERS);
$user = $this->userService->getByNameOrEmail($userNameOrEmail); $user = $this->userService->getByNameOrEmail($userNameOrEmail);
return $this->userViewProxy->fromEntity($user); return $this->userViewProxy->fromEntity($user);
} }
public function getFiltered() public function getFiltered()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_USERS); $this->privilegeService->assertPrivilege(Privilege::LIST_USERS);
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader); $filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize($this->config->users->usersPerPage); $filter->setPageSize($this->config->users->usersPerPage);
@ -65,8 +76,8 @@ final class UserController extends AbstractController
public function createUser() public function createUser()
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::REGISTER); $this->privilegeService->assertPrivilege(Privilege::REGISTER);
$formData = new \Szurubooru\FormData\RegistrationFormData($this->inputReader); $formData = new RegistrationFormData($this->inputReader);
$user = $this->userService->createUser($formData); $user = $this->userService->createUser($formData);
return $this->userViewProxy->fromEntity($user); return $this->userViewProxy->fromEntity($user);
} }
@ -74,43 +85,43 @@ final class UserController extends AbstractController
public function updateUser($userNameOrEmail) public function updateUser($userNameOrEmail)
{ {
$user = $this->userService->getByNameOrEmail($userNameOrEmail); $user = $this->userService->getByNameOrEmail($userNameOrEmail);
$formData = new \Szurubooru\FormData\UserEditFormData($this->inputReader); $formData = new UserEditFormData($this->inputReader);
if ($formData->avatarStyle !== null || $formData->avatarContent !== null) if ($formData->avatarStyle !== null || $formData->avatarContent !== null)
{ {
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($userNameOrEmail) $this->privilegeService->isLoggedIn($userNameOrEmail)
? \Szurubooru\Privilege::CHANGE_OWN_AVATAR_STYLE ? Privilege::CHANGE_OWN_AVATAR_STYLE
: \Szurubooru\Privilege::CHANGE_ALL_AVATAR_STYLES); : Privilege::CHANGE_ALL_AVATAR_STYLES);
} }
if ($formData->userName !== null) if ($formData->userName !== null)
{ {
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($userNameOrEmail) $this->privilegeService->isLoggedIn($userNameOrEmail)
? \Szurubooru\Privilege::CHANGE_OWN_NAME ? Privilege::CHANGE_OWN_NAME
: \Szurubooru\Privilege::CHANGE_ALL_NAMES); : Privilege::CHANGE_ALL_NAMES);
} }
if ($formData->password !== null) if ($formData->password !== null)
{ {
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($userNameOrEmail) $this->privilegeService->isLoggedIn($userNameOrEmail)
? \Szurubooru\Privilege::CHANGE_OWN_PASSWORD ? Privilege::CHANGE_OWN_PASSWORD
: \Szurubooru\Privilege::CHANGE_ALL_PASSWORDS); : Privilege::CHANGE_ALL_PASSWORDS);
} }
if ($formData->email !== null) if ($formData->email !== null)
{ {
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($userNameOrEmail) $this->privilegeService->isLoggedIn($userNameOrEmail)
? \Szurubooru\Privilege::CHANGE_OWN_EMAIL_ADDRESS ? Privilege::CHANGE_OWN_EMAIL_ADDRESS
: \Szurubooru\Privilege::CHANGE_ALL_EMAIL_ADDRESSES); : Privilege::CHANGE_ALL_EMAIL_ADDRESSES);
} }
if ($formData->accessRank) if ($formData->accessRank)
{ {
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_ACCESS_RANK); $this->privilegeService->assertPrivilege(Privilege::CHANGE_ACCESS_RANK);
} }
if ($formData->browsingSettings) if ($formData->browsingSettings)
@ -126,8 +137,8 @@ final class UserController extends AbstractController
{ {
$this->privilegeService->assertPrivilege( $this->privilegeService->assertPrivilege(
$this->privilegeService->isLoggedIn($userNameOrEmail) $this->privilegeService->isLoggedIn($userNameOrEmail)
? \Szurubooru\Privilege::DELETE_OWN_ACCOUNT ? Privilege::DELETE_OWN_ACCOUNT
: \Szurubooru\Privilege::DELETE_ACCOUNTS); : Privilege::DELETE_ACCOUNTS);
$user = $this->userService->getByNameOrEmail($userNameOrEmail); $user = $this->userService->getByNameOrEmail($userNameOrEmail);
return $this->userService->deleteUser($user); return $this->userService->deleteUser($user);

View file

@ -1,5 +1,7 @@
<?php <?php
namespace Szurubooru\Controllers\ViewProxies; namespace Szurubooru\Controllers\ViewProxies;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\ScoreService;
class CommentViewProxy extends AbstractViewProxy class CommentViewProxy extends AbstractViewProxy
{ {
@ -10,8 +12,8 @@ class CommentViewProxy extends AbstractViewProxy
const FETCH_OWN_SCORE = 'fetchOwnScore'; const FETCH_OWN_SCORE = 'fetchOwnScore';
public function __construct( public function __construct(
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\ScoreService $scoreService, ScoreService $scoreService,
UserViewProxy $userViewProxy) UserViewProxy $userViewProxy)
{ {
$this->authService = $authService; $this->authService = $authService;

View file

@ -1,5 +1,13 @@
<?php <?php
namespace Szurubooru\Controllers\ViewProxies; namespace Szurubooru\Controllers\ViewProxies;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\Privilege;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\FavoritesService;
use Szurubooru\Services\HistoryService;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\ScoreService;
class PostViewProxy extends AbstractViewProxy class PostViewProxy extends AbstractViewProxy
{ {
@ -20,11 +28,11 @@ class PostViewProxy extends AbstractViewProxy
private $snapshotViewProxy; private $snapshotViewProxy;
public function __construct( public function __construct(
\Szurubooru\Services\PrivilegeService $privilegeService, PrivilegeService $privilegeService,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\HistoryService $historyService, HistoryService $historyService,
\Szurubooru\Services\FavoritesService $favoritesService, FavoritesService $favoritesService,
\Szurubooru\Services\ScoreService $scoreService, ScoreService $scoreService,
TagViewProxy $tagViewProxy, TagViewProxy $tagViewProxy,
UserViewProxy $userViewProxy, UserViewProxy $userViewProxy,
SnapshotViewProxy $snapshotViewProxy) SnapshotViewProxy $snapshotViewProxy)
@ -50,11 +58,11 @@ class PostViewProxy extends AbstractViewProxy
$result->name = $post->getName(); $result->name = $post->getName();
$result->uploadTime = $post->getUploadTime(); $result->uploadTime = $post->getUploadTime();
$result->lastEditTime = $post->getLastEditTime(); $result->lastEditTime = $post->getLastEditTime();
$result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()); $result->safety = EnumHelper::postSafetyToString($post->getSafety());
$result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType()); $result->contentType = EnumHelper::postTypeToString($post->getContentType());
$result->contentChecksum = $post->getContentChecksum(); $result->contentChecksum = $post->getContentChecksum();
$result->contentMimeType = $post->getContentMimeType(); $result->contentMimeType = $post->getContentMimeType();
$result->contentExtension = \Szurubooru\Helpers\MimeHelper::getExtension($post->getContentMimeType()); $result->contentExtension = MimeHelper::getExtension($post->getContentMimeType());
$result->source = $post->getSource(); $result->source = $post->getSource();
$result->imageWidth = $post->getImageWidth(); $result->imageWidth = $post->getImageWidth();
$result->imageHeight = $post->getImageHeight(); $result->imageHeight = $post->getImageHeight();
@ -76,7 +84,7 @@ class PostViewProxy extends AbstractViewProxy
if (!empty($config[self::FETCH_HISTORY])) if (!empty($config[self::FETCH_HISTORY]))
{ {
if ($this->privilegeService->hasPrivilege(\Szurubooru\Privilege::VIEW_HISTORY)) if ($this->privilegeService->hasPrivilege(Privilege::VIEW_HISTORY))
$result->history = $this->snapshotViewProxy->fromArray($this->historyService->getPostHistory($post)); $result->history = $this->snapshotViewProxy->fromArray($this->historyService->getPostHistory($post));
else else
$result->history = []; $result->history = [];

View file

@ -1,11 +1,14 @@
<?php <?php
namespace Szurubooru\Controllers\ViewProxies; namespace Szurubooru\Controllers\ViewProxies;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\Privilege;
use Szurubooru\Services\PrivilegeService;
class UserViewProxy extends AbstractViewProxy class UserViewProxy extends AbstractViewProxy
{ {
private $privilegeService; private $privilegeService;
public function __construct(\Szurubooru\Services\PrivilegeService $privilegeService) public function __construct(PrivilegeService $privilegeService)
{ {
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
} }
@ -17,10 +20,10 @@ class UserViewProxy extends AbstractViewProxy
{ {
$result->id = $user->getId(); $result->id = $user->getId();
$result->name = $user->getName(); $result->name = $user->getName();
$result->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankToString($user->getAccessRank()); $result->accessRank = EnumHelper::accessRankToString($user->getAccessRank());
$result->registrationTime = $user->getRegistrationTime(); $result->registrationTime = $user->getRegistrationTime();
$result->lastLoginTime = $user->getLastLoginTime(); $result->lastLoginTime = $user->getLastLoginTime();
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle()); $result->avatarStyle = EnumHelper::avatarStyleToString($user->getAvatarStyle());
$result->banned = $user->isBanned(); $result->banned = $user->isBanned();
if ($this->privilegeService->isLoggedIn($user)) if ($this->privilegeService->isLoggedIn($user))
@ -28,7 +31,7 @@ class UserViewProxy extends AbstractViewProxy
$result->browsingSettings = $user->getBrowsingSettings(); $result->browsingSettings = $user->getBrowsingSettings();
} }
if ($this->privilegeService->hasPrivilege(\Szurubooru\Privilege::VIEW_ALL_EMAIL_ADDRESSES) or if ($this->privilegeService->hasPrivilege(Privilege::VIEW_ALL_EMAIL_ADDRESSES) or
$this->privilegeService->isLoggedIn($user)) $this->privilegeService->isLoggedIn($user))
{ {
$result->email = $user->getEmail(); $result->email = $user->getEmail();

View file

@ -1,5 +1,14 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\IEntityConverter;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Entity;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
use Szurubooru\SearchServices\Requirements\RequirementRangedValue;
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
use Szurubooru\SearchServices\Result;
abstract class AbstractDao implements ICrudDao abstract class AbstractDao implements ICrudDao
{ {
@ -10,9 +19,9 @@ abstract class AbstractDao implements ICrudDao
protected $driver; protected $driver;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
$tableName, $tableName,
\Szurubooru\Dao\EntityConverters\IEntityConverter $entityConverter) IEntityConverter $entityConverter)
{ {
$this->setDatabaseConnection($databaseConnection); $this->setDatabaseConnection($databaseConnection);
$this->tableName = $tableName; $this->tableName = $tableName;
@ -70,7 +79,7 @@ abstract class AbstractDao implements ICrudDao
return $this->findBy($this->getIdColumn(), $entityIds); return $this->findBy($this->getIdColumn(), $entityIds);
} }
public function findFiltered(\Szurubooru\SearchServices\Filters\IFilter $searchFilter) public function findFiltered(IFilter $searchFilter)
{ {
$query = $this->fpdo->from($this->tableName)->disableSmartJoin(); $query = $this->fpdo->from($this->tableName)->disableSmartJoin();
@ -90,7 +99,7 @@ abstract class AbstractDao implements ICrudDao
$this->decorateQueryFromFilter($query, $searchFilter); $this->decorateQueryFromFilter($query, $searchFilter);
$totalRecords = count($query); $totalRecords = count($query);
$searchResult = new \Szurubooru\SearchServices\Result(); $searchResult = new Result();
$searchResult->setSearchFilter($searchFilter); $searchResult->setSearchFilter($searchFilter);
$searchResult->setEntities($entities); $searchResult->setEntities($entities);
$searchResult->setTotalRecords($totalRecords); $searchResult->setTotalRecords($totalRecords);
@ -113,14 +122,14 @@ abstract class AbstractDao implements ICrudDao
return $this->deleteBy($this->getIdColumn(), $entityId); return $this->deleteBy($this->getIdColumn(), $entityId);
} }
protected function update(\Szurubooru\Entities\Entity $entity) protected function update(Entity $entity)
{ {
$arrayEntity = $this->entityConverter->toArray($entity); $arrayEntity = $this->entityConverter->toArray($entity);
$this->fpdo->update($this->tableName)->set($arrayEntity)->where($this->getIdColumn(), $entity->getId())->execute(); $this->fpdo->update($this->tableName)->set($arrayEntity)->where($this->getIdColumn(), $entity->getId())->execute();
return $entity; return $entity;
} }
protected function create(\Szurubooru\Entities\Entity $entity) protected function create(Entity $entity)
{ {
$arrayEntity = $this->entityConverter->toArray($entity); $arrayEntity = $this->entityConverter->toArray($entity);
$this->fpdo->insertInto($this->tableName)->values($arrayEntity)->execute(); $this->fpdo->insertInto($this->tableName)->values($arrayEntity)->execute();
@ -164,11 +173,11 @@ abstract class AbstractDao implements ICrudDao
$this->fpdo->deleteFrom($this->tableName)->where($columnName, $value)->execute(); $this->fpdo->deleteFrom($this->tableName)->where($columnName, $value)->execute();
} }
protected function afterLoad(\Szurubooru\Entities\Entity $entity) protected function afterLoad(Entity $entity)
{ {
} }
protected function afterSave(\Szurubooru\Entities\Entity $entity) protected function afterSave(Entity $entity)
{ {
} }
@ -176,16 +185,16 @@ abstract class AbstractDao implements ICrudDao
{ {
} }
protected function beforeDelete(\Szurubooru\Entities\Entity $entity) protected function beforeDelete(Entity $entity)
{ {
} }
protected function decorateQueryFromRequirement($query, \Szurubooru\SearchServices\Requirements\Requirement $requirement) protected function decorateQueryFromRequirement($query, Requirement $requirement)
{ {
$value = $requirement->getValue(); $value = $requirement->getValue();
$sqlColumn = $requirement->getType(); $sqlColumn = $requirement->getType();
if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementCompositeValue) if ($value instanceof RequirementCompositeValue)
{ {
$sql = $sqlColumn; $sql = $sqlColumn;
$bindings = [$value->getValues()]; $bindings = [$value->getValues()];
@ -194,7 +203,7 @@ abstract class AbstractDao implements ICrudDao
$sql = 'NOT ' . $sql; $sql = 'NOT ' . $sql;
} }
else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementRangedValue) else if ($value instanceof RequirementRangedValue)
{ {
if ($value->getMinValue() and $value->getMaxValue()) if ($value->getMinValue() and $value->getMaxValue())
{ {
@ -218,7 +227,7 @@ abstract class AbstractDao implements ICrudDao
$sql = 'NOT (' . $sql . ')'; $sql = 'NOT (' . $sql . ')';
} }
else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementSingleValue) else if ($value instanceof RequirementSingleValue)
{ {
$sql = $sqlColumn; $sql = $sqlColumn;
$bindings = [$value->getValue()]; $bindings = [$value->getValue()];
@ -230,7 +239,7 @@ abstract class AbstractDao implements ICrudDao
else else
throw new \Exception('Bad value: ' . get_class($value)); throw new \Exception('Bad value: ' . get_class($value));
call_user_func_array([$query, 'where'], array_merge([$sql], $bindings)); $query->where($sql, ...$bindings);
} }
protected function arrayToEntities(array $arrayEntities) protected function arrayToEntities(array $arrayEntities)
@ -244,14 +253,14 @@ abstract class AbstractDao implements ICrudDao
return $entities; return $entities;
} }
private function setDatabaseConnection(\Szurubooru\DatabaseConnection $databaseConnection) private function setDatabaseConnection(DatabaseConnection $databaseConnection)
{ {
$this->pdo = $databaseConnection->getPDO(); $this->pdo = $databaseConnection->getPDO();
$this->fpdo = new \FluentPDO($this->pdo); $this->fpdo = new \FluentPDO($this->pdo);
$this->driver = $databaseConnection->getDriver(); $this->driver = $databaseConnection->getDriver();
} }
private function decorateQueryFromFilter($query, \Szurubooru\SearchServices\Filters\IFilter $filter) private function decorateQueryFromFilter($query, IFilter $filter)
{ {
foreach ($filter->getRequirements() as $requirement) foreach ($filter->getRequirements() as $requirement)
{ {
@ -264,7 +273,7 @@ abstract class AbstractDao implements ICrudDao
$orderByString = ''; $orderByString = '';
foreach ($order as $orderColumn => $orderDir) foreach ($order as $orderColumn => $orderDir)
{ {
if ($orderColumn === \Szurubooru\SearchServices\Filters\BasicFilter::ORDER_RANDOM) if ($orderColumn === IFilter::ORDER_RANDOM)
{ {
$driver = $this->driver; $driver = $this->driver;
if ($driver === 'sqlite') if ($driver === 'sqlite')
@ -276,12 +285,12 @@ abstract class AbstractDao implements ICrudDao
$orderColumn = 'RAND()'; $orderColumn = 'RAND()';
} }
} }
$orderByString .= $orderColumn . ' ' . ($orderDir === \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', '; $orderByString .= $orderColumn . ' ' . ($orderDir === IFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', ';
} }
return substr($orderByString, 0, -2); return substr($orderByString, 0, -2);
} }
private function upsert(\Szurubooru\Entities\Entity $entity) private function upsert(Entity $entity)
{ {
if ($entity->getId()) if ($entity->getId())
{ {

View file

@ -1,5 +1,12 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\CommentEntityConverter;
use Szurubooru\Dao\PostDao;
use Szurubooru\Dao\UserDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Comment;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Post;
class CommentDao extends AbstractDao implements ICrudDao class CommentDao extends AbstractDao implements ICrudDao
{ {
@ -7,36 +14,36 @@ class CommentDao extends AbstractDao implements ICrudDao
private $postDao; private $postDao;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Dao\UserDao $userDao, UserDao $userDao,
\Szurubooru\Dao\PostDao $postDao) PostDao $postDao)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'comments', 'comments',
new \Szurubooru\Dao\EntityConverters\CommentEntityConverter()); new CommentEntityConverter());
$this->userDao = $userDao; $this->userDao = $userDao;
$this->postDao = $postDao; $this->postDao = $postDao;
} }
public function findByPost(\Szurubooru\Entities\Post $post) public function findByPost(Post $post)
{ {
return $this->findBy('postId', $post->getId()); return $this->findBy('postId', $post->getId());
} }
protected function afterLoad(\Szurubooru\Entities\Entity $comment) protected function afterLoad(Entity $comment)
{ {
$comment->setLazyLoader( $comment->setLazyLoader(
\Szurubooru\Entities\Comment::LAZY_LOADER_USER, Comment::LAZY_LOADER_USER,
function (\Szurubooru\Entities\Comment $comment) function (Comment $comment)
{ {
return $this->userDao->findById($comment->getUserId()); return $this->userDao->findById($comment->getUserId());
}); });
$comment->setLazyLoader( $comment->setLazyLoader(
\Szurubooru\Entities\Comment::LAZY_LOADER_POST, Comment::LAZY_LOADER_POST,
function (\Szurubooru\Entities\Comment $comment) function (Comment $comment)
{ {
return $this->postDao->findById($comment->getPostId()); return $this->postDao->findById($comment->getPostId());
}); });

View file

@ -5,7 +5,7 @@ abstract class AbstractEntityConverter implements IEntityConverter
{ {
private $entityDecorator = null; private $entityDecorator = null;
public function setEntityDecorator($entityDecorator) public function setEntityDecorator(callable $entityDecorator)
{ {
$this->entityDecorator = $entityDecorator; $this->entityDecorator = $entityDecorator;
} }
@ -13,8 +13,9 @@ abstract class AbstractEntityConverter implements IEntityConverter
public function toEntity(array $array) public function toEntity(array $array)
{ {
$entity = $this->toBasicEntity($array); $entity = $this->toBasicEntity($array);
if ($this->entityDecorator !== null) $func = $this->entityDecorator;
call_user_func($this->entityDecorator, $entity); if ($func !== null)
$func($entity);
return $entity; return $entity;
} }

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Comment;
use Szurubooru\Entities\Entity;
class CommentEntityConverter extends AbstractEntityConverter implements IEntityConverter class CommentEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -18,13 +20,13 @@ class CommentEntityConverter extends AbstractEntityConverter implements IEntityC
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Comment($array['id']); $entity = new Comment($array['id']);
$entity->setUserId($array['userId']); $entity->setUserId($array['userId']);
$entity->setPostId($array['postId']); $entity->setPostId($array['postId']);
$entity->setText($array['text']); $entity->setText($array['text']);
$entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime'])); $entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime']));
$entity->setLastEditTime($this->dbTimeToEntityTime($array['lastEditTime'])); $entity->setLastEditTime($this->dbTimeToEntityTime($array['lastEditTime']));
$entity->setMeta(\Szurubooru\Entities\Comment::META_SCORE, intval($array['score'])); $entity->setMeta(Comment::META_SCORE, intval($array['score']));
return $entity; return $entity;
} }
} }

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Favorite;
class FavoriteEntityConverter extends AbstractEntityConverter implements IEntityConverter class FavoriteEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -16,7 +18,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Favorite($array['id']); $entity = new Favorite($array['id']);
$entity->setUserId($array['userId']); $entity->setUserId($array['userId']);
$entity->setPostId($array['postId']); $entity->setPostId($array['postId']);
$entity->setTime($this->dbTimeToEntityTime($array['time'])); $entity->setTime($this->dbTimeToEntityTime($array['time']));

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\GlobalParam;
class GlobalParamEntityConverter extends AbstractEntityConverter implements IEntityConverter class GlobalParamEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -15,7 +17,7 @@ class GlobalParamEntityConverter extends AbstractEntityConverter implements IEnt
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\GlobalParam($array['id']); $entity = new GlobalParam($array['id']);
$entity->setKey($array['dataKey']); $entity->setKey($array['dataKey']);
$entity->setValue($array['dataValue']); $entity->setValue($array['dataValue']);
return $entity; return $entity;

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
interface IEntityConverter interface IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity); public function toArray(Entity $entity);
public function toEntity(array $array); public function toEntity(array $array);
} }

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Post;
class PostEntityConverter extends AbstractEntityConverter implements IEntityConverter class PostEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -28,7 +30,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Post(intval($array['id'])); $entity = new Post(intval($array['id']));
$entity->setName($array['name']); $entity->setName($array['name']);
$entity->setUserId($array['userId']); $entity->setUserId($array['userId']);
$entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime'])); $entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime']));
@ -44,10 +46,10 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity->setOriginalFileName($array['originalFileName']); $entity->setOriginalFileName($array['originalFileName']);
$entity->setFeatureCount(intval($array['featureCount'])); $entity->setFeatureCount(intval($array['featureCount']));
$entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime'])); $entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime']));
$entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount'])); $entity->setMeta(Post::META_TAG_COUNT, intval($array['tagCount']));
$entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount'])); $entity->setMeta(Post::META_FAV_COUNT, intval($array['favCount']));
$entity->setMeta(\Szurubooru\Entities\Post::META_COMMENT_COUNT, intval($array['commentCount'])); $entity->setMeta(Post::META_COMMENT_COUNT, intval($array['commentCount']));
$entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score'])); $entity->setMeta(Post::META_SCORE, intval($array['score']));
return $entity; return $entity;
} }
} }

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Score;
class ScoreEntityConverter extends AbstractEntityConverter implements IEntityConverter class ScoreEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -18,7 +20,7 @@ class ScoreEntityConverter extends AbstractEntityConverter implements IEntityCon
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Score($array['id']); $entity = new Score($array['id']);
$entity->setUserId($array['userId']); $entity->setUserId($array['userId']);
$entity->setPostId($array['postId']); $entity->setPostId($array['postId']);
$entity->setCommentId($array['commentId']); $entity->setCommentId($array['commentId']);

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Snapshot;
class SnapshotEntityConverter extends AbstractEntityConverter implements IEntityConverter class SnapshotEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -20,7 +22,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Snapshot(intval($array['id'])); $entity = new Snapshot(intval($array['id']));
$entity->setTime($this->dbTimeToEntityTime($array['time'])); $entity->setTime($this->dbTimeToEntityTime($array['time']));
$entity->setType(intval($array['type'])); $entity->setType(intval($array['type']));
$entity->setPrimaryKey($array['primaryKey']); $entity->setPrimaryKey($array['primaryKey']);

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Tag;
class TagEntityConverter extends AbstractEntityConverter implements IEntityConverter class TagEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -15,10 +17,10 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Tag($array['id']); $entity = new Tag($array['id']);
$entity->setName($array['name']); $entity->setName($array['name']);
$entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime'])); $entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime']));
$entity->setMeta(\Szurubooru\Entities\Tag::META_USAGES, intval($array['usages'])); $entity->setMeta(Tag::META_USAGES, intval($array['usages']));
return $entity; return $entity;
} }
} }

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Token;
class TokenEntityConverter extends AbstractEntityConverter implements IEntityConverter class TokenEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -16,7 +18,7 @@ class TokenEntityConverter extends AbstractEntityConverter implements IEntityCon
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\Token(intval($array['id'])); $entity = new Token(intval($array['id']));
$entity->setName($array['name']); $entity->setName($array['name']);
$entity->setPurpose($array['purpose']); $entity->setPurpose($array['purpose']);
$entity->setAdditionalData($array['additionalData']); $entity->setAdditionalData($array['additionalData']);

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Szurubooru\Dao\EntityConverters; namespace Szurubooru\Dao\EntityConverters;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\User;
class UserEntityConverter extends AbstractEntityConverter implements IEntityConverter class UserEntityConverter extends AbstractEntityConverter implements IEntityConverter
{ {
public function toArray(\Szurubooru\Entities\Entity $entity) public function toArray(Entity $entity)
{ {
return return
[ [
@ -25,7 +27,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
public function toBasicEntity(array $array) public function toBasicEntity(array $array)
{ {
$entity = new \Szurubooru\Entities\User(intval($array['id'])); $entity = new User(intval($array['id']));
$entity->setName($array['name']); $entity->setName($array['name']);
$entity->setEmail($array['email']); $entity->setEmail($array['email']);
$entity->setEmailUnconfirmed($array['emailUnconfirmed']); $entity->setEmailUnconfirmed($array['emailUnconfirmed']);

View file

@ -1,40 +1,47 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\FavoriteEntityConverter;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Favorite;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
use Szurubooru\Services\TimeService;
class FavoritesDao extends AbstractDao implements ICrudDao class FavoritesDao extends AbstractDao implements ICrudDao
{ {
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Services\TimeService $timeService) TimeService $timeService)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'favorites', 'favorites',
new \Szurubooru\Dao\EntityConverters\FavoriteEntityConverter()); new FavoriteEntityConverter());
$this->timeService = $timeService; $this->timeService = $timeService;
} }
public function findByEntity(\Szurubooru\Entities\Entity $entity) public function findByEntity(Entity $entity)
{ {
if ($entity instanceof \Szurubooru\Entities\Post) if ($entity instanceof Post)
return $this->findBy('postId', $entity->getId()); return $this->findBy('postId', $entity->getId());
else else
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
} }
public function set(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function set(User $user, Entity $entity)
{ {
$favorite = $this->get($user, $entity); $favorite = $this->get($user, $entity);
if (!$favorite) if (!$favorite)
{ {
$favorite = new \Szurubooru\Entities\Favorite(); $favorite = new Favorite();
$favorite->setTime($this->timeService->getCurrentTime()); $favorite->setTime($this->timeService->getCurrentTime());
$favorite->setUserId($user->getId()); $favorite->setUserId($user->getId());
if ($entity instanceof \Szurubooru\Entities\Post) if ($entity instanceof Post)
$favorite->setPostId($entity->getId()); $favorite->setPostId($entity->getId());
else else
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -44,18 +51,18 @@ class FavoritesDao extends AbstractDao implements ICrudDao
return $favorite; return $favorite;
} }
public function delete(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function delete(User $user, Entity $entity)
{ {
$favorite = $this->get($user, $entity); $favorite = $this->get($user, $entity);
if ($favorite) if ($favorite)
$this->deleteById($favorite->getId()); $this->deleteById($favorite->getId());
} }
private function get(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) private function get(User $user, Entity $entity)
{ {
$query = $this->fpdo->from($this->tableName)->where('userId', $user->getId()); $query = $this->fpdo->from($this->tableName)->where('userId', $user->getId());
if ($entity instanceof \Szurubooru\Entities\Post) if ($entity instanceof Post)
$query->where('postId', $entity->getId()); $query->where('postId', $entity->getId());
else else
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();

View file

@ -1,14 +1,16 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\GlobalParamEntityConverter;
use Szurubooru\DatabaseConnection;
class GlobalParamDao extends AbstractDao implements ICrudDao class GlobalParamDao extends AbstractDao implements ICrudDao
{ {
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection) public function __construct(DatabaseConnection $databaseConnection)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'globals', 'globals',
new \Szurubooru\Dao\EntityConverters\GlobalParamEntityConverter()); new GlobalParamEntityConverter());
} }
public function save(&$entity) public function save(&$entity)

View file

@ -1,5 +1,15 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\PostEntityConverter;
use Szurubooru\Dao\TagDao;
use Szurubooru\Dao\UserDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Post;
use Szurubooru\SearchServices\Filters\PostFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\Services\FileService;
use Szurubooru\Services\ThumbnailService;
class PostDao extends AbstractDao implements ICrudDao class PostDao extends AbstractDao implements ICrudDao
{ {
@ -9,16 +19,16 @@ class PostDao extends AbstractDao implements ICrudDao
private $thumbnailService; private $thumbnailService;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Dao\TagDao $tagDao, TagDao $tagDao,
\Szurubooru\Dao\UserDao $userDao, UserDao $userDao,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Services\ThumbnailService $thumbnailService) ThumbnailService $thumbnailService)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'posts', 'posts',
new \Szurubooru\Dao\EntityConverters\PostEntityConverter()); new PostEntityConverter());
$this->tagDao = $tagDao; $this->tagDao = $tagDao;
$this->userDao = $userDao; $this->userDao = $userDao;
@ -47,45 +57,45 @@ class PostDao extends AbstractDao implements ICrudDao
return $this->findOneBy('contentChecksum', $checksum); return $this->findOneBy('contentChecksum', $checksum);
} }
protected function afterLoad(\Szurubooru\Entities\Entity $post) protected function afterLoad(Entity $post)
{ {
$post->setLazyLoader( $post->setLazyLoader(
\Szurubooru\Entities\Post::LAZY_LOADER_CONTENT, Post::LAZY_LOADER_CONTENT,
function (\Szurubooru\Entities\Post $post) function (Post $post)
{ {
return $this->fileService->load($post->getContentPath()); return $this->fileService->load($post->getContentPath());
}); });
$post->setLazyLoader( $post->setLazyLoader(
\Szurubooru\Entities\Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT, Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT,
function (\Szurubooru\Entities\Post $post) function (Post $post)
{ {
return $this->fileService->load($post->getThumbnailSourceContentPath()); return $this->fileService->load($post->getThumbnailSourceContentPath());
}); });
$post->setLazyLoader( $post->setLazyLoader(
\Szurubooru\Entities\Post::LAZY_LOADER_USER, Post::LAZY_LOADER_USER,
function (\Szurubooru\Entities\Post $post) function (Post $post)
{ {
return $this->getUser($post); return $this->getUser($post);
}); });
$post->setLazyLoader( $post->setLazyLoader(
\Szurubooru\Entities\Post::LAZY_LOADER_TAGS, Post::LAZY_LOADER_TAGS,
function (\Szurubooru\Entities\Post $post) function (Post $post)
{ {
return $this->getTags($post); return $this->getTags($post);
}); });
$post->setLazyLoader( $post->setLazyLoader(
\Szurubooru\Entities\Post::LAZY_LOADER_RELATED_POSTS, Post::LAZY_LOADER_RELATED_POSTS,
function (\Szurubooru\Entities\Post $post) function (Post $post)
{ {
return $this->getRelatedPosts($post); return $this->getRelatedPosts($post);
}); });
} }
protected function afterSave(\Szurubooru\Entities\Entity $post) protected function afterSave(Entity $post)
{ {
$this->syncContent($post); $this->syncContent($post);
$this->syncThumbnailSourceContent($post); $this->syncThumbnailSourceContent($post);
@ -93,9 +103,9 @@ class PostDao extends AbstractDao implements ICrudDao
$this->syncPostRelations($post); $this->syncPostRelations($post);
} }
protected function decorateQueryFromRequirement($query, \Szurubooru\SearchServices\Requirements\Requirement $requirement) protected function decorateQueryFromRequirement($query, Requirement $requirement)
{ {
if ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG) if ($requirement->getType() === PostFilter::REQUIREMENT_TAG)
{ {
$sql = 'EXISTS ( $sql = 'EXISTS (
SELECT 1 FROM postTags SELECT 1 FROM postTags
@ -110,24 +120,24 @@ class PostDao extends AbstractDao implements ICrudDao
return; return;
} }
elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE) elseif ($requirement->getType() === PostFilter::REQUIREMENT_FAVORITE)
{ {
$query->innerJoin('favorites _fav ON _fav.postId = posts.id'); $query->innerJoin('favorites _fav ON _fav.postId = posts.id');
$query->innerJoin('users favoritedBy ON favoritedBy.id = _fav.userId'); $query->innerJoin('users favoritedBy ON favoritedBy.id = _fav.userId');
} }
elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT) elseif ($requirement->getType() === PostFilter::REQUIREMENT_COMMENT)
{ {
$query->innerJoin('comments _comment ON _comment.postId = posts.id'); $query->innerJoin('comments _comment ON _comment.postId = posts.id');
$query->innerJoin('users commentedBy ON commentedBy.id = _comment.userId'); $query->innerJoin('users commentedBy ON commentedBy.id = _comment.userId');
} }
elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER) elseif ($requirement->getType() === PostFilter::REQUIREMENT_UPLOADER)
{ {
$query->innerJoin('users uploader ON uploader.id = userId'); $query->innerJoin('users uploader ON uploader.id = userId');
} }
elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE) elseif ($requirement->getType() === PostFilter::REQUIREMENT_USER_SCORE)
{ {
$values = $requirement->getValue()->getValues(); $values = $requirement->getValue()->getValues();
$userName = $values[0]; $userName = $values[0];
@ -147,17 +157,17 @@ class PostDao extends AbstractDao implements ICrudDao
parent::decorateQueryFromRequirement($query, $requirement); parent::decorateQueryFromRequirement($query, $requirement);
} }
private function getTags(\Szurubooru\Entities\Post $post) private function getTags(Post $post)
{ {
return $this->tagDao->findByPostId($post->getId()); return $this->tagDao->findByPostId($post->getId());
} }
private function getUser(\Szurubooru\Entities\Post $post) private function getUser(Post $post)
{ {
return $this->userDao->findById($post->getUserId()); return $this->userDao->findById($post->getUserId());
} }
private function getRelatedPosts(\Szurubooru\Entities\Post $post) private function getRelatedPosts(Post $post)
{ {
$query = $this->fpdo $query = $this->fpdo
->from('postRelations') ->from('postRelations')
@ -179,7 +189,7 @@ class PostDao extends AbstractDao implements ICrudDao
return $this->findByIds($relatedPostIds); return $this->findByIds($relatedPostIds);
} }
private function syncContent(\Szurubooru\Entities\Post $post) private function syncContent(Post $post)
{ {
$targetPath = $post->getContentPath(); $targetPath = $post->getContentPath();
$content = $post->getContent(); $content = $post->getContent();
@ -190,7 +200,7 @@ class PostDao extends AbstractDao implements ICrudDao
$this->thumbnailService->deleteUsedThumbnails($targetPath); $this->thumbnailService->deleteUsedThumbnails($targetPath);
} }
private function syncThumbnailSourceContent(\Szurubooru\Entities\Post $post) private function syncThumbnailSourceContent(Post $post)
{ {
$targetPath = $post->getThumbnailSourceContentPath(); $targetPath = $post->getThumbnailSourceContentPath();
$content = $post->getThumbnailSourceContent(); $content = $post->getThumbnailSourceContent();
@ -201,7 +211,7 @@ class PostDao extends AbstractDao implements ICrudDao
$this->thumbnailService->deleteUsedThumbnails($targetPath); $this->thumbnailService->deleteUsedThumbnails($targetPath);
} }
private function syncTags(\Szurubooru\Entities\Post $post) private function syncTags(Post $post)
{ {
$tagIds = array_map( $tagIds = array_map(
function ($tag) function ($tag)
@ -232,7 +242,7 @@ class PostDao extends AbstractDao implements ICrudDao
} }
} }
private function syncPostRelations(\Szurubooru\Entities\Post $post) private function syncPostRelations(Post $post)
{ {
$this->fpdo->deleteFrom('postRelations')->where('post1id', $post->getId())->execute(); $this->fpdo->deleteFrom('postRelations')->where('post1id', $post->getId())->execute();
$this->fpdo->deleteFrom('postRelations')->where('post2id', $post->getId())->execute(); $this->fpdo->deleteFrom('postRelations')->where('post2id', $post->getId())->execute();

View file

@ -1,29 +1,37 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\ScoreEntityConverter;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Comment;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\Score;
use Szurubooru\Entities\User;
use Szurubooru\Services\TimeService;
class ScoreDao extends AbstractDao implements ICrudDao class ScoreDao extends AbstractDao implements ICrudDao
{ {
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Services\TimeService $timeService) TimeService $timeService)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'scores', 'scores',
new \Szurubooru\Dao\EntityConverters\ScoreEntityConverter()); new ScoreEntityConverter());
$this->timeService = $timeService; $this->timeService = $timeService;
} }
public function getScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function getScore(User $user, Entity $entity)
{ {
$query = $this->fpdo->from($this->tableName)->where('userId', $user->getId()); $query = $this->fpdo->from($this->tableName)->where('userId', $user->getId());
if ($entity instanceof \Szurubooru\Entities\Post) if ($entity instanceof Post)
$query->where('postId', $entity->getId()); $query->where('postId', $entity->getId());
elseif ($entity instanceof \Szurubooru\Entities\Comment) elseif ($entity instanceof Comment)
$query->where('commentId', $entity->getId()); $query->where('commentId', $entity->getId());
else else
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -33,18 +41,18 @@ class ScoreDao extends AbstractDao implements ICrudDao
return array_shift($entities); return array_shift($entities);
} }
public function setScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity, $scoreValue) public function setScore(User $user, Entity $entity, $scoreValue)
{ {
$score = $this->getScore($user, $entity); $score = $this->getScore($user, $entity);
if (!$score) if (!$score)
{ {
$score = new \Szurubooru\Entities\Score(); $score = new Score();
$score->setTime($this->timeService->getCurrentTime()); $score->setTime($this->timeService->getCurrentTime());
$score->setUserId($user->getId()); $score->setUserId($user->getId());
if ($entity instanceof \Szurubooru\Entities\Post) if ($entity instanceof Post)
$score->setPostId($entity->getId()); $score->setPostId($entity->getId());
elseif ($entity instanceof \Szurubooru\Entities\Comment) elseif ($entity instanceof Comment)
$score->setCommentId($entity->getId()); $score->setCommentId($entity->getId());
else else
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();

View file

@ -1,18 +1,23 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\SnapshotEntityConverter;
use Szurubooru\Dao\UserDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Snapshot;
class SnapshotDao extends AbstractDao class SnapshotDao extends AbstractDao
{ {
private $userDao; private $userDao;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Dao\UserDao $userDao) UserDao $userDao)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'snapshots', 'snapshots',
new \Szurubooru\Dao\EntityConverters\SnapshotEntityConverter()); new SnapshotEntityConverter());
$this->userDao = $userDao; $this->userDao = $userDao;
} }
@ -27,17 +32,17 @@ class SnapshotDao extends AbstractDao
return $this->arrayToEntities(iterator_to_array($query)); return $this->arrayToEntities(iterator_to_array($query));
} }
public function afterLoad(\Szurubooru\Entities\Entity $snapshot) public function afterLoad(Entity $snapshot)
{ {
$snapshot->setLazyLoader( $snapshot->setLazyLoader(
\Szurubooru\Entities\Snapshot::LAZY_LOADER_USER, Snapshot::LAZY_LOADER_USER,
function (\Szurubooru\Entities\Snapshot $snapshot) function (Snapshot $snapshot)
{ {
return $this->getUser($snapshot); return $this->getUser($snapshot);
}); });
} }
private function getUser(\Szurubooru\Entities\Snapshot $snapshot) private function getUser(Snapshot $snapshot)
{ {
$userId = $snapshot->getUserId(); $userId = $snapshot->getUserId();
return $this->userDao->findById($userId); return $this->userDao->findById($userId);

View file

@ -1,15 +1,16 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\TagEntityConverter;
use Szurubooru\DatabaseConnection;
class TagDao extends AbstractDao implements ICrudDao class TagDao extends AbstractDao implements ICrudDao
{ {
public function __construct( public function __construct(DatabaseConnection $databaseConnection)
\Szurubooru\DatabaseConnection $databaseConnection)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'tags', 'tags',
new \Szurubooru\Dao\EntityConverters\TagEntityConverter()); new TagEntityConverter());
} }
public function findByNames($tagNames) public function findByNames($tagNames)

View file

@ -1,14 +1,16 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\TokenEntityConverter;
use Szurubooru\DatabaseConnection;
class TokenDao extends AbstractDao class TokenDao extends AbstractDao
{ {
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection) public function __construct(DatabaseConnection $databaseConnection)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'tokens', 'tokens',
new \Szurubooru\Dao\EntityConverters\TokenEntityConverter()); new TokenEntityConverter());
} }
public function findByName($tokenName) public function findByName($tokenName)

View file

@ -1,11 +1,12 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\DatabaseConnection;
class TransactionManager class TransactionManager
{ {
private $databaseConnection; private $databaseConnection;
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection) public function __construct(DatabaseConnection $databaseConnection)
{ {
$this->databaseConnection = $databaseConnection; $this->databaseConnection = $databaseConnection;
} }

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Szurubooru\Dao; namespace Szurubooru\Dao;
use Szurubooru\Dao\EntityConverters\UserEntityConverter;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\User;
use Szurubooru\Services\FileService;
use Szurubooru\Services\ThumbnailService;
class UserDao extends AbstractDao implements ICrudDao class UserDao extends AbstractDao implements ICrudDao
{ {
@ -10,14 +16,14 @@ class UserDao extends AbstractDao implements ICrudDao
private $thumbnailService; private $thumbnailService;
public function __construct( public function __construct(
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Services\ThumbnailService $thumbnailService) ThumbnailService $thumbnailService)
{ {
parent::__construct( parent::__construct(
$databaseConnection, $databaseConnection,
'users', 'users',
new \Szurubooru\Dao\EntityConverters\UserEntityConverter()); new UserEntityConverter());
$this->fileService = $fileService; $this->fileService = $fileService;
$this->thumbnailService = $thumbnailService; $this->thumbnailService = $thumbnailService;
@ -49,18 +55,18 @@ class UserDao extends AbstractDao implements ICrudDao
$this->fpdo->deleteFrom('tokens')->where('additionalData', $userName); $this->fpdo->deleteFrom('tokens')->where('additionalData', $userName);
} }
protected function afterLoad(\Szurubooru\Entities\Entity $user) protected function afterLoad(Entity $user)
{ {
$user->setLazyLoader( $user->setLazyLoader(
\Szurubooru\Entities\User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT, User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT,
function(\Szurubooru\Entities\User $user) function(User $user)
{ {
$avatarSource = $user->getCustomAvatarSourceContentPath(); $avatarSource = $user->getCustomAvatarSourceContentPath();
return $this->fileService->load($avatarSource); return $this->fileService->load($avatarSource);
}); });
} }
protected function afterSave(\Szurubooru\Entities\Entity $user) protected function afterSave(Entity $user)
{ {
$targetPath = $user->getCustomAvatarSourceContentPath(); $targetPath = $user->getCustomAvatarSourceContentPath();
$content = $user->getCustomAvatarSourceContent(); $content = $user->getCustomAvatarSourceContent();
@ -71,7 +77,7 @@ class UserDao extends AbstractDao implements ICrudDao
$this->thumbnailService->deleteUsedThumbnails($targetPath); $this->thumbnailService->deleteUsedThumbnails($targetPath);
} }
protected function afterDelete(\Szurubooru\Entities\Entity $user) protected function afterDelete(Entity $user)
{ {
$avatarSource = $user->getCustomAvatarSourceContentPath(); $avatarSource = $user->getCustomAvatarSourceContentPath();
$this->fileService->delete($avatarSource); $this->fileService->delete($avatarSource);

View file

@ -1,12 +1,13 @@
<?php <?php
namespace Szurubooru; namespace Szurubooru;
use Szurubooru\Config;
class DatabaseConnection class DatabaseConnection
{ {
private $pdo; private $pdo;
private $config; private $config;
public function __construct(\Szurubooru\Config $config) public function __construct(Config $config)
{ {
$this->config = $config; $this->config = $config;
} }

View file

@ -1,5 +1,13 @@
<?php <?php
namespace Szurubooru; namespace Szurubooru;
use Szurubooru\Bootstrap;
use Szurubooru\Config;
use Szurubooru\ControllerRepository;
use Szurubooru\DatabaseConnection;
use Szurubooru\Helpers\HttpHelper;
use Szurubooru\Router;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\TokenService;
final class Dispatcher final class Dispatcher
{ {
@ -10,13 +18,13 @@ final class Dispatcher
private $tokenService; private $tokenService;
public function __construct( public function __construct(
\Szurubooru\Router $router, Router $router,
\Szurubooru\Config $config, Config $config,
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Helpers\HttpHelper $httpHelper, HttpHelper $httpHelper,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\TokenService $tokenService, TokenService $tokenService,
\Szurubooru\ControllerRepository $controllerRepository) ControllerRepository $controllerRepository)
{ {
$this->router = $router; $this->router = $router;
$this->config = $config; $this->config = $config;
@ -52,7 +60,7 @@ final class Dispatcher
]; ];
} }
$end = microtime(true); $end = microtime(true);
$json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime(); $json['__time'] = $end - Bootstrap::getStartTime();
if ($this->config->misc->dumpSqlIntoQueries) if ($this->config->misc->dumpSqlIntoQueries)
{ {
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount(); $json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount();

View file

@ -1,5 +1,7 @@
<?php <?php
namespace Szurubooru\Entities; namespace Szurubooru\Entities;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
final class Comment extends Entity final class Comment extends Entity
{ {
@ -69,7 +71,7 @@ final class Comment extends Entity
return $this->lazyLoad(self::LAZY_LOADER_USER, null); return $this->lazyLoad(self::LAZY_LOADER_USER, null);
} }
public function setUser(\Szurubooru\Entities\User $user = null) public function setUser(User $user = null)
{ {
$this->lazySave(self::LAZY_LOADER_USER, $user); $this->lazySave(self::LAZY_LOADER_USER, $user);
$this->userId = $user ? $user->getId() : null; $this->userId = $user ? $user->getId() : null;
@ -80,7 +82,7 @@ final class Comment extends Entity
return $this->lazyLoad(self::LAZY_LOADER_POST, null); return $this->lazyLoad(self::LAZY_LOADER_POST, null);
} }
public function setPost(\Szurubooru\Entities\Post $post) public function setPost(Post $post)
{ {
$this->lazySave(self::LAZY_LOADER_POST, $post); $this->lazySave(self::LAZY_LOADER_POST, $post);
$this->postId = $post->getId(); $this->postId = $post->getId();

View file

@ -1,5 +1,7 @@
<?php <?php
namespace Szurubooru\Entities; namespace Szurubooru\Entities;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
final class Favorite extends Entity final class Favorite extends Entity
{ {
@ -45,7 +47,7 @@ final class Favorite extends Entity
return $this->lazyLoad(self::LAZY_LOADER_USER, null); return $this->lazyLoad(self::LAZY_LOADER_USER, null);
} }
public function setUser(\Szurubooru\Entities\User $user) public function setUser(User $user)
{ {
$this->lazySave(self::LAZY_LOADER_USER, $user); $this->lazySave(self::LAZY_LOADER_USER, $user);
$this->userId = $user->getId(); $this->userId = $user->getId();
@ -56,7 +58,7 @@ final class Favorite extends Entity
return $this->lazyLoad(self::LAZY_LOADER_POST, null); return $this->lazyLoad(self::LAZY_LOADER_POST, null);
} }
public function setPost(\Szurubooru\Entities\Post $post) public function setPost(Post $post)
{ {
$this->lazySave(self::LAZY_LOADER_POST, $post); $this->lazySave(self::LAZY_LOADER_POST, $post);
$this->postId = $post->getId(); $this->postId = $post->getId();

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Entities; namespace Szurubooru\Entities;
use Szurubooru\Entities\User;
final class Post extends Entity final class Post extends Entity
{ {
@ -220,7 +221,7 @@ final class Post extends Entity
return $this->lazyLoad(self::LAZY_LOADER_USER, null); return $this->lazyLoad(self::LAZY_LOADER_USER, null);
} }
public function setUser(\Szurubooru\Entities\User $user = null) public function setUser(User $user = null)
{ {
$this->lazySave(self::LAZY_LOADER_USER, $user); $this->lazySave(self::LAZY_LOADER_USER, $user);
$this->userId = $user ? $user->getId() : null; $this->userId = $user ? $user->getId() : null;

View file

@ -4,10 +4,10 @@ namespace Szurubooru\Entities;
final class Score extends Entity final class Score extends Entity
{ {
private $postId; private $postId;
private $userId;
private $commentId; private $commentId;
private $time;
private $score; private $score;
private $time;
private $userId;
public function getUserId() public function getUserId()
{ {

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Entities; namespace Szurubooru\Entities;
use Szurubooru\Entities\User;
final class Snapshot extends Entity final class Snapshot extends Entity
{ {
@ -93,7 +94,7 @@ final class Snapshot extends Entity
return $this->lazyLoad(self::LAZY_LOADER_USER, null); return $this->lazyLoad(self::LAZY_LOADER_USER, null);
} }
public function setUser(\Szurubooru\Entities\User $user = null) public function setUser(User $user = null)
{ {
$this->lazySave(self::LAZY_LOADER_USER, $user); $this->lazySave(self::LAZY_LOADER_USER, $user);
$this->userId = $user ? $user->getId() : null; $this->userId = $user ? $user->getId() : null;

View file

@ -1,7 +1,9 @@
<?php <?php
namespace Szurubooru\FormData; namespace Szurubooru\FormData;
use Szurubooru\IValidatable;
use Szurubooru\Validator;
class LoginFormData implements \Szurubooru\IValidatable class LoginFormData implements IValidatable
{ {
public $userNameOrEmail; public $userNameOrEmail;
public $password; public $password;
@ -15,7 +17,7 @@ class LoginFormData implements \Szurubooru\IValidatable
} }
} }
public function validate(\Szurubooru\Validator $validator) public function validate(Validator $validator)
{ {
} }
} }

View file

@ -1,7 +1,10 @@
<?php <?php
namespace Szurubooru\FormData; namespace Szurubooru\FormData;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\IValidatable;
use Szurubooru\Validator;
class PostEditFormData implements \Szurubooru\IValidatable class PostEditFormData implements IValidatable
{ {
public $content; public $content;
public $thumbnail; public $thumbnail;
@ -18,7 +21,7 @@ class PostEditFormData implements \Szurubooru\IValidatable
{ {
$this->content = $inputReader->decodeBase64($inputReader->content); $this->content = $inputReader->decodeBase64($inputReader->content);
$this->thumbnail = $inputReader->decodebase64($inputReader->thumbnail); $this->thumbnail = $inputReader->decodebase64($inputReader->thumbnail);
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety); $this->safety = EnumHelper::postSafetyFromString($inputReader->safety);
$this->source = $inputReader->source; $this->source = $inputReader->source;
$this->tags = preg_split('/[\s+]/', $inputReader->tags); $this->tags = preg_split('/[\s+]/', $inputReader->tags);
$this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations)); $this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations));
@ -26,7 +29,7 @@ class PostEditFormData implements \Szurubooru\IValidatable
} }
} }
public function validate(\Szurubooru\Validator $validator) public function validate(Validator $validator)
{ {
$validator->validatePostTags($this->tags); $validator->validatePostTags($this->tags);

View file

@ -1,7 +1,9 @@
<?php <?php
namespace Szurubooru\FormData; namespace Szurubooru\FormData;
use Szurubooru\IValidatable;
use Szurubooru\Validator;
class RegistrationFormData implements \Szurubooru\IValidatable class RegistrationFormData implements IValidatable
{ {
public $userName; public $userName;
public $password; public $password;
@ -17,7 +19,7 @@ class RegistrationFormData implements \Szurubooru\IValidatable
} }
} }
public function validate(\Szurubooru\Validator $validator) public function validate(Validator $validator)
{ {
$validator->validateUserName($this->userName); $validator->validateUserName($this->userName);
$validator->validatePassword($this->password); $validator->validatePassword($this->password);

View file

@ -1,7 +1,10 @@
<?php <?php
namespace Szurubooru\FormData; namespace Szurubooru\FormData;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\IValidatable;
use Szurubooru\Validator;
class UploadFormData implements \Szurubooru\IValidatable class UploadFormData implements IValidatable
{ {
public $contentFileName; public $contentFileName;
public $content; public $content;
@ -19,13 +22,13 @@ class UploadFormData implements \Szurubooru\IValidatable
$this->content = $inputReader->decodeBase64($inputReader->content); $this->content = $inputReader->decodeBase64($inputReader->content);
$this->url = $inputReader->url; $this->url = $inputReader->url;
$this->anonymous = $inputReader->anonymous; $this->anonymous = $inputReader->anonymous;
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety); $this->safety = EnumHelper::postSafetyFromString($inputReader->safety);
$this->source = $inputReader->source; $this->source = $inputReader->source;
$this->tags = preg_split('/[\s+]/', $inputReader->tags); $this->tags = preg_split('/[\s+]/', $inputReader->tags);
} }
} }
public function validate(\Szurubooru\Validator $validator) public function validate(Validator $validator)
{ {
if ($this->content === null and $this->url === null) if ($this->content === null and $this->url === null)
throw new \DomainException('Neither data or URL provided.'); throw new \DomainException('Neither data or URL provided.');

View file

@ -1,7 +1,11 @@
<?php <?php
namespace Szurubooru\FormData; namespace Szurubooru\FormData;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\IValidatable;
use Szurubooru\Validator;
class UserEditFormData implements \Szurubooru\IValidatable class UserEditFormData implements IValidatable
{ {
public $userName; public $userName;
public $email; public $email;
@ -20,16 +24,16 @@ class UserEditFormData implements \Szurubooru\IValidatable
$this->email = $inputReader->email; $this->email = $inputReader->email;
$this->password = $inputReader->password; $this->password = $inputReader->password;
if ($inputReader->accessRank !== null) if ($inputReader->accessRank !== null)
$this->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankFromString($inputReader->accessRank); $this->accessRank = EnumHelper::accessRankFromString($inputReader->accessRank);
if ($inputReader->avatarStyle !== null) if ($inputReader->avatarStyle !== null)
$this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle); $this->avatarStyle = EnumHelper::avatarStyleFromString($inputReader->avatarStyle);
$this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent); $this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent);
$this->browsingSettings = json_decode($inputReader->browsingSettings); $this->browsingSettings = json_decode($inputReader->browsingSettings);
$this->banned = boolval($inputReader->banned); $this->banned = boolval($inputReader->banned);
} }
} }
public function validate(\Szurubooru\Validator $validator) public function validate(Validator $validator)
{ {
if ($this->userName !== null) if ($this->userName !== null)
$validator->validateUserName($this->userName); $validator->validateUserName($this->userName);
@ -45,8 +49,8 @@ class UserEditFormData implements \Szurubooru\IValidatable
if ($this->avatarContent) if ($this->avatarContent)
{ {
$avatarContentMimeType = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($this->avatarContent); $avatarContentMimeType = MimeHelper::getMimeTypeFromBuffer($this->avatarContent);
if (!\Szurubooru\Helpers\MimeHelper::isImage($avatarContentMimeType)) if (!MimeHelper::isImage($avatarContentMimeType))
throw new \DomainException('Avatar must be an image (detected: ' . $avatarContentMimeType . ').'); throw new \DomainException('Avatar must be an image (detected: ' . $avatarContentMimeType . ').');
} }

View file

@ -1,43 +1,46 @@
<?php <?php
namespace Szurubooru\Helpers; namespace Szurubooru\Helpers;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\Snapshot;
use Szurubooru\Entities\User;
class EnumHelper class EnumHelper
{ {
private static $accessRankMap = private static $accessRankMap =
[ [
'anonymous' => \Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS, 'anonymous' => User::ACCESS_RANK_ANONYMOUS,
'regularUser' => \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER, 'regularUser' => User::ACCESS_RANK_REGULAR_USER,
'powerUser' => \Szurubooru\Entities\User::ACCESS_RANK_POWER_USER, 'powerUser' => User::ACCESS_RANK_POWER_USER,
'moderator' => \Szurubooru\Entities\User::ACCESS_RANK_MODERATOR, 'moderator' => User::ACCESS_RANK_MODERATOR,
'administrator' => \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR, 'administrator' => User::ACCESS_RANK_ADMINISTRATOR,
]; ];
private static $avatarStyleMap = private static $avatarStyleMap =
[ [
'gravatar' => \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR, 'gravatar' => User::AVATAR_STYLE_GRAVATAR,
'manual' => \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL, 'manual' => User::AVATAR_STYLE_MANUAL,
'none' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK, 'none' => User::AVATAR_STYLE_BLANK,
'blank' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK, 'blank' => User::AVATAR_STYLE_BLANK,
]; ];
private static $postSafetyMap = private static $postSafetyMap =
[ [
'safe' => \Szurubooru\Entities\Post::POST_SAFETY_SAFE, 'safe' => Post::POST_SAFETY_SAFE,
'sketchy' => \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY, 'sketchy' => Post::POST_SAFETY_SKETCHY,
'unsafe' => \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE, 'unsafe' => Post::POST_SAFETY_UNSAFE,
]; ];
private static $postTypeMap = private static $postTypeMap =
[ [
'image' => \Szurubooru\Entities\Post::POST_TYPE_IMAGE, 'image' => Post::POST_TYPE_IMAGE,
'video' => \Szurubooru\Entities\Post::POST_TYPE_VIDEO, 'video' => Post::POST_TYPE_VIDEO,
'flash' => \Szurubooru\Entities\Post::POST_TYPE_FLASH, 'flash' => Post::POST_TYPE_FLASH,
'youtube' => \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE, 'youtube' => Post::POST_TYPE_YOUTUBE,
]; ];
private static $snapshotTypeMap = private static $snapshotTypeMap =
[ [
'post' => \Szurubooru\Entities\Snapshot::TYPE_POST, 'post' => Snapshot::TYPE_POST,
]; ];
public static function accessRankToString($accessRank) public static function accessRankToString($accessRank)

View file

@ -1,7 +1,8 @@
<?php <?php
namespace Szurubooru; namespace Szurubooru;
use Szurubooru\Validator;
interface IValidatable interface IValidatable
{ {
public function validate(\Szurubooru\Validator $validator); public function validate(Validator $validator);
} }

View file

@ -1,5 +1,7 @@
<?php <?php
namespace Szurubooru; namespace Szurubooru;
use DI\ContainerBuilder;
use Doctrine\Common\Cache\ArrayCache;
final class Injector final class Injector
{ {
@ -12,8 +14,8 @@ final class Injector
. DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'di.php'; . DIRECTORY_SEPARATOR . 'di.php';
$builder = new \DI\ContainerBuilder(); $builder = new ContainerBuilder();
$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache()); $builder->setDefinitionCache(new ArrayCache());
$builder->addDefinitions($definitionsPath); $builder->addDefinitions($definitionsPath);
self::$container = $builder->build(); self::$container = $builder->build();
} }

View file

@ -6,7 +6,7 @@ final class Route
public $query; public $query;
public $route; public $route;
public function __construct($query, $route) public function __construct($query, callable $route)
{ {
$this->query = $query; $this->query = $query;
$this->route = $route; $this->route = $route;
@ -19,7 +19,8 @@ final class Route
if (!preg_match($this->regex, $query, $matches)) if (!preg_match($this->regex, $query, $matches))
return false; return false;
$routeArguments = $this->getRouteArguments($matches); $routeArguments = $this->getRouteArguments($matches);
$output = call_user_func_array($this->route, $routeArguments); $func = $this->route;
$output = $func(...array_values($routeArguments));
return true; return true;
} }

View file

@ -5,27 +5,27 @@ class Router
{ {
private $routes; private $routes;
public function get($query, $route) public function get($query, callable $route)
{ {
$this->route('GET', $query, $route); $this->route('GET', $query, $route);
} }
public function put($query, $route) public function put($query, callable $route)
{ {
$this->route('PUT', $query, $route); $this->route('PUT', $query, $route);
} }
public function delete($query, $route) public function delete($query, callable $route)
{ {
$this->route('DELETE', $query, $route); $this->route('DELETE', $query, $route);
} }
public function post($query, $route) public function post($query, callable $route)
{ {
$this->route('POST', $query, $route); $this->route('POST', $query, $route);
} }
private function route($method, $query, $route) private function route($method, $query, callable $route)
{ {
$this->routes[$method][] = new Route($query, $route); $this->routes[$method][] = new Route($query, $route);
} }

View file

@ -1,10 +1,9 @@
<?php <?php
namespace Szurubooru\SearchServices\Filters; namespace Szurubooru\SearchServices\Filters;
use Szurubooru\SearchServices\Requirements\Requirement;
class BasicFilter implements IFilter class BasicFilter implements IFilter
{ {
const ORDER_RANDOM = 'random';
private $order = []; private $order = [];
private $requirements = []; private $requirements = [];
private $pageNumber; private $pageNumber;
@ -20,7 +19,7 @@ class BasicFilter implements IFilter
$this->order = $order; $this->order = $order;
} }
public function addRequirement(\Szurubooru\SearchServices\Requirements\Requirement $requirement) public function addRequirement(Requirement $requirement)
{ {
$this->requirements[] = $requirement; $this->requirements[] = $requirement;
} }

View file

@ -1,8 +1,11 @@
<?php <?php
namespace Szurubooru\SearchServices\Filters; namespace Szurubooru\SearchServices\Filters;
use Szurubooru\SearchServices\Requirements\Requirement;
interface IFilter interface IFilter
{ {
const ORDER_RANDOM = 'random';
const ORDER_ASC = 1; const ORDER_ASC = 1;
const ORDER_DESC = -1; const ORDER_DESC = -1;
@ -12,7 +15,7 @@ interface IFilter
public function getRequirements(); public function getRequirements();
public function addRequirement(\Szurubooru\SearchServices\Requirements\Requirement $requirement); public function addRequirement(Requirement $requirement);
public function getPageSize(); public function getPageSize();

View file

@ -1,12 +1,20 @@
<?php <?php
namespace Szurubooru\SearchServices\Parsers; namespace Szurubooru\SearchServices\Parsers;
use Szurubooru\Helpers\InputReader;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
use Szurubooru\SearchServices\Requirements\RequirementRangedValue;
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
use Szurubooru\SearchServices\Tokens\NamedSearchToken;
use Szurubooru\SearchServices\Tokens\SearchToken;
abstract class AbstractSearchParser abstract class AbstractSearchParser
{ {
const ALLOW_COMPOSITE = 1; const ALLOW_COMPOSITE = 1;
const ALLOW_RANGES = 2; const ALLOW_RANGES = 2;
public function createFilterFromInputReader(\Szurubooru\Helpers\InputReader $inputReader) public function createFilterFromInputReader(InputReader $inputReader)
{ {
$filter = $this->createFilter(); $filter = $this->createFilter();
$filter->setOrder($this->getOrder($inputReader->order) + $filter->getOrder()); $filter->setOrder($this->getOrder($inputReader->order) + $filter->getOrder());
@ -21,14 +29,14 @@ abstract class AbstractSearchParser
foreach ($tokens as $token) foreach ($tokens as $token)
{ {
if ($token instanceof \Szurubooru\SearchServices\Tokens\NamedSearchToken) if ($token instanceof NamedSearchToken)
{ {
if ($token->getKey() === 'order') if ($token->getKey() === 'order')
$filter->setOrder($this->getOrder($token->getValue()) + $filter->getOrder()); $filter->setOrder($this->getOrder($token->getValue()) + $filter->getOrder());
else else
$this->decorateFilterFromNamedToken($filter, $token); $this->decorateFilterFromNamedToken($filter, $token);
} }
elseif ($token instanceof \Szurubooru\SearchServices\Tokens\SearchToken) elseif ($token instanceof SearchToken)
$this->decorateFilterFromToken($filter, $token); $this->decorateFilterFromToken($filter, $token);
else else
throw new \RuntimeException('Invalid search token type: ' . get_class($token)); throw new \RuntimeException('Invalid search token type: ' . get_class($token));
@ -39,13 +47,13 @@ abstract class AbstractSearchParser
protected abstract function createFilter(); protected abstract function createFilter();
protected abstract function decorateFilterFromToken($filter, $token); protected abstract function decorateFilterFromToken(IFilter $filter, SearchToken $token);
protected abstract function decorateFilterFromNamedToken($filter, $namedToken); protected abstract function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken);
protected abstract function getOrderColumn($token); protected abstract function getOrderColumn($tokenText);
protected function createRequirementValue($text, $flags = 0, $valueDecorator = null) protected function createRequirementValue($text, $flags = 0, callable $valueDecorator = null)
{ {
if ($valueDecorator === null) if ($valueDecorator === null)
{ {
@ -60,7 +68,7 @@ abstract class AbstractSearchParser
list ($minValue, $maxValue) = explode('..', $text); list ($minValue, $maxValue) = explode('..', $text);
$minValue = $valueDecorator($minValue); $minValue = $valueDecorator($minValue);
$maxValue = $valueDecorator($maxValue); $maxValue = $valueDecorator($maxValue);
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementRangedValue(); $tokenValue = new RequirementRangedValue();
$tokenValue->setMinValue($minValue); $tokenValue->setMinValue($minValue);
$tokenValue->setMaxValue($maxValue); $tokenValue->setMaxValue($maxValue);
return $tokenValue; return $tokenValue;
@ -69,18 +77,18 @@ abstract class AbstractSearchParser
{ {
$values = explode(',', $text); $values = explode(',', $text);
$values = array_map($valueDecorator, $values); $values = array_map($valueDecorator, $values);
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); $tokenValue = new RequirementCompositeValue();
$tokenValue->setValues($values); $tokenValue->setValues($values);
return $tokenValue; return $tokenValue;
} }
$value = $valueDecorator($text); $value = $valueDecorator($text);
return new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($value); return new RequirementSingleValue($value);
} }
protected function addRequirementFromToken($filter, $token, $type, $flags, $valueDecorator = null) protected function addRequirementFromToken($filter, $token, $type, $flags, callable $valueDecorator = null)
{ {
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType($type); $requirement->setType($type);
$requirement->setValue($this->createRequirementValue($token->getValue(), $flags, $valueDecorator)); $requirement->setValue($this->createRequirementValue($token->getValue(), $flags, $valueDecorator));
$requirement->setNegated($token->isNegated()); $requirement->setNegated($token->isNegated());
@ -99,14 +107,14 @@ abstract class AbstractSearchParser
if (count($token) === 1) if (count($token) === 1)
{ {
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC; $orderDir = IFilter::ORDER_DESC;
} }
elseif (count($token) === 2) elseif (count($token) === 2)
{ {
if ($token[1] === 'desc') if ($token[1] === 'desc')
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC; $orderDir = IFilter::ORDER_DESC;
elseif ($token[1] === 'asc') elseif ($token[1] === 'asc')
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC; $orderDir = IFilter::ORDER_ASC;
else else
throw new \Exception('Wrong search order direction'); throw new \Exception('Wrong search order direction');
} }
@ -139,14 +147,14 @@ abstract class AbstractSearchParser
$colonPosition = strpos($tokenText, ':'); $colonPosition = strpos($tokenText, ':');
if (($colonPosition !== false) and ($colonPosition > 0)) if (($colonPosition !== false) and ($colonPosition > 0))
{ {
$searchToken = new \Szurubooru\SearchServices\Tokens\NamedSearchToken(); $searchToken = new NamedSearchToken();
list ($tokenKey, $tokenValue) = explode(':', $tokenText, 2); list ($tokenKey, $tokenValue) = explode(':', $tokenText, 2);
$searchToken->setKey($tokenKey); $searchToken->setKey($tokenKey);
$searchToken->setValue($tokenValue); $searchToken->setValue($tokenValue);
} }
else else
{ {
$searchToken = new \Szurubooru\SearchServices\Tokens\SearchToken(); $searchToken = new SearchToken();
$searchToken->setValue($tokenText); $searchToken->setValue($tokenText);
} }

View file

@ -1,5 +1,15 @@
<?php <?php
namespace Szurubooru\SearchServices\Parsers; namespace Szurubooru\SearchServices\Parsers;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\NotSupportedException;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Filters\PostFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
use Szurubooru\SearchServices\Tokens\NamedSearchToken;
use Szurubooru\SearchServices\Tokens\SearchToken;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\PrivilegeService;
class PostSearchParser extends AbstractSearchParser class PostSearchParser extends AbstractSearchParser
{ {
@ -7,8 +17,8 @@ class PostSearchParser extends AbstractSearchParser
private $privilegeService; private $privilegeService;
public function __construct( public function __construct(
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\PrivilegeService $privilegeService) PrivilegeService $privilegeService)
{ {
$this->authService = $authService; $this->authService = $authService;
$this->privilegeService = $privilegeService; $this->privilegeService = $privilegeService;
@ -16,19 +26,19 @@ class PostSearchParser extends AbstractSearchParser
protected function createFilter() protected function createFilter()
{ {
return new \Szurubooru\SearchServices\Filters\PostFilter; return new PostFilter;
} }
protected function decorateFilterFromToken($filter, $token) protected function decorateFilterFromToken(IFilter $filter, SearchToken $token)
{ {
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG); $requirement->setType(PostFilter::REQUIREMENT_TAG);
$requirement->setValue($this->createRequirementValue($token->getValue())); $requirement->setValue($this->createRequirementValue($token->getValue()));
$requirement->setNegated($token->isNegated()); $requirement->setNegated($token->isNegated());
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
} }
protected function decorateFilterFromNamedToken($filter, $token) protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $token)
{ {
if ($token->getKey() === 'id') if ($token->getKey() === 'id')
$this->addIdRequirement($filter, $token); $this->addIdRequirement($filter, $token);
@ -81,53 +91,53 @@ class PostSearchParser extends AbstractSearchParser
elseif ($token->getKey() === 'special' and $token->getValue() === 'fav') elseif ($token->getKey() === 'special' and $token->getValue() === 'fav')
{ {
$this->privilegeService->assertLoggedIn(); $this->privilegeService->assertLoggedIn();
$token = new \Szurubooru\SearchServices\Tokens\NamedSearchToken(); $token = new NamedSearchToken();
$token->setKey('fav'); $token->setKey('fav');
$token->setValue($this->authService->getLoggedInUser()->getName()); $token->setValue($this->authService->getLoggedInUser()->getName());
$this->decorateFilterFromNamedToken($filter, $token); $this->decorateFilterFromNamedToken($filter, $token);
} }
else else
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
protected function getOrderColumn($token) protected function getOrderColumn($tokenText)
{ {
if ($token === 'id') if ($tokenText === 'id')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_ID; return PostFilter::ORDER_ID;
elseif ($token === 'fav_time') elseif ($tokenText === 'fav_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME; return PostFilter::ORDER_FAV_TIME;
elseif ($token === 'fav_count') elseif ($tokenText === 'fav_count')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_COUNT; return PostFilter::ORDER_FAV_COUNT;
elseif ($token === 'tag_count') elseif ($tokenText === 'tag_count')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_TAG_COUNT; return PostFilter::ORDER_TAG_COUNT;
elseif ($token === 'time') elseif ($tokenText === 'time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_EDIT_TIME; return PostFilter::ORDER_LAST_EDIT_TIME;
elseif ($token === 'score') elseif ($tokenText === 'score')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_SCORE; return PostFilter::ORDER_SCORE;
elseif ($token === 'file_size') elseif ($tokenText === 'file_size')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FILE_SIZE; return PostFilter::ORDER_FILE_SIZE;
elseif ($token === 'random') elseif ($tokenText === 'random')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_RANDOM; return PostFilter::ORDER_RANDOM;
elseif ($token === 'feature_time') elseif ($tokenText === 'feature_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FEATURE_TIME; return PostFilter::ORDER_LAST_FEATURE_TIME;
elseif ($token === 'comment_time') elseif ($tokenText === 'comment_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME; return PostFilter::ORDER_LAST_COMMENT_TIME;
elseif ($token === 'fav_time') elseif ($tokenText === 'fav_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FAV_TIME; return PostFilter::ORDER_LAST_FAV_TIME;
else else
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
private function addIdRequirement($filter, $token) private function addIdRequirement($filter, $token)
@ -135,7 +145,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID, PostFilter::REQUIREMENT_ID,
self::ALLOW_COMPOSITE | self::ALLOW_RANGES); self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
} }
@ -144,7 +154,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH, PostFilter::REQUIREMENT_HASH,
self::ALLOW_COMPOSITE); self::ALLOW_COMPOSITE);
} }
@ -173,7 +183,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE, PostFilter::REQUIREMENT_DATE,
self::ALLOW_RANGES); self::ALLOW_RANGES);
} }
@ -182,7 +192,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT, PostFilter::REQUIREMENT_TAG_COUNT,
self::ALLOW_COMPOSITE | self::ALLOW_RANGES); self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
} }
@ -191,7 +201,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT, PostFilter::REQUIREMENT_FAV_COUNT,
self::ALLOW_COMPOSITE | self::ALLOW_RANGES); self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
} }
@ -200,7 +210,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT, PostFilter::REQUIREMENT_COMMENT_COUNT,
self::ALLOW_COMPOSITE | self::ALLOW_RANGES); self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
} }
@ -209,7 +219,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SCORE, PostFilter::REQUIREMENT_SCORE,
self::ALLOW_COMPOSITE | self::ALLOW_RANGES); self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
} }
@ -218,7 +228,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER, PostFilter::REQUIREMENT_UPLOADER,
self::ALLOW_COMPOSITE); self::ALLOW_COMPOSITE);
} }
@ -227,11 +237,11 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY, PostFilter::REQUIREMENT_SAFETY,
self::ALLOW_COMPOSITE, self::ALLOW_COMPOSITE,
function ($value) function ($value)
{ {
return \Szurubooru\Helpers\EnumHelper::postSafetyFromString($value); return EnumHelper::postSafetyFromString($value);
}); });
} }
@ -240,7 +250,7 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE, PostFilter::REQUIREMENT_FAVORITE,
self::ALLOW_COMPOSITE); self::ALLOW_COMPOSITE);
} }
@ -249,11 +259,11 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TYPE, PostFilter::REQUIREMENT_TYPE,
self::ALLOW_COMPOSITE, self::ALLOW_COMPOSITE,
function ($value) function ($value)
{ {
return \Szurubooru\Helpers\EnumHelper::postTypeFromSTring($value); return EnumHelper::postTypeFromString($value);
}); });
} }
@ -262,16 +272,16 @@ class PostSearchParser extends AbstractSearchParser
$this->addRequirementFromToken( $this->addRequirementFromToken(
$filter, $filter,
$token, $token,
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT, PostFilter::REQUIREMENT_COMMENT,
self::ALLOW_COMPOSITE); self::ALLOW_COMPOSITE);
} }
private function addUserScoreRequirement($filter, $userName, $score, $isNegated) private function addUserScoreRequirement($filter, $userName, $score, $isNegated)
{ {
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); $tokenValue = new RequirementCompositeValue();
$tokenValue->setValues([$userName, $score]); $tokenValue->setValues([$userName, $score]);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE); $requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
$requirement->setValue($tokenValue); $requirement->setValue($tokenValue);
$requirement->setNegated($isNegated); $requirement->setNegated($isNegated);
$filter->addRequirement($requirement); $filter->addRequirement($requirement);

View file

@ -1,41 +1,48 @@
<?php <?php
namespace Szurubooru\SearchServices\Parsers; namespace Szurubooru\SearchServices\Parsers;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\NotSupportedException;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Filters\SnapshotFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Tokens\NamedSearchToken;
use Szurubooru\SearchServices\Tokens\SearchToken;
class SnapshotSearchParser extends AbstractSearchParser class SnapshotSearchParser extends AbstractSearchParser
{ {
protected function createFilter() protected function createFilter()
{ {
return new \Szurubooru\SearchServices\Filters\SnapshotFilter; return new SnapshotFilter;
} }
protected function decorateFilterFromToken($filter, $token) protected function decorateFilterFromToken(IFilter $filter, SearchToken $token)
{ {
if (substr_count($token->getValue(), ',') !== 1) if (substr_count($token->getValue(), ',') !== 1)
throw new \BadMethodCallException('Not supported'); throw new NotSupportedException();
if ($token->isNegated()) if ($token->isNegated())
throw new \BadMethodCallException('Not supported'); throw new NotSupportedException();
list ($type, $primaryKey) = explode(',', $token->getValue()); list ($type, $primaryKey) = explode(',', $token->getValue());
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
$requirement->setValue($this->createRequirementValue($primaryKey)); $requirement->setValue($this->createRequirementValue($primaryKey));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
$requirement->setValue($this->createRequirementValue(\Szurubooru\Helpers\EnumHelper::snapshotTypeFromString($type))); $requirement->setValue($this->createRequirementValue(EnumHelper::snapshotTypeFromString($type)));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
} }
protected function decorateFilterFromNamedToken($filter, $namedToken) protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken)
{ {
throw new \BadMethodCallException('Not supported'); throw new NotSupportedException();
} }
protected function getOrderColumn($token) protected function getOrderColumn($tokenText)
{ {
throw new \BadMethodCallException('Not supported'); throw new NotSupportedException();
} }
} }

View file

@ -1,38 +1,43 @@
<?php <?php
namespace Szurubooru\SearchServices\Parsers; namespace Szurubooru\SearchServices\Parsers;
use Szurubooru\NotSupportedException;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Filters\TagFilter;
use Szurubooru\SearchServices\Tokens\NamedSearchToken;
use Szurubooru\SearchServices\Tokens\SearchToken;
class TagSearchParser extends AbstractSearchParser class TagSearchParser extends AbstractSearchParser
{ {
protected function createFilter() protected function createFilter()
{ {
return new \Szurubooru\SearchServices\Filters\TagFilter; return new TagFilter;
} }
protected function decorateFilterFromToken($filter, $token) protected function decorateFilterFromToken(IFilter $filter, SearchToken $token)
{ {
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
protected function decorateFilterFromNamedToken($filter, $namedToken) protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken)
{ {
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
protected function getOrderColumn($token) protected function getOrderColumn($tokenText)
{ {
if ($token === 'id') if ($tokenText === 'id')
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_ID; return TagFilter::ORDER_ID;
elseif ($token === 'name') elseif ($tokenText === 'name')
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_NAME; return TagFilter::ORDER_NAME;
elseif ($token === 'creation_time') elseif ($tokenText === 'creation_time')
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_CREATION_TIME; return TagFilter::ORDER_CREATION_TIME;
elseif ($token === 'usage_count') elseif ($tokenText === 'usage_count')
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_USAGE_COUNT; return TagFilter::ORDER_USAGE_COUNT;
else else
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
} }

View file

@ -1,32 +1,37 @@
<?php <?php
namespace Szurubooru\SearchServices\Parsers; namespace Szurubooru\SearchServices\Parsers;
use Szurubooru\NotSupportedException;
use Szurubooru\SearchServices\Filters\IFilter;
use Szurubooru\SearchServices\Filters\UserFilter;
use Szurubooru\SearchServices\Tokens\NamedSearchToken;
use Szurubooru\SearchServices\Tokens\SearchToken;
class UserSearchParser extends AbstractSearchParser class UserSearchParser extends AbstractSearchParser
{ {
protected function createFilter() protected function createFilter()
{ {
return new \Szurubooru\SearchServices\Filters\UserFilter; return new UserFilter;
} }
protected function decorateFilterFromToken($filter, $token) protected function decorateFilterFromToken(IFilter $filter, SearchToken $token)
{ {
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
protected function decorateFilterFromNamedToken($filter, $namedToken) protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken)
{ {
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
protected function getOrderColumn($token) protected function getOrderColumn($tokenText)
{ {
if ($token === 'name') if ($tokenText === 'name')
return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME; return UserFilter::ORDER_NAME;
elseif ($token === 'registration_time') elseif ($tokenText === 'registration_time')
return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME; return UserFilter::ORDER_REGISTRATION_TIME;
else else
throw new \Szurubooru\NotSupportedException(); throw new NotSupportedException();
} }
} }

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\SearchServices; namespace Szurubooru\SearchServices;
use Szurubooru\SearchServices\Filters\IFilter;
class Result class Result
{ {
@ -9,7 +10,7 @@ class Result
public $entities; public $entities;
public $totalRecords; public $totalRecords;
public function setSearchFilter(Filters\IFilter $searchFilter = null) public function setSearchFilter(IFilter $searchFilter = null)
{ {
$this->searchFilter = $searchFilter; $this->searchFilter = $searchFilter;
} }

View file

@ -1,5 +1,12 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Entities\Token;
use Szurubooru\Entities\User;
use Szurubooru\Services\PasswordService;
use Szurubooru\Services\TimeService;
use Szurubooru\Services\TokenService;
use Szurubooru\Services\UserService;
class AuthService class AuthService
{ {
@ -13,11 +20,11 @@ class AuthService
private $tokenService; private $tokenService;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Services\PasswordService $passwordService, PasswordService $passwordService,
\Szurubooru\Services\TimeService $timeService, TimeService $timeService,
\Szurubooru\Services\TokenService $tokenService, TokenService $tokenService,
\Szurubooru\Services\UserService $userService) UserService $userService)
{ {
$this->config = $config; $this->config = $config;
$this->passwordService = $passwordService; $this->passwordService = $passwordService;
@ -60,9 +67,9 @@ class AuthService
$this->loggedInUser = $user; $this->loggedInUser = $user;
} }
public function loginFromToken(\Szurubooru\Entities\Token $token) public function loginFromToken(Token $token)
{ {
if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_LOGIN) if ($token->getPurpose() !== Token::PURPOSE_LOGIN)
throw new \Exception('This token is not a login token.'); throw new \Exception('This token is not a login token.');
$user = $this->userService->getById($token->getAdditionalData()); $user = $this->userService->getById($token->getAdditionalData());
@ -74,10 +81,10 @@ class AuthService
public function getAnonymousUser() public function getAnonymousUser()
{ {
$user = new \Szurubooru\Entities\User(); $user = new User();
$user->setName('Anonymous user'); $user->setName('Anonymous user');
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS); $user->setAccessRank(User::ACCESS_RANK_ANONYMOUS);
$user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_BLANK); $user->setAvatarStyle(User::AVATAR_STYLE_BLANK);
return $user; return $user;
} }
@ -96,9 +103,9 @@ class AuthService
$this->loginToken = null; $this->loginToken = null;
} }
private function createAndSaveLoginToken(\Szurubooru\Entities\User $user) private function createAndSaveLoginToken(User $user)
{ {
return $this->tokenService->createAndSaveToken($user->getId(), \Szurubooru\Entities\Token::PURPOSE_LOGIN); return $this->tokenService->createAndSaveToken($user->getId(), Token::PURPOSE_LOGIN);
} }
private function doFinalChecksOnUser($user) private function doFinalChecksOnUser($user)

View file

@ -1,5 +1,13 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\CommentDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Entities\Comment;
use Szurubooru\Entities\Post;
use Szurubooru\SearchServices\Filters\CommentFilter;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\TimeService;
use Szurubooru\Validator;
class CommentService class CommentService
{ {
@ -10,11 +18,11 @@ class CommentService
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\Validator $validator, Validator $validator,
\Szurubooru\Dao\CommentDao $commentDao, CommentDao $commentDao,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\TimeService $timeService) TimeService $timeService)
{ {
$this->validator = $validator; $this->validator = $validator;
$this->commentDao = $commentDao; $this->commentDao = $commentDao;
@ -35,7 +43,7 @@ class CommentService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getByPost(\Szurubooru\Entities\Post $post) public function getByPost(Post $post)
{ {
$transactionFunc = function() use ($post) $transactionFunc = function() use ($post)
{ {
@ -44,7 +52,7 @@ class CommentService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getFiltered(\Szurubooru\SearchServices\Filters\CommentFilter $filter) public function getFiltered(CommentFilter $filter)
{ {
$transactionFunc = function() use ($filter) $transactionFunc = function() use ($filter)
{ {
@ -53,11 +61,11 @@ class CommentService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function createComment(\Szurubooru\Entities\Post $post, $text) public function createComment(Post $post, $text)
{ {
$transactionFunc = function() use ($post, $text) $transactionFunc = function() use ($post, $text)
{ {
$comment = new \Szurubooru\Entities\Comment(); $comment = new Comment();
$comment->setCreationTime($this->timeService->getCurrentTime()); $comment->setCreationTime($this->timeService->getCurrentTime());
$comment->setLastEditTime($this->timeService->getCurrentTime()); $comment->setLastEditTime($this->timeService->getCurrentTime());
$comment->setUser($this->authService->isLoggedIn() ? $this->authService->getLoggedInUser() : null); $comment->setUser($this->authService->isLoggedIn() ? $this->authService->getLoggedInUser() : null);
@ -70,7 +78,7 @@ class CommentService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function updateComment(\Szurubooru\Entities\Comment $comment, $newText) public function updateComment(Comment $comment, $newText)
{ {
$transactionFunc = function() use ($comment, $newText) $transactionFunc = function() use ($comment, $newText)
{ {
@ -82,7 +90,7 @@ class CommentService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function deleteComment(\Szurubooru\Entities\Comment $comment) public function deleteComment(Comment $comment)
{ {
$transactionFunc = function() use ($comment) $transactionFunc = function() use ($comment)
{ {
@ -91,7 +99,7 @@ class CommentService
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
private function updateCommentText(\Szurubooru\Entities\Comment $comment, $text) private function updateCommentText(Comment $comment, $text)
{ {
$this->validator->validateLength($text, 5, 2000, 'Comment text'); $this->validator->validateLength($text, 5, 2000, 'Comment text');
$comment->setText($text); $comment->setText($text);

View file

@ -1,16 +1,19 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use \Szurubooru\Config;
use \Szurubooru\Entities\Token;
use \Szurubooru\Entities\User;
class EmailService class EmailService
{ {
private $config; private $config;
public function __construct(\Szurubooru\Config $config) public function __construct(Config $config)
{ {
$this->config = $config; $this->config = $config;
} }
public function sendPasswordResetEmail(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Token $token) public function sendPasswordResetEmail(User $user, Token $token)
{ {
if (!$user->getEmail()) if (!$user->getEmail())
throw new \BadMethodCall('An activated e-mail addreses is needed to reset the password.'); throw new \BadMethodCall('An activated e-mail addreses is needed to reset the password.');
@ -25,7 +28,7 @@ class EmailService
$this->sendEmail($user->getEmail(), $mailSubject, $mailBody); $this->sendEmail($user->getEmail(), $mailSubject, $mailBody);
} }
public function sendActivationEmail(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Token $token) public function sendActivationEmail(User $user, Token $token)
{ {
if (!$user->getEmailUnconfirmed()) if (!$user->getEmailUnconfirmed())
throw new \BadMethodCallException('An e-mail address is needed to activate the account.'); throw new \BadMethodCallException('An e-mail address is needed to activate the account.');

View file

@ -1,5 +1,12 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\FavoritesDao;
use Szurubooru\Dao\ScoreDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Dao\UserDao;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\User;
use Szurubooru\Services\TimeService;
class FavoritesService class FavoritesService
{ {
@ -10,11 +17,11 @@ class FavoritesService
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\Dao\FavoritesDao $favoritesDao, FavoritesDao $favoritesDao,
\Szurubooru\Dao\ScoreDao $scoreDao, ScoreDao $scoreDao,
\Szurubooru\Dao\UserDao $userDao, UserDao $userDao,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Services\TimeService $timeService) TimeService $timeService)
{ {
$this->favoritesDao = $favoritesDao; $this->favoritesDao = $favoritesDao;
$this->scoreDao = $scoreDao; $this->scoreDao = $scoreDao;
@ -23,7 +30,7 @@ class FavoritesService
$this->timeService = $timeService; $this->timeService = $timeService;
} }
public function getFavoriteUsers(\Szurubooru\Entities\Entity $entity) public function getFavoriteUsers(Entity $entity)
{ {
$transactionFunc = function() use ($entity) $transactionFunc = function() use ($entity)
{ {
@ -38,7 +45,7 @@ class FavoritesService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function addFavorite(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function addFavorite(User $user, Entity $entity)
{ {
$transactionFunc = function() use ($user, $entity) $transactionFunc = function() use ($user, $entity)
{ {
@ -49,7 +56,7 @@ class FavoritesService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function deleteFavorite(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function deleteFavorite(User $user, Entity $entity)
{ {
$transactionFunc = function() use ($user, $entity) $transactionFunc = function() use ($user, $entity)
{ {

View file

@ -1,12 +1,14 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Helpers\HttpHelper;
class FileService class FileService
{ {
private $dataDirectory; private $dataDirectory;
private $httpHelper; private $httpHelper;
public function __construct(\Szurubooru\Config $config, \Szurubooru\Helpers\HttpHelper $httpHelper) public function __construct(Config $config, HttpHelper $httpHelper)
{ {
$this->dataDirectory = $config->getPublicDataDirectory(); $this->dataDirectory = $config->getPublicDataDirectory();
$this->httpHelper = $httpHelper; $this->httpHelper = $httpHelper;

View file

@ -1,5 +1,18 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\GlobalParamDao;
use Szurubooru\Dao\SnapshotDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Entities\GlobalParam;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\Snapshot;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\SearchServices\Filters\SnapshotFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\TimeService;
use Szurubooru\Validator;
class HistoryService class HistoryService
{ {
@ -11,12 +24,12 @@ class HistoryService
private $transactionManager; private $transactionManager;
public function __construct( public function __construct(
\Szurubooru\Validator $validator, Validator $validator,
\Szurubooru\Dao\SnapshotDao $snapshotDao, SnapshotDao $snapshotDao,
\Szurubooru\Dao\GlobalParamDao $globalParamDao, GlobalParamDao $globalParamDao,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Services\TimeService $timeService, TimeService $timeService,
\Szurubooru\Services\AuthService $authService) AuthService $authService)
{ {
$this->validator = $validator; $this->validator = $validator;
$this->snapshotDao = $snapshotDao; $this->snapshotDao = $snapshotDao;
@ -26,7 +39,7 @@ class HistoryService
$this->transactionManager = $transactionManager; $this->transactionManager = $transactionManager;
} }
public function getFiltered(\Szurubooru\SearchServices\Filters\SnapshotFilter $filter) public function getFiltered(SnapshotFilter $filter)
{ {
$transactionFunc = function() use ($filter) $transactionFunc = function() use ($filter)
{ {
@ -35,24 +48,24 @@ class HistoryService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getPostHistory(\Szurubooru\Entities\Post $post) public function getPostHistory(Post $post)
{ {
$filter = new \Szurubooru\SearchServices\Filters\SnapshotFilter(); $filter = new SnapshotFilter();
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); $requirement->setValue(new RequirementSingleValue($post->getId()));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST)); $requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
return $this->getFiltered($filter)->getEntities(); return $this->getFiltered($filter)->getEntities();
} }
public function saveSnapshot(\Szurubooru\Entities\Snapshot $snapshot) public function saveSnapshot(Snapshot $snapshot)
{ {
$transactionFunc = function() use ($snapshot) $transactionFunc = function() use ($snapshot)
{ {
@ -79,23 +92,23 @@ class HistoryService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function getPostDeleteSnapshot(\Szurubooru\Entities\Post $post) public function getPostDeleteSnapshot(Post $post)
{ {
$snapshot = $this->getPostSnapshot($post); $snapshot = $this->getPostSnapshot($post);
$snapshot->setData([]); $snapshot->setData([]);
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_DELETE); $snapshot->setOperation(Snapshot::OPERATION_DELETE);
return $snapshot; return $snapshot;
} }
public function getPostChangeSnapshot(\Szurubooru\Entities\Post $post) public function getPostChangeSnapshot(Post $post)
{ {
$featuredPostParam = $this->globalParamDao->findByKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); $featuredPostParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST);
$isFeatured = ($featuredPostParam and intval($featuredPostParam->getValue()) === $post->getId()); $isFeatured = ($featuredPostParam and intval($featuredPostParam->getValue()) === $post->getId());
$data = $data =
[ [
'source' => $post->getSource(), 'source' => $post->getSource(),
'safety' => \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()), 'safety' => EnumHelper::postSafetyToString($post->getSafety()),
'contentChecksum' => $post->getContentChecksum(), 'contentChecksum' => $post->getContentChecksum(),
'featured' => $isFeatured, 'featured' => $isFeatured,
@ -118,7 +131,7 @@ class HistoryService
]; ];
$snapshot = $this->getPostSnapshot($post); $snapshot = $this->getPostSnapshot($post);
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE); $snapshot->setOperation(Snapshot::OPERATION_CHANGE);
$snapshot->setData($data); $snapshot->setData($data);
return $snapshot; return $snapshot;
} }
@ -153,10 +166,10 @@ class HistoryService
]; ];
} }
private function getPostSnapshot(\Szurubooru\Entities\Post $post) private function getPostSnapshot(Post $post)
{ {
$snapshot = new \Szurubooru\Entities\Snapshot(); $snapshot = new Snapshot();
$snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST); $snapshot->setType(Snapshot::TYPE_POST);
$snapshot->setPrimaryKey($post->getId()); $snapshot->setPrimaryKey($post->getId());
return $snapshot; return $snapshot;
} }

View file

@ -1,13 +1,15 @@
<?php <?php
namespace Szurubooru\Services\ImageManipulation; namespace Szurubooru\Services\ImageManipulation;
use Szurubooru\Services\ImageManipulation\GdImageManipulator;
use Szurubooru\Services\ImageManipulation\ImagickImageManipulator;
class ImageManipulator implements IImageManipulator class ImageManipulator implements IImageManipulator
{ {
private $strategy; private $strategy;
public function __construct( public function __construct(
\Szurubooru\Services\ImageManipulation\ImagickImageManipulator $imagickImageManipulator, ImagickImageManipulator $imagickImageManipulator,
\Szurubooru\Services\ImageManipulation\GdImageManipulator $gdImageManipulator) GdImageManipulator $gdImageManipulator)
{ {
if (extension_loaded('imagick')) if (extension_loaded('imagick'))
{ {

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
class PasswordService class PasswordService
{ {
@ -7,7 +8,7 @@ class PasswordService
private $alphabet; private $alphabet;
private $pattern; private $pattern;
public function __construct(\Szurubooru\Config $config) public function __construct(Config $config)
{ {
$this->config = $config; $this->config = $config;
$this->alphabet = $this->alphabet =

View file

@ -1,5 +1,26 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Dao\GlobalParamDao;
use Szurubooru\Dao\PostDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Entities\GlobalParam;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\Tag;
use Szurubooru\FormData\PostEditFormData;
use Szurubooru\FormData\UploadFormData;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\SearchServices\Filters\PostFilter;
use Szurubooru\SearchServices\Filters\SnapshotFilter;
use Szurubooru\SearchServices\Requirements\Requirement;
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\FileService;
use Szurubooru\Services\HistoryService;
use Szurubooru\Services\ImageManipulation\ImageManipulator;
use Szurubooru\Services\TagService;
use Szurubooru\Services\TimeService;
use Szurubooru\Validator;
class PostService class PostService
{ {
@ -16,17 +37,17 @@ class PostService
private $imageManipulator; private $imageManipulator;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Validator $validator, Validator $validator,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Dao\PostDao $postDao, PostDao $postDao,
\Szurubooru\Dao\GlobalParamDao $globalParamDao, GlobalParamDao $globalParamDao,
\Szurubooru\Services\AuthService $authService, AuthService $authService,
\Szurubooru\Services\TimeService $timeService, TimeService $timeService,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Services\TagService $tagService, TagService $tagService,
\Szurubooru\Services\HistoryService $historyService, HistoryService $historyService,
\Szurubooru\Services\ImageManipulation\ImageManipulator $imageManipulator) ImageManipulator $imageManipulator)
{ {
$this->config = $config; $this->config = $config;
$this->validator = $validator; $this->validator = $validator;
@ -67,7 +88,7 @@ class PostService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getFiltered(\Szurubooru\SearchServices\Filters\PostFilter $filter) public function getFiltered(PostFilter $filter)
{ {
$transactionFunc = function() use ($filter) $transactionFunc = function() use ($filter)
{ {
@ -80,7 +101,7 @@ class PostService
{ {
$transactionFunc = function() $transactionFunc = function()
{ {
$globalParam = $this->globalParamDao->findByKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); $globalParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST);
if (!$globalParam) if (!$globalParam)
return null; return null;
return $this->getByNameOrId($globalParam->getValue()); return $this->getByNameOrId($globalParam->getValue());
@ -88,20 +109,20 @@ class PostService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getHistory(\Szurubooru\Entities\Post $post) public function getHistory(Post $post)
{ {
$transactionFunc = function() use ($post) $transactionFunc = function() use ($post)
{ {
$filter = new \Szurubooru\SearchServices\Filters\SnapshotFilter(); $filter = new SnapshotFilter();
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); $requirement->setValue(new RequirementSingleValue($post->getId()));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST)); $requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST));
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
return $this->historyService->getFiltered($filter)->getEntities(); return $this->historyService->getFiltered($filter)->getEntities();
@ -109,13 +130,13 @@ class PostService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function createPost(\Szurubooru\FormData\UploadFormData $formData) public function createPost(UploadFormData $formData)
{ {
$transactionFunc = function() use ($formData) $transactionFunc = function() use ($formData)
{ {
$formData->validate($this->validator); $formData->validate($this->validator);
$post = new \Szurubooru\Entities\Post(); $post = new Post();
$post->setUploadTime($this->timeService->getCurrentTime()); $post->setUploadTime($this->timeService->getCurrentTime());
$post->setLastEditTime($this->timeService->getCurrentTime()); $post->setLastEditTime($this->timeService->getCurrentTime());
$post->setUser($formData->anonymous ? null : $this->authService->getLoggedInUser()); $post->setUser($formData->anonymous ? null : $this->authService->getLoggedInUser());
@ -138,7 +159,7 @@ class PostService
return $ret; return $ret;
} }
public function updatePost(\Szurubooru\Entities\Post $post, \Szurubooru\FormData\PostEditFormData $formData) public function updatePost(Post $post, PostEditFormData $formData)
{ {
$transactionFunc = function() use ($post, $formData) $transactionFunc = function() use ($post, $formData)
{ {
@ -176,17 +197,17 @@ class PostService
return $ret; return $ret;
} }
private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety) private function updatePostSafety(Post $post, $newSafety)
{ {
$post->setSafety($newSafety); $post->setSafety($newSafety);
} }
private function updatePostSource(\Szurubooru\Entities\Post $post, $newSource) private function updatePostSource(Post $post, $newSource)
{ {
$post->setSource($newSource); $post->setSource($newSource);
} }
private function updatePostContentFromStringOrUrl(\Szurubooru\Entities\Post $post, $content, $url) private function updatePostContentFromStringOrUrl(Post $post, $content, $url)
{ {
if ($url) if ($url)
$this->updatePostContentFromUrl($post, $url); $this->updatePostContentFromUrl($post, $url);
@ -196,7 +217,7 @@ class PostService
throw new \DomainException('No content specified'); throw new \DomainException('No content specified');
} }
private function updatePostContentFromString(\Szurubooru\Entities\Post $post, $content) private function updatePostContentFromString(Post $post, $content)
{ {
if (!$content) if (!$content)
throw new \DomainException('File cannot be empty.'); throw new \DomainException('File cannot be empty.');
@ -204,15 +225,15 @@ class PostService
if (strlen($content) > $this->config->database->maxPostSize) if (strlen($content) > $this->config->database->maxPostSize)
throw new \DomainException('Upload is too big.'); throw new \DomainException('Upload is too big.');
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content); $mime = MimeHelper::getMimeTypeFromBuffer($content);
$post->setContentMimeType($mime); $post->setContentMimeType($mime);
if (\Szurubooru\Helpers\MimeHelper::isFlash($mime)) if (MimeHelper::isFlash($mime))
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_FLASH); $post->setContentType(Post::POST_TYPE_FLASH);
elseif (\Szurubooru\Helpers\MimeHelper::isImage($mime)) elseif (MimeHelper::isImage($mime))
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_IMAGE); $post->setContentType(Post::POST_TYPE_IMAGE);
elseif (\Szurubooru\Helpers\MimeHelper::isVideo($mime)) elseif (MimeHelper::isVideo($mime))
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_VIDEO); $post->setContentType(Post::POST_TYPE_VIDEO);
else else
throw new \DomainException('Unhandled file type: "' . $mime . '"'); throw new \DomainException('Unhandled file type: "' . $mime . '"');
@ -228,7 +249,7 @@ class PostService
$post->setOriginalFileSize(strlen($content)); $post->setOriginalFileSize(strlen($content));
} }
private function updatePostContentFromUrl(\Szurubooru\Entities\Post $post, $url) private function updatePostContentFromUrl(Post $post, $url)
{ {
if (!preg_match('/^https?:\/\//', $url)) if (!preg_match('/^https?:\/\//', $url))
throw new \InvalidArgumentException('Invalid URL "' . $url . '"'); throw new \InvalidArgumentException('Invalid URL "' . $url . '"');
@ -239,7 +260,7 @@ class PostService
if ($youtubeId) if ($youtubeId)
{ {
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE); $post->setContentType(Post::POST_TYPE_YOUTUBE);
$post->setImageWidth(null); $post->setImageWidth(null);
$post->setImageHeight(null); $post->setImageHeight(null);
$post->setContentChecksum($url); $post->setContentChecksum($url);
@ -259,7 +280,7 @@ class PostService
} }
} }
private function updatePostThumbnailFromString(\Szurubooru\Entities\Post $post, $newThumbnail) private function updatePostThumbnailFromString(Post $post, $newThumbnail)
{ {
if (strlen($newThumbnail) > $this->config->database->maxCustomThumbnailSize) if (strlen($newThumbnail) > $this->config->database->maxCustomThumbnailSize)
throw new \DomainException('Thumbnail is too big.'); throw new \DomainException('Thumbnail is too big.');
@ -267,12 +288,12 @@ class PostService
$post->setThumbnailSourceContent($newThumbnail); $post->setThumbnailSourceContent($newThumbnail);
} }
private function updatePostTags(\Szurubooru\Entities\Post $post, array $newTagNames) private function updatePostTags(Post $post, array $newTagNames)
{ {
$tags = []; $tags = [];
foreach ($newTagNames as $tagName) foreach ($newTagNames as $tagName)
{ {
$tag = new \Szurubooru\Entities\Tag(); $tag = new Tag();
$tag->setName($tagName); $tag->setName($tagName);
$tags[] = $tag; $tags[] = $tag;
} }
@ -280,7 +301,7 @@ class PostService
$post->setTags($tags); $post->setTags($tags);
} }
private function updatePostRelations(\Szurubooru\Entities\Post $post, array $newRelatedPostIds) private function updatePostRelations(Post $post, array $newRelatedPostIds)
{ {
$relatedPosts = $this->postDao->findByIds($newRelatedPostIds); $relatedPosts = $this->postDao->findByIds($newRelatedPostIds);
foreach ($newRelatedPostIds as $postId) foreach ($newRelatedPostIds as $postId)
@ -292,7 +313,7 @@ class PostService
$post->setRelatedPosts($relatedPosts); $post->setRelatedPosts($relatedPosts);
} }
public function deletePost(\Szurubooru\Entities\Post $post) public function deletePost(Post $post)
{ {
$transactionFunc = function() use ($post) $transactionFunc = function() use ($post)
{ {
@ -302,7 +323,7 @@ class PostService
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
public function featurePost(\Szurubooru\Entities\Post $post) public function featurePost(Post $post)
{ {
$transactionFunc = function() use ($post) $transactionFunc = function() use ($post)
{ {
@ -311,8 +332,8 @@ class PostService
$post->setLastFeatureTime($this->timeService->getCurrentTime()); $post->setLastFeatureTime($this->timeService->getCurrentTime());
$post->setFeatureCount($post->getFeatureCount() + 1); $post->setFeatureCount($post->getFeatureCount() + 1);
$this->postDao->save($post); $this->postDao->save($post);
$globalParam = new \Szurubooru\Entities\GlobalParam(); $globalParam = new GlobalParam();
$globalParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); $globalParam->setKey(GlobalParam::KEY_FEATURED_POST);
$globalParam->setValue($post->getId()); $globalParam->setValue($post->getId());
$this->globalParamDao->save($globalParam); $this->globalParamDao->save($globalParam);
@ -327,20 +348,20 @@ class PostService
{ {
$transactionFunc = function() $transactionFunc = function()
{ {
$countParam = new \Szurubooru\Entities\GlobalParam(); $countParam = new GlobalParam();
$countParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_COUNT); $countParam->setKey(GlobalParam::KEY_POST_COUNT);
$countParam->setValue($this->postDao->getCount()); $countParam->setValue($this->postDao->getCount());
$this->globalParamDao->save($countParam); $this->globalParamDao->save($countParam);
$fileSizeParam = new \Szurubooru\Entities\GlobalParam(); $fileSizeParam = new GlobalParam();
$fileSizeParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_SIZE); $fileSizeParam->setKey(GlobalParam::KEY_POST_SIZE);
$fileSizeParam->setValue($this->postDao->getTotalFileSize()); $fileSizeParam->setValue($this->postDao->getTotalFileSize());
$this->globalParamDao->save($fileSizeParam); $this->globalParamDao->save($fileSizeParam);
}; };
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
private function assertNoPostWithThisContentChecksum(\Szurubooru\Entities\Post $parent) private function assertNoPostWithThisContentChecksum(Post $parent)
{ {
$checksumToCheck = $parent->getContentChecksum(); $checksumToCheck = $parent->getContentChecksum();
$postWithThisChecksum = $this->postDao->findByContentChecksum($checksumToCheck); $postWithThisChecksum = $this->postDao->findByContentChecksum($checksumToCheck);

View file

@ -1,5 +1,9 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Entities\User;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\Services\AuthService;
class PrivilegeService class PrivilegeService
{ {
@ -7,8 +11,8 @@ class PrivilegeService
private $privilegeMap; private $privilegeMap;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Services\AuthService $authService) AuthService $authService)
{ {
$this->authService = $authService; $this->authService = $authService;
@ -30,7 +34,7 @@ class PrivilegeService
public function getCurrentPrivileges() public function getCurrentPrivileges()
{ {
$currentAccessRank = $this->authService->getLoggedInUser()->getAccessRank(); $currentAccessRank = $this->authService->getLoggedInUser()->getAccessRank();
$currentAccessRankName = \Szurubooru\Helpers\EnumHelper::accessRankToString($currentAccessRank); $currentAccessRankName = EnumHelper::accessRankToString($currentAccessRank);
if (!isset($this->privilegeMap[$currentAccessRankName])) if (!isset($this->privilegeMap[$currentAccessRankName]))
return []; return [];
return $this->privilegeMap[$currentAccessRankName]; return $this->privilegeMap[$currentAccessRankName];
@ -64,7 +68,7 @@ class PrivilegeService
public function isLoggedIn($userIdentifier) public function isLoggedIn($userIdentifier)
{ {
$loggedInUser = $this->authService->getLoggedInUser(); $loggedInUser = $this->authService->getLoggedInUser();
if ($userIdentifier instanceof \Szurubooru\Entities\User) if ($userIdentifier instanceof User)
{ {
return $loggedInUser->getId() and ($loggedInUser->getId() === $userIdentifier->getId()); return $loggedInUser->getId() and ($loggedInUser->getId() === $userIdentifier->getId());
} }

View file

@ -1,5 +1,13 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\FavoritesDao;
use Szurubooru\Dao\ScoreDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Dao\UserDao;
use Szurubooru\Entities\Entity;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
use Szurubooru\Services\TimeService;
class ScoreService class ScoreService
{ {
@ -10,11 +18,11 @@ class ScoreService
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\Dao\ScoreDao $scoreDao, ScoreDao $scoreDao,
\Szurubooru\Dao\FavoritesDao $favoritesDao, FavoritesDao $favoritesDao,
\Szurubooru\Dao\UserDao $userDao, UserDao $userDao,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Services\TimeService $timeService) TimeService $timeService)
{ {
$this->scoreDao = $scoreDao; $this->scoreDao = $scoreDao;
$this->favoritesDao = $favoritesDao; $this->favoritesDao = $favoritesDao;
@ -23,7 +31,7 @@ class ScoreService
$this->timeService = $timeService; $this->timeService = $timeService;
} }
public function getScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function getScore(User $user, Entity $entity)
{ {
$transactionFunc = function() use ($user, $entity) $transactionFunc = function() use ($user, $entity)
{ {
@ -32,7 +40,7 @@ class ScoreService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getScoreValue(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) public function getScoreValue(User $user, Entity $entity)
{ {
$score = $this->getScore($user, $entity); $score = $this->getScore($user, $entity);
if (!$score) if (!$score)
@ -40,14 +48,14 @@ class ScoreService
return $score->getScore(); return $score->getScore();
} }
public function setScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity, $scoreValue) public function setScore(User $user, Entity $entity, $scoreValue)
{ {
if ($scoreValue !== 1 and $scoreValue !== 0 and $scoreValue !== -1) if ($scoreValue !== 1 and $scoreValue !== 0 and $scoreValue !== -1)
throw new \DomainException('Bad score'); throw new \DomainException('Bad score');
$transactionFunc = function() use ($user, $entity, $scoreValue) $transactionFunc = function() use ($user, $entity, $scoreValue)
{ {
if (($scoreValue !== 1) and ($entity instanceof \Szurubooru\Entities\Post)) if (($scoreValue !== 1) and ($entity instanceof Post))
$this->favoritesDao->delete($user, $entity); $this->favoritesDao->delete($user, $entity);
return $this->scoreDao->setScore($user, $entity, $scoreValue); return $this->scoreDao->setScore($user, $entity, $scoreValue);

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\TagDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Entities\Tag;
use Szurubooru\SearchServices\Filters\TagFilter;
use Szurubooru\Services\FileService;
use Szurubooru\Services\TimeService;
class TagService class TagService
{ {
@ -9,10 +15,10 @@ class TagService
private $timeService; private $timeService;
public function __construct( public function __construct(
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Dao\TagDao $tagDao, TagDao $tagDao,
\Szurubooru\Services\TimeService $timeService, TimeService $timeService,
\Szurubooru\Services\FileService $fileService) FileService $fileService)
{ {
$this->transactionManager = $transactionManager; $this->transactionManager = $transactionManager;
$this->tagDao = $tagDao; $this->tagDao = $tagDao;
@ -20,7 +26,7 @@ class TagService
$this->fileService = $fileService; $this->fileService = $fileService;
} }
public function getFiltered(\Szurubooru\SearchServices\Filters\TagFilter $filter) public function getFiltered(TagFilter $filter)
{ {
$transactionFunc = function() use ($filter) $transactionFunc = function() use ($filter)
{ {
@ -68,7 +74,7 @@ class TagService
$tagsToCreate = []; $tagsToCreate = [];
foreach ($tagNamesToCreate as $tagName) foreach ($tagNamesToCreate as $tagName)
{ {
$tag = new \Szurubooru\Entities\Tag; $tag = new Tag;
$tag->setName($tagName); $tag->setName($tagName);
$tag->setCreationTime($this->timeService->getCurrentTime()); $tag->setCreationTime($this->timeService->getCurrentTime());
$tagsToCreate[] = $tag; $tagsToCreate[] = $tag;

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Services\ThumbnailGenerators; namespace Szurubooru\Services\ThumbnailGenerators;
use Szurubooru\Helpers\ProgramExecutor;
class FlashThumbnailGenerator implements IThumbnailGenerator class FlashThumbnailGenerator implements IThumbnailGenerator
{ {
@ -19,9 +20,9 @@ class FlashThumbnailGenerator implements IThumbnailGenerator
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png'; $tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
file_put_contents($tmpSourcePath, $source); file_put_contents($tmpSourcePath, $source);
if (\Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH)) if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH))
{ {
\Szurubooru\Helpers\ProgramExecutor::run( ProgramExecutor::run(
self::PROGRAM_NAME_DUMP_GNASH, self::PROGRAM_NAME_DUMP_GNASH,
[ [
'--screenshot', 'last', '--screenshot', 'last',
@ -33,9 +34,9 @@ class FlashThumbnailGenerator implements IThumbnailGenerator
]); ]);
} }
if (!file_exists($tmpTargetPath) and \Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER)) if (!file_exists($tmpTargetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
{ {
\Szurubooru\Helpers\ProgramExecutor::run( ProgramExecutor::run(
self::PROGRAM_NAME_SWFRENDER, self::PROGRAM_NAME_SWFRENDER,
[ [
'swfrender', 'swfrender',

View file

@ -1,11 +1,13 @@
<?php <?php
namespace Szurubooru\Services\ThumbnailGenerators; namespace Szurubooru\Services\ThumbnailGenerators;
use Szurubooru\Services\ImageManipulation\IImageManipulator;
use Szurubooru\Services\ImageManipulation\ImageManipulator;
class ImageThumbnailGenerator implements IThumbnailGenerator class ImageThumbnailGenerator implements IThumbnailGenerator
{ {
private $imageManipulator; private $imageManipulator;
public function __construct(\Szurubooru\Services\ImageManipulation\ImageManipulator $imageManipulator) public function __construct(ImageManipulator $imageManipulator)
{ {
$this->imageManipulator = $imageManipulator; $this->imageManipulator = $imageManipulator;
} }
@ -34,7 +36,7 @@ class ImageThumbnailGenerator implements IThumbnailGenerator
return $this->imageManipulator->saveToBuffer( return $this->imageManipulator->saveToBuffer(
$image, $image,
\Szurubooru\Services\ImageManipulation\IImageManipulator::FORMAT_JPEG); IImageManipulator::FORMAT_JPEG);
} }
catch (\Exception $e) catch (\Exception $e)
{ {

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Services\ThumbnailGenerators; namespace Szurubooru\Services\ThumbnailGenerators;
use Szurubooru\Helpers\MimeHelper;
class SmartThumbnailGenerator implements IThumbnailGenerator class SmartThumbnailGenerator implements IThumbnailGenerator
{ {
@ -19,15 +20,15 @@ class SmartThumbnailGenerator implements IThumbnailGenerator
public function generate($source, $width, $height, $cropStyle) public function generate($source, $width, $height, $cropStyle)
{ {
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($source); $mime = MimeHelper::getMimeTypeFromBuffer($source);
if (\Szurubooru\Helpers\MimeHelper::isFlash($mime)) if (MimeHelper::isFlash($mime))
return $this->flashThumbnailGenerator->generate($source, $width, $height, $cropStyle); return $this->flashThumbnailGenerator->generate($source, $width, $height, $cropStyle);
if (\Szurubooru\Helpers\MimeHelper::isVideo($mime)) if (MimeHelper::isVideo($mime))
return $this->videoThumbnailGenerator->generate($source, $width, $height, $cropStyle); return $this->videoThumbnailGenerator->generate($source, $width, $height, $cropStyle);
if (\Szurubooru\Helpers\MimeHelper::isImage($mime)) if (MimeHelper::isImage($mime))
return $this->imageThumbnailGenerator->generate($source, $width, $height, $cropStyle); return $this->imageThumbnailGenerator->generate($source, $width, $height, $cropStyle);
return null; return null;

View file

@ -1,5 +1,6 @@
<?php <?php
namespace Szurubooru\Services\ThumbnailGenerators; namespace Szurubooru\Services\ThumbnailGenerators;
use \Szurubooru\Helpers\ProgramExecutor;
class VideoThumbnailGenerator implements IThumbnailGenerator class VideoThumbnailGenerator implements IThumbnailGenerator
{ {
@ -19,9 +20,9 @@ class VideoThumbnailGenerator implements IThumbnailGenerator
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png'; $tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
file_put_contents($tmpSourcePath, $source); file_put_contents($tmpSourcePath, $source);
if (\Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER)) if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER))
{ {
\Szurubooru\Helpers\ProgramExecutor::run( ProgramExecutor::run(
self::PROGRAM_NAME_FFMPEGTHUMBNAILER, self::PROGRAM_NAME_FFMPEGTHUMBNAILER,
[ [
'-i' . $tmpSourcePath, '-i' . $tmpSourcePath,
@ -31,9 +32,9 @@ class VideoThumbnailGenerator implements IThumbnailGenerator
]); ]);
} }
if (!file_exists($tmpTargetPath) and \Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG)) if (!file_exists($tmpTargetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
{ {
\Szurubooru\Helpers\ProgramExecutor::run(self::PROGRAM_NAME_FFMEPG, ProgramExecutor::run(self::PROGRAM_NAME_FFMEPG,
[ [
'-i', $tmpSourcePath, '-i', $tmpSourcePath,
'-vframes', '1', '-vframes', '1',

View file

@ -1,5 +1,9 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Services\FileService;
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
class ThumbnailService class ThumbnailService
{ {
@ -8,9 +12,9 @@ class ThumbnailService
private $thumbnailGenerator; private $thumbnailGenerator;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator $thumbnailGenerator) SmartThumbnailGenerator $thumbnailGenerator)
{ {
$this->config = $config; $this->config = $config;
$this->fileService = $fileService; $this->fileService = $fileService;
@ -40,11 +44,11 @@ class ThumbnailService
switch ($this->config->misc->thumbnailCropStyle) switch ($this->config->misc->thumbnailCropStyle)
{ {
case 'outside': case 'outside':
$cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE; $cropStyle = IThumbnailGenerator::CROP_OUTSIDE;
break; break;
case 'inside': case 'inside':
$cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_INSIDE; $cropStyle = IThumbnailGenerator::CROP_INSIDE;
break; break;
default: default:

View file

@ -1,5 +1,8 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Dao\TokenDao;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Entities\Token;
class TokenService class TokenService
{ {
@ -7,8 +10,8 @@ class TokenService
private $tokenDao; private $tokenDao;
public function __construct( public function __construct(
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Dao\TokenDao $tokenDao) TokenDao $tokenDao)
{ {
$this->transactionManager = $transactionManager; $this->transactionManager = $transactionManager;
$this->tokenDao = $tokenDao; $this->tokenDao = $tokenDao;
@ -52,7 +55,7 @@ class TokenService
if (!$token) if (!$token)
{ {
$token = new \Szurubooru\Entities\Token(); $token = new Token();
$token->setName(sha1(date('r') . uniqid() . microtime(true))); $token->setName(sha1(date('r') . uniqid() . microtime(true)));
$token->setAdditionalData($additionalData); $token->setAdditionalData($additionalData);
$token->setPurpose($tokenPurpose); $token->setPurpose($tokenPurpose);

View file

@ -1,5 +1,9 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\DatabaseConnection;
use Szurubooru\Upgrades\IUpgrade;
use Szurubooru\Upgrades\UpgradeRepository;
final class UpgradeService final class UpgradeService
{ {
@ -9,9 +13,9 @@ final class UpgradeService
private $executedUpgradeNames = []; private $executedUpgradeNames = [];
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\DatabaseConnection $databaseConnection, DatabaseConnection $databaseConnection,
\Szurubooru\Upgrades\UpgradeRepository $upgradeRepository) UpgradeRepository $upgradeRepository)
{ {
$this->config = $config; $this->config = $config;
$this->databaseConnection = $databaseConnection; $this->databaseConnection = $databaseConnection;
@ -42,12 +46,12 @@ final class UpgradeService
} }
} }
private function isUpgradeNeeded(\Szurubooru\Upgrades\IUpgrade $upgrade) private function isUpgradeNeeded(IUpgrade $upgrade)
{ {
return !in_array(get_class($upgrade), $this->executedUpgradeNames); return !in_array(get_class($upgrade), $this->executedUpgradeNames);
} }
private function runUpgrade(\Szurubooru\Upgrades\IUpgrade $upgrade) private function runUpgrade(IUpgrade $upgrade)
{ {
$upgrade->run($this->databaseConnection); $upgrade->run($this->databaseConnection);
$this->executedUpgradeNames[] = get_class($upgrade); $this->executedUpgradeNames[] = get_class($upgrade);

View file

@ -1,5 +1,21 @@
<?php <?php
namespace Szurubooru\Services; namespace Szurubooru\Services;
use Szurubooru\Config;
use Szurubooru\Dao\TransactionManager;
use Szurubooru\Dao\UserDao;
use Szurubooru\Entities\Token;
use Szurubooru\Entities\User;
use Szurubooru\FormData\RegistrationFormData;
use Szurubooru\FormData\UserEditFormData;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\SearchServices\Filters\UserFilter;
use Szurubooru\Services\EmailService;
use Szurubooru\Services\FileService;
use Szurubooru\Services\PasswordService;
use Szurubooru\Services\ThumbnailService;
use Szurubooru\Services\TimeService;
use Szurubooru\Services\TokenService;
use Szurubooru\Validator;
class UserService class UserService
{ {
@ -15,16 +31,16 @@ class UserService
private $tokenService; private $tokenService;
public function __construct( public function __construct(
\Szurubooru\Config $config, Config $config,
\Szurubooru\Validator $validator, Validator $validator,
\Szurubooru\Dao\TransactionManager $transactionManager, TransactionManager $transactionManager,
\Szurubooru\Dao\UserDao $userDao, UserDao $userDao,
\Szurubooru\Services\PasswordService $passwordService, PasswordService $passwordService,
\Szurubooru\Services\EmailService $emailService, EmailService $emailService,
\Szurubooru\Services\FileService $fileService, FileService $fileService,
\Szurubooru\Services\ThumbnailService $thumbnailService, ThumbnailService $thumbnailService,
\Szurubooru\Services\TimeService $timeService, TimeService $timeService,
\Szurubooru\Services\TokenService $tokenService) TokenService $tokenService)
{ {
$this->config = $config; $this->config = $config;
$this->validator = $validator; $this->validator = $validator;
@ -79,7 +95,7 @@ class UserService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function getFiltered(\Szurubooru\SearchServices\Filters\UserFilter $filter) public function getFiltered(UserFilter $filter)
{ {
$transactionFunc = function() use ($filter) $transactionFunc = function() use ($filter)
{ {
@ -88,30 +104,30 @@ class UserService
return $this->transactionManager->rollback($transactionFunc); return $this->transactionManager->rollback($transactionFunc);
} }
public function createUser(\Szurubooru\FormData\RegistrationFormData $formData) public function createUser(RegistrationFormData $formData)
{ {
$transactionFunc = function() use ($formData) $transactionFunc = function() use ($formData)
{ {
$formData->validate($this->validator); $formData->validate($this->validator);
$user = new \Szurubooru\Entities\User(); $user = new User();
$user->setRegistrationTime($this->timeService->getCurrentTime()); $user->setRegistrationTime($this->timeService->getCurrentTime());
$user->setLastLoginTime(null); $user->setLastLoginTime(null);
$user->setAccessRank($this->userDao->hasAnyUsers() $user->setAccessRank($this->userDao->hasAnyUsers()
? \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER ? User::ACCESS_RANK_REGULAR_USER
: \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR); : User::ACCESS_RANK_ADMINISTRATOR);
$user->setPasswordSalt($this->passwordService->getRandomPassword()); $user->setPasswordSalt($this->passwordService->getRandomPassword());
$this->updateUserName($user, $formData->userName); $this->updateUserName($user, $formData->userName);
$this->updateUserPassword($user, $formData->password); $this->updateUserPassword($user, $formData->password);
$this->updateUserAvatarStyle($user, \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR); $this->updateUserAvatarStyle($user, User::AVATAR_STYLE_GRAVATAR);
$this->updateUserEmail($user, $formData->email); $this->updateUserEmail($user, $formData->email);
return $this->userDao->save($user); return $this->userDao->save($user);
}; };
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function updateUser(\Szurubooru\Entities\User $user, \Szurubooru\FormData\UserEditFormData $formData) public function updateUser(User $user, UserEditFormData $formData)
{ {
$transactionFunc = function() use ($user, $formData) $transactionFunc = function() use ($user, $formData)
{ {
@ -146,7 +162,7 @@ class UserService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function deleteUser(\Szurubooru\Entities\User $user) public function deleteUser(User $user)
{ {
$transactionFunc = function() use ($user) $transactionFunc = function() use ($user)
{ {
@ -155,21 +171,21 @@ class UserService
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
public function sendPasswordResetEmail(\Szurubooru\Entities\User $user) public function sendPasswordResetEmail(User $user)
{ {
$transactionFunc = function() use ($user) $transactionFunc = function() use ($user)
{ {
$token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET); $token = $this->tokenService->createAndSaveToken($user->getName(), Token::PURPOSE_PASSWORD_RESET);
$this->emailService->sendPasswordResetEmail($user, $token); $this->emailService->sendPasswordResetEmail($user, $token);
}; };
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
public function finishPasswordReset(\Szurubooru\Entities\Token $token) public function finishPasswordReset(Token $token)
{ {
$transactionFunc = function() use ($token) $transactionFunc = function() use ($token)
{ {
if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET) if ($token->getPurpose() !== Token::PURPOSE_PASSWORD_RESET)
throw new \Exception('This token is not a password reset token.'); throw new \Exception('This token is not a password reset token.');
$user = $this->getByName($token->getAdditionalData()); $user = $this->getByName($token->getAdditionalData());
@ -182,21 +198,21 @@ class UserService
return $this->transactionManager->commit($transactionFunc); return $this->transactionManager->commit($transactionFunc);
} }
public function sendActivationEmail(\Szurubooru\Entities\User $user) public function sendActivationEmail(User $user)
{ {
$transactionFunc = function() use ($user) $transactionFunc = function() use ($user)
{ {
$token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_ACTIVATE); $token = $this->tokenService->createAndSaveToken($user->getName(), Token::PURPOSE_ACTIVATE);
$this->emailService->sendActivationEmail($user, $token); $this->emailService->sendActivationEmail($user, $token);
}; };
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
public function finishActivation(\Szurubooru\Entities\Token $token) public function finishActivation(Token $token)
{ {
$transactionFunc = function() use ($token) $transactionFunc = function() use ($token)
{ {
if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_ACTIVATE) if ($token->getPurpose() !== Token::PURPOSE_ACTIVATE)
throw new \Exception('This token is not an activation token.'); throw new \Exception('This token is not an activation token.');
$user = $this->getByName($token->getAdditionalData()); $user = $this->getByName($token->getAdditionalData());
@ -207,15 +223,15 @@ class UserService
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
private function updateUserAvatarStyle(\Szurubooru\Entities\User $user, $newAvatarStyle) private function updateUserAvatarStyle(User $user, $newAvatarStyle)
{ {
$user->setAvatarStyle($newAvatarStyle); $user->setAvatarStyle($newAvatarStyle);
} }
private function updateUserAvatarContent(\Szurubooru\Entities\User $user, $newAvatarContent) private function updateUserAvatarContent(User $user, $newAvatarContent)
{ {
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($newAvatarContent); $mime = MimeHelper::getMimeTypeFromBuffer($newAvatarContent);
if (!\Szurubooru\Helpers\MimeHelper::isImage($mime)) if (!MimeHelper::isImage($mime))
throw new \DomainException('Avatar must be an image.'); throw new \DomainException('Avatar must be an image.');
if (strlen($newAvatarContent) > $this->config->database->maxCustomThumbnailSize) if (strlen($newAvatarContent) > $this->config->database->maxCustomThumbnailSize)
@ -224,18 +240,18 @@ class UserService
$user->setCustomAvatarSourceContent($newAvatarContent); $user->setCustomAvatarSourceContent($newAvatarContent);
} }
private function updateUserName(\Szurubooru\Entities\User $user, $newName) private function updateUserName(User $user, $newName)
{ {
$this->assertNoUserWithThisName($user, $newName); $this->assertNoUserWithThisName($user, $newName);
$user->setName($newName); $user->setName($newName);
} }
private function updateUserPassword(\Szurubooru\Entities\User $user, $newPassword) private function updateUserPassword(User $user, $newPassword)
{ {
$user->setPasswordHash($this->passwordService->getHash($newPassword, $user->getPasswordSalt())); $user->setPasswordHash($this->passwordService->getHash($newPassword, $user->getPasswordSalt()));
} }
private function updateUserEmail(\Szurubooru\Entities\User $user, $newEmail) private function updateUserEmail(User $user, $newEmail)
{ {
if ($user->getEmail() === $newEmail) if ($user->getEmail() === $newEmail)
{ {
@ -249,17 +265,17 @@ class UserService
} }
} }
private function updateUserAccessRank(\Szurubooru\Entities\User $user, $newAccessRank) private function updateUserAccessRank(User $user, $newAccessRank)
{ {
$user->setAccessRank($newAccessRank); $user->setAccessRank($newAccessRank);
} }
private function updateUserBrowsingSettings(\Szurubooru\Entities\User $user, $newBrowsingSettings) private function updateUserBrowsingSettings(User $user, $newBrowsingSettings)
{ {
$user->setBrowsingSettings($newBrowsingSettings); $user->setBrowsingSettings($newBrowsingSettings);
} }
public function updateUserLastLoginTime(\Szurubooru\Entities\User $user) public function updateUserLastLoginTime(User $user)
{ {
$transactionFunc = function() use ($user) $transactionFunc = function() use ($user)
{ {
@ -269,9 +285,9 @@ class UserService
$this->transactionManager->commit($transactionFunc); $this->transactionManager->commit($transactionFunc);
} }
private function sendActivationEmailIfNeeded(\Szurubooru\Entities\User $user) private function sendActivationEmailIfNeeded(User $user)
{ {
if ($user->getAccessRank() === \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR if ($user->getAccessRank() === User::ACCESS_RANK_ADMINISTRATOR
or !$this->config->security->needEmailActivationToRegister) or !$this->config->security->needEmailActivationToRegister)
{ {
$user = $this->confirmUserEmail($user); $user = $this->confirmUserEmail($user);
@ -283,7 +299,7 @@ class UserService
return $user; return $user;
} }
private function confirmUserEmail(\Szurubooru\Entities\User $user) private function confirmUserEmail(User $user)
{ {
//security issue: //security issue:
//1. two users set their unconfirmed mail to godzilla@empire.gov //1. two users set their unconfirmed mail to godzilla@empire.gov
@ -301,14 +317,14 @@ class UserService
return $user; return $user;
} }
private function assertNoUserWithThisName(\Szurubooru\Entities\User $owner, $nameToCheck) private function assertNoUserWithThisName(User $owner, $nameToCheck)
{ {
$userWithThisName = $this->userDao->findByName($nameToCheck); $userWithThisName = $this->userDao->findByName($nameToCheck);
if ($userWithThisName and $userWithThisName->getId() !== $owner->getId()) if ($userWithThisName and $userWithThisName->getId() !== $owner->getId())
throw new \DomainException('User with this name already exists.'); throw new \DomainException('User with this name already exists.');
} }
private function assertNoUserWithThisEmail(\Szurubooru\Entities\User $owner, $emailToCheck) private function assertNoUserWithThisEmail(User $owner, $emailToCheck)
{ {
if (!$emailToCheck) if (!$emailToCheck)
return; return;

View file

@ -1,7 +1,8 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
interface IUpgrade interface IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection); public function run(DatabaseConnection $databaseConnection);
} }

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade01 implements IUpgrade class Upgrade01 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade02 implements IUpgrade class Upgrade02 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$databaseConnection->getPDO()->exec(' $databaseConnection->getPDO()->exec('
ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE'); ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade03 implements IUpgrade class Upgrade03 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,5 +1,11 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\Dao\PostDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Post;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\Services\FileService;
use Szurubooru\Services\PostService;
class Upgrade04 implements IUpgrade class Upgrade04 implements IUpgrade
{ {
@ -8,26 +14,26 @@ class Upgrade04 implements IUpgrade
private $fileService; private $fileService;
public function __construct( public function __construct(
\Szurubooru\Dao\PostDao $postDao, PostDao $postDao,
\Szurubooru\Services\PostService $postService, PostService $postService,
\Szurubooru\Services\FileService $fileService) FileService $fileService)
{ {
$this->postDao = $postDao; $this->postDao = $postDao;
$this->postService = $postService; $this->postService = $postService;
$this->fileService = $fileService; $this->fileService = $fileService;
} }
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL'); $databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL');
$posts = $this->postDao->findAll(); $posts = $this->postDao->findAll();
foreach ($posts as $post) foreach ($posts as $post)
{ {
if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE) if ($post->getContentType() !== Post::POST_TYPE_YOUTUBE)
{ {
$fullPath = $this->fileService->getFullPath($post->getContentPath()); $fullPath = $this->fileService->getFullPath($post->getContentPath());
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath); $mime = MimeHelper::getMimeTypeFromFile($fullPath);
$post->setContentMimeType($mime); $post->setContentMimeType($mime);
$this->postDao->save($post); $this->postDao->save($post);
} }

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade05 implements IUpgrade class Upgrade05 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade06 implements IUpgrade class Upgrade06 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade07 implements IUpgrade class Upgrade07 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade08 implements IUpgrade class Upgrade08 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,5 +1,8 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\Dao\PostDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Services\HistoryService;
class Upgrade09 implements IUpgrade class Upgrade09 implements IUpgrade
{ {
@ -7,14 +10,14 @@ class Upgrade09 implements IUpgrade
private $historyService; private $historyService;
public function __construct( public function __construct(
\Szurubooru\Dao\PostDao $postDao, PostDao $postDao,
\Szurubooru\Services\HistoryService $historyService) HistoryService $historyService)
{ {
$this->postDao = $postDao; $this->postDao = $postDao;
$this->historyService = $historyService; $this->historyService = $historyService;
} }
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade10 implements IUpgrade class Upgrade10 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade11 implements IUpgrade class Upgrade11 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,16 +1,18 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
use Szurubooru\Services\TagService;
class Upgrade12 implements IUpgrade class Upgrade12 implements IUpgrade
{ {
private $tagService; private $tagService;
public function __construct(\Szurubooru\Services\TagService $tagService) public function __construct(TagService $tagService)
{ {
$this->tagService = $tagService; $this->tagService = $tagService;
} }
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$this->tagService->exportJson(); $this->tagService->exportJson();
} }

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade13 implements IUpgrade class Upgrade13 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade14 implements IUpgrade class Upgrade14 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade15 implements IUpgrade class Upgrade15 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver(); $driver = $databaseConnection->getDriver();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade16 implements IUpgrade class Upgrade16 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();

View file

@ -1,9 +1,10 @@
<?php <?php
namespace Szurubooru\Upgrades; namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade17 implements IUpgrade class Upgrade17 implements IUpgrade
{ {
public function run(\Szurubooru\DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();

Some files were not shown because too many files have changed in this diff Show more