Added "use ..." statements
This version ditches backwards compatibility with PHP earlier than 5.6.
This commit is contained in:
parent
5bc73d220e
commit
632bac8661
140 changed files with 1673 additions and 1076 deletions
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers;
|
||||
use Szurubooru\Router;
|
||||
|
||||
abstract class AbstractController
|
||||
{
|
||||
abstract function registerRoutes(\Szurubooru\Router $router);
|
||||
abstract function registerRoutes(Router $router);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -12,13 +21,13 @@ final class AuthController extends AbstractController
|
|||
private $tokenViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\UserService $userService,
|
||||
\Szurubooru\Services\TokenService $tokenService,
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Helpers\InputReader $inputReader,
|
||||
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy,
|
||||
\Szurubooru\Controllers\ViewProxies\TokenViewProxy $tokenViewProxy)
|
||||
AuthService $authService,
|
||||
UserService $userService,
|
||||
TokenService $tokenService,
|
||||
PrivilegeService $privilegeService,
|
||||
InputReader $inputReader,
|
||||
UserViewProxy $userViewProxy,
|
||||
TokenViewProxy $tokenViewProxy)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
$this->userService = $userService;
|
||||
|
@ -29,7 +38,7 @@ final class AuthController extends AbstractController
|
|||
$this->tokenViewProxy = $tokenViewProxy;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->post('/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))
|
||||
{
|
||||
$formData = new \Szurubooru\FormData\LoginFormData($this->inputReader);
|
||||
$formData = new LoginFormData($this->inputReader);
|
||||
$this->authService->loginFromCredentials($formData);
|
||||
|
||||
$user = $this->authService->getLoggedInUser();
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -12,13 +26,13 @@ class CommentController extends AbstractController
|
|||
private $inputReader;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\Services\CommentService $commentService,
|
||||
\Szurubooru\Controllers\ViewProxies\CommentViewProxy $commentViewProxy,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy $postViewProxy,
|
||||
\Szurubooru\Helpers\InputReader $inputReader)
|
||||
PrivilegeService $privilegeService,
|
||||
AuthService $authService,
|
||||
PostService $postService,
|
||||
CommentService $commentService,
|
||||
CommentViewProxy $commentViewProxy,
|
||||
PostViewProxy $postViewProxy,
|
||||
InputReader $inputReader)
|
||||
{
|
||||
$this->privilegeService = $privilegeService;
|
||||
$this->authService = $authService;
|
||||
|
@ -29,7 +43,7 @@ class CommentController extends AbstractController
|
|||
$this->inputReader = $inputReader;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/comments', [$this, 'getComments']);
|
||||
$router->get('/api/comments/:postNameOrId', [$this, 'getPostComments']);
|
||||
|
@ -40,19 +54,19 @@ class CommentController extends AbstractController
|
|||
|
||||
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->setPageNumber($this->inputReader->page);
|
||||
$filter->setOrder([
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME =>
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::ORDER_DESC]);
|
||||
PostFilter::ORDER_LAST_COMMENT_TIME =>
|
||||
PostFilter::ORDER_DESC]);
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementRangedValue());
|
||||
$requirement = new Requirement();
|
||||
$requirement->setValue(new RequirementRangedValue());
|
||||
$requirement->getValue()->setMinValue(1);
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT);
|
||||
$requirement->setType(PostFilter::REQUIREMENT_COMMENT_COUNT);
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
$result = $this->postService->getFiltered($filter);
|
||||
|
@ -77,17 +91,17 @@ class CommentController extends AbstractController
|
|||
|
||||
public function getPostComments($postNameOrId)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_COMMENTS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::LIST_COMMENTS);
|
||||
$post = $this->postService->getByNameOrId($postNameOrId);
|
||||
|
||||
$filter = new \Szurubooru\SearchServices\Filters\CommentFilter();
|
||||
$filter = new CommentFilter();
|
||||
$filter->setOrder([
|
||||
\Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ID =>
|
||||
\Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ASC]);
|
||||
CommentFilter::ORDER_ID =>
|
||||
CommentFilter::ORDER_ASC]);
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId()));
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\CommentFilter::REQUIREMENT_POST_ID);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setValue(new RequirementSingleValue($post->getId()));
|
||||
$requirement->setType(CommentFilter::REQUIREMENT_POST_ID);
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
$result = $this->commentService->getFiltered($filter);
|
||||
|
@ -97,7 +111,7 @@ class CommentController extends AbstractController
|
|||
|
||||
public function addComment($postNameOrId)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::ADD_COMMENTS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::ADD_COMMENTS);
|
||||
|
||||
$post = $this->postService->getByNameOrId($postNameOrId);
|
||||
$comment = $this->commentService->createComment($post, $this->inputReader->text);
|
||||
|
@ -110,8 +124,8 @@ class CommentController extends AbstractController
|
|||
|
||||
$this->privilegeService->assertPrivilege(
|
||||
($comment->getUser() and $this->privilegeService->isLoggedIn($comment->getUser()))
|
||||
? \Szurubooru\Privilege::EDIT_OWN_COMMENTS
|
||||
: \Szurubooru\Privilege::EDIT_ALL_COMMENTS);
|
||||
? Privilege::EDIT_OWN_COMMENTS
|
||||
: Privilege::EDIT_ALL_COMMENTS);
|
||||
|
||||
$comment = $this->commentService->updateComment($comment, $this->inputReader->text);
|
||||
return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig());
|
||||
|
@ -123,8 +137,8 @@ class CommentController extends AbstractController
|
|||
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($comment->getUser())
|
||||
? \Szurubooru\Privilege::DELETE_OWN_COMMENTS
|
||||
: \Szurubooru\Privilege::DELETE_ALL_COMMENTS);
|
||||
? Privilege::DELETE_OWN_COMMENTS
|
||||
: Privilege::DELETE_ALL_COMMENTS);
|
||||
|
||||
return $this->commentService->deleteComment($comment);
|
||||
}
|
||||
|
@ -133,7 +147,7 @@ class CommentController extends AbstractController
|
|||
{
|
||||
return
|
||||
[
|
||||
\Szurubooru\Controllers\ViewProxies\CommentViewProxy::FETCH_OWN_SCORE => true,
|
||||
CommentViewProxy::FETCH_OWN_SCORE => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +16,11 @@ class FavoritesController extends AbstractController
|
|||
private $userViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\Services\FavoritesService $favoritesService,
|
||||
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy)
|
||||
PrivilegeService $privilegeService,
|
||||
AuthService $authService,
|
||||
PostService $postService,
|
||||
FavoritesService $favoritesService,
|
||||
UserViewProxy $userViewProxy)
|
||||
{
|
||||
$this->privilegeService = $privilegeService;
|
||||
$this->authService = $authService;
|
||||
|
@ -23,7 +29,7 @@ class FavoritesController extends AbstractController
|
|||
$this->userViewProxy = $userViewProxy;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/posts/:postNameOrId/favorites', [$this, 'getFavoriteUsers']);
|
||||
$router->post('/api/posts/:postNameOrId/favorites', [$this, 'addFavorite']);
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers;
|
||||
use Szurubooru\Dao\GlobalParamDao;
|
||||
use Szurubooru\Router;
|
||||
|
||||
final class GlobalParamController extends AbstractController
|
||||
{
|
||||
private $globalParamDao;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\GlobalParamDao $globalParamDao)
|
||||
public function __construct(GlobalParamDao $globalParamDao)
|
||||
{
|
||||
$this->globalParamDao = $globalParamDao;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/globals', [$this, 'getGlobals']);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +17,11 @@ final class HistoryController extends AbstractController
|
|||
private $snapshotViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\HistoryService $historyService,
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\SearchServices\Parsers\SnapshotSearchParser $snapshotSearchParser,
|
||||
\Szurubooru\Helpers\InputReader $inputReader,
|
||||
\Szurubooru\Controllers\ViewProxies\SnapshotViewProxy $snapshotViewProxy)
|
||||
HistoryService $historyService,
|
||||
PrivilegeService $privilegeService,
|
||||
SnapshotSearchParser $snapshotSearchParser,
|
||||
InputReader $inputReader,
|
||||
SnapshotViewProxy $snapshotViewProxy)
|
||||
{
|
||||
$this->historyService = $historyService;
|
||||
$this->privilegeService = $privilegeService;
|
||||
|
@ -23,14 +30,14 @@ final class HistoryController extends AbstractController
|
|||
$this->snapshotViewProxy = $snapshotViewProxy;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/history', [$this, 'getFiltered']);
|
||||
}
|
||||
|
||||
public function getFiltered()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY);
|
||||
$this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY);
|
||||
|
||||
$filter = $this->snapshotSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter->setPageSize(50);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -9,10 +14,10 @@ final class PostContentController extends AbstractController
|
|||
private $thumbnailService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Helpers\HttpHelper $httpHelper,
|
||||
\Szurubooru\Services\ThumbnailService $thumbnailService)
|
||||
PostService $postService,
|
||||
FileService $fileService,
|
||||
HttpHelper $httpHelper,
|
||||
ThumbnailService $thumbnailService)
|
||||
{
|
||||
$this->postService = $postService;
|
||||
$this->fileService = $fileService;
|
||||
|
@ -20,7 +25,7 @@ final class PostContentController extends AbstractController
|
|||
$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/thumbnail/:size', [$this, 'getPostThumbnail']);
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -13,14 +30,14 @@ final class PostController extends AbstractController
|
|||
private $snapshotViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\SearchServices\Parsers\PostSearchParser $postSearchParser,
|
||||
\Szurubooru\Helpers\InputReader $inputReader,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy $postViewProxy,
|
||||
\Szurubooru\Controllers\ViewProxies\SnapshotViewProxy $snapshotViewProxy)
|
||||
Config $config,
|
||||
AuthService $authService,
|
||||
PrivilegeService $privilegeService,
|
||||
PostService $postService,
|
||||
PostSearchParser $postSearchParser,
|
||||
InputReader $inputReader,
|
||||
PostViewProxy $postViewProxy,
|
||||
SnapshotViewProxy $snapshotViewProxy)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->authService = $authService;
|
||||
|
@ -32,7 +49,7 @@ final class PostController extends AbstractController
|
|||
$this->snapshotViewProxy = $snapshotViewProxy;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->post('/api/posts', [$this, 'createPost']);
|
||||
$router->get('/api/posts', [$this, 'getFiltered']);
|
||||
|
@ -47,7 +64,7 @@ final class PostController extends AbstractController
|
|||
public function getByNameOrId($postNameOrId)
|
||||
{
|
||||
if ($postNameOrId !== 'featured')
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_POSTS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS);
|
||||
|
||||
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
||||
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
|
||||
|
@ -55,14 +72,14 @@ final class PostController extends AbstractController
|
|||
|
||||
public function getHistory($postNameOrId)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY);
|
||||
$this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY);
|
||||
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
||||
return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))];
|
||||
}
|
||||
|
||||
public function getFiltered()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_POSTS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::LIST_POSTS);
|
||||
|
||||
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter->setPageSize($this->config->posts->postsPerPage);
|
||||
|
@ -78,13 +95,13 @@ final class PostController extends AbstractController
|
|||
|
||||
public function createPost()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS);
|
||||
$formData = new \Szurubooru\FormData\UploadFormData($this->inputReader);
|
||||
$this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS);
|
||||
$formData = new UploadFormData($this->inputReader);
|
||||
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS);
|
||||
|
||||
if ($formData->anonymous)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS_ANONYMOUSLY);
|
||||
$this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS_ANONYMOUSLY);
|
||||
|
||||
$post = $this->postService->createPost($formData);
|
||||
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
|
||||
|
@ -93,22 +110,22 @@ final class PostController extends AbstractController
|
|||
public function updatePost($postNameOrId)
|
||||
{
|
||||
$post = $this->postService->getByNameOrId($postNameOrId);
|
||||
$formData = new \Szurubooru\FormData\PostEditFormData($this->inputReader);
|
||||
$formData = new PostEditFormData($this->inputReader);
|
||||
|
||||
if ($formData->content !== null)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_CONTENT);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_CONTENT);
|
||||
|
||||
if ($formData->thumbnail !== null)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_THUMBNAIL);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_THUMBNAIL);
|
||||
|
||||
if ($formData->safety !== null)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SAFETY);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SAFETY);
|
||||
|
||||
if ($formData->source !== null)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SOURCE);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SOURCE);
|
||||
|
||||
if ($formData->tags !== null)
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_TAGS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_TAGS);
|
||||
|
||||
$this->postService->updatePost($post, $formData);
|
||||
$post = $this->postService->getByNameOrId($postNameOrId);
|
||||
|
@ -139,12 +156,12 @@ final class PostController extends AbstractController
|
|||
{
|
||||
return
|
||||
[
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_RELATIONS => true,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_USER => true,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_HISTORY => true,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_OWN_SCORE => true,
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_FAVORITES => true,
|
||||
PostViewProxy::FETCH_RELATIONS => true,
|
||||
PostViewProxy::FETCH_TAGS => true,
|
||||
PostViewProxy::FETCH_USER => true,
|
||||
PostViewProxy::FETCH_HISTORY => true,
|
||||
PostViewProxy::FETCH_OWN_SCORE => true,
|
||||
PostViewProxy::FETCH_FAVORITES => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -152,7 +169,7 @@ final class PostController extends AbstractController
|
|||
{
|
||||
return
|
||||
[
|
||||
\Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true,
|
||||
PostViewProxy::FETCH_TAGS => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -163,33 +180,33 @@ final class PostController extends AbstractController
|
|||
if (!$userSettings)
|
||||
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 = [];
|
||||
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->safe))
|
||||
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_SAFE;
|
||||
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->sketchy))
|
||||
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY;
|
||||
if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->unsafe))
|
||||
$values[] = \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->safe))
|
||||
$values[] = Post::POST_SAFETY_SAFE;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->sketchy))
|
||||
$values[] = Post::POST_SAFETY_SKETCHY;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->unsafe))
|
||||
$values[] = Post::POST_SAFETY_UNSAFE;
|
||||
if (count($values))
|
||||
{
|
||||
$requirementValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue();
|
||||
$requirementValue = new RequirementCompositeValue();
|
||||
$requirementValue->setValues($values);
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_SAFETY);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$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]);
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$filter->addRequirement($requirement);
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
<?php
|
||||
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 $authService;
|
||||
|
@ -11,12 +19,12 @@ class ScoreController extends AbstractController
|
|||
private $inputReader;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\Services\CommentService $commentService,
|
||||
\Szurubooru\Services\ScoreService $scoreService,
|
||||
\Szurubooru\Helpers\InputReader $inputReader)
|
||||
PrivilegeService $privilegeService,
|
||||
AuthService $authService,
|
||||
PostService $postService,
|
||||
CommentService $commentService,
|
||||
ScoreService $scoreService,
|
||||
InputReader $inputReader)
|
||||
{
|
||||
$this->privilegeService = $privilegeService;
|
||||
$this->authService = $authService;
|
||||
|
@ -26,7 +34,7 @@ class ScoreController extends AbstractController
|
|||
$this->inputReader = $inputReader;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/posts/:postNameOrId/score', [$this, 'getPostScore']);
|
||||
$router->post('/api/posts/:postNameOrId/score', [$this, 'setPostScore']);
|
||||
|
@ -58,7 +66,7 @@ class ScoreController extends AbstractController
|
|||
return $this->setScore($comment);
|
||||
}
|
||||
|
||||
private function setScore(\Szurubooru\Entities\Entity $entity)
|
||||
private function setScore(Entity $entity)
|
||||
{
|
||||
$this->privilegeService->assertLoggedIn();
|
||||
$score = intval($this->inputReader->score);
|
||||
|
@ -67,7 +75,7 @@ class ScoreController extends AbstractController
|
|||
return ['score' => $result->getScore()];
|
||||
}
|
||||
|
||||
private function getScore(\Szurubooru\Entities\Entity $entity)
|
||||
private function getScore(Entity $entity)
|
||||
{
|
||||
$this->privilegeService->assertLoggedIn();
|
||||
$user = $this->authService->getLoggedInUser();
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +17,11 @@ final class TagController extends AbstractController
|
|||
private $inputReader;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\TagService $tagService,
|
||||
\Szurubooru\Controllers\ViewProxies\TagViewProxy $tagViewProxy,
|
||||
\Szurubooru\SearchServices\Parsers\TagSearchParser $tagSearchParser,
|
||||
\Szurubooru\Helpers\InputReader $inputReader)
|
||||
PrivilegeService $privilegeService,
|
||||
TagService $tagService,
|
||||
TagViewProxy $tagViewProxy,
|
||||
TagSearchParser $tagSearchParser,
|
||||
InputReader $inputReader)
|
||||
{
|
||||
$this->privilegeService = $privilegeService;
|
||||
$this->tagService = $tagService;
|
||||
|
@ -23,14 +30,14 @@ final class TagController extends AbstractController
|
|||
$this->inputReader = $inputReader;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/tags', [$this, 'getTags']);
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_TAGS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
|
||||
|
||||
$filter = $this->tagSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter->setPageSize(50);
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -9,10 +15,10 @@ final class UserAvatarController extends AbstractController
|
|||
private $thumbnailService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\UserService $userService,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Helpers\HttpHelper $httpHelper,
|
||||
\Szurubooru\Services\ThumbnailService $thumbnailService)
|
||||
UserService $userService,
|
||||
FileService $fileService,
|
||||
HttpHelper $httpHelper,
|
||||
ThumbnailService $thumbnailService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
$this->fileService = $fileService;
|
||||
|
@ -20,7 +26,7 @@ final class UserAvatarController extends AbstractController
|
|||
$this->thumbnailService = $thumbnailService;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->get('/api/users/:userName/avatar/:size', [$this, 'getAvatarByName']);
|
||||
}
|
||||
|
@ -38,17 +44,17 @@ final class UserAvatarController extends AbstractController
|
|||
|
||||
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())));
|
||||
$url = 'https://www.gravatar.com/avatar/' . $hash . '?d=retro&s=' . $size;
|
||||
$this->serveFromUrl($url);
|
||||
break;
|
||||
|
||||
case \Szurubooru\Entities\User::AVATAR_STYLE_BLANK:
|
||||
case User::AVATAR_STYLE_BLANK:
|
||||
$this->serveBlankFile($size);
|
||||
break;
|
||||
|
||||
case \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL:
|
||||
case User::AVATAR_STYLE_MANUAL:
|
||||
$this->serveFromFile($user->getCustomAvatarSourceContentPath(), $size);
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -12,13 +23,13 @@ final class UserController extends AbstractController
|
|||
private $userViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\UserService $userService,
|
||||
\Szurubooru\Services\TokenService $tokenService,
|
||||
\Szurubooru\SearchServices\Parsers\UserSearchParser $userSearchParser,
|
||||
\Szurubooru\Helpers\InputReader $inputReader,
|
||||
\Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy)
|
||||
Config $config,
|
||||
PrivilegeService $privilegeService,
|
||||
UserService $userService,
|
||||
TokenService $tokenService,
|
||||
UserSearchParser $userSearchParser,
|
||||
InputReader $inputReader,
|
||||
UserViewProxy $userViewProxy)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->privilegeService = $privilegeService;
|
||||
|
@ -29,7 +40,7 @@ final class UserController extends AbstractController
|
|||
$this->userViewProxy = $userViewProxy;
|
||||
}
|
||||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
public function registerRoutes(Router $router)
|
||||
{
|
||||
$router->post('/api/users', [$this, 'createUser']);
|
||||
$router->get('/api/users', [$this, 'getFiltered']);
|
||||
|
@ -44,14 +55,14 @@ final class UserController extends AbstractController
|
|||
|
||||
public function getByNameOrEmail($userNameOrEmail)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_USERS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::VIEW_USERS);
|
||||
$user = $this->userService->getByNameOrEmail($userNameOrEmail);
|
||||
return $this->userViewProxy->fromEntity($user);
|
||||
}
|
||||
|
||||
public function getFiltered()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_USERS);
|
||||
$this->privilegeService->assertPrivilege(Privilege::LIST_USERS);
|
||||
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter->setPageSize($this->config->users->usersPerPage);
|
||||
|
@ -65,8 +76,8 @@ final class UserController extends AbstractController
|
|||
|
||||
public function createUser()
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::REGISTER);
|
||||
$formData = new \Szurubooru\FormData\RegistrationFormData($this->inputReader);
|
||||
$this->privilegeService->assertPrivilege(Privilege::REGISTER);
|
||||
$formData = new RegistrationFormData($this->inputReader);
|
||||
$user = $this->userService->createUser($formData);
|
||||
return $this->userViewProxy->fromEntity($user);
|
||||
}
|
||||
|
@ -74,43 +85,43 @@ final class UserController extends AbstractController
|
|||
public function updateUser($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)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($userNameOrEmail)
|
||||
? \Szurubooru\Privilege::CHANGE_OWN_AVATAR_STYLE
|
||||
: \Szurubooru\Privilege::CHANGE_ALL_AVATAR_STYLES);
|
||||
? Privilege::CHANGE_OWN_AVATAR_STYLE
|
||||
: Privilege::CHANGE_ALL_AVATAR_STYLES);
|
||||
}
|
||||
|
||||
if ($formData->userName !== null)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($userNameOrEmail)
|
||||
? \Szurubooru\Privilege::CHANGE_OWN_NAME
|
||||
: \Szurubooru\Privilege::CHANGE_ALL_NAMES);
|
||||
? Privilege::CHANGE_OWN_NAME
|
||||
: Privilege::CHANGE_ALL_NAMES);
|
||||
}
|
||||
|
||||
if ($formData->password !== null)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($userNameOrEmail)
|
||||
? \Szurubooru\Privilege::CHANGE_OWN_PASSWORD
|
||||
: \Szurubooru\Privilege::CHANGE_ALL_PASSWORDS);
|
||||
? Privilege::CHANGE_OWN_PASSWORD
|
||||
: Privilege::CHANGE_ALL_PASSWORDS);
|
||||
}
|
||||
|
||||
if ($formData->email !== null)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($userNameOrEmail)
|
||||
? \Szurubooru\Privilege::CHANGE_OWN_EMAIL_ADDRESS
|
||||
: \Szurubooru\Privilege::CHANGE_ALL_EMAIL_ADDRESSES);
|
||||
? Privilege::CHANGE_OWN_EMAIL_ADDRESS
|
||||
: Privilege::CHANGE_ALL_EMAIL_ADDRESSES);
|
||||
}
|
||||
|
||||
if ($formData->accessRank)
|
||||
{
|
||||
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_ACCESS_RANK);
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_ACCESS_RANK);
|
||||
}
|
||||
|
||||
if ($formData->browsingSettings)
|
||||
|
@ -126,8 +137,8 @@ final class UserController extends AbstractController
|
|||
{
|
||||
$this->privilegeService->assertPrivilege(
|
||||
$this->privilegeService->isLoggedIn($userNameOrEmail)
|
||||
? \Szurubooru\Privilege::DELETE_OWN_ACCOUNT
|
||||
: \Szurubooru\Privilege::DELETE_ACCOUNTS);
|
||||
? Privilege::DELETE_OWN_ACCOUNT
|
||||
: Privilege::DELETE_ACCOUNTS);
|
||||
|
||||
$user = $this->userService->getByNameOrEmail($userNameOrEmail);
|
||||
return $this->userService->deleteUser($user);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers\ViewProxies;
|
||||
use Szurubooru\Services\AuthService;
|
||||
use Szurubooru\Services\ScoreService;
|
||||
|
||||
class CommentViewProxy extends AbstractViewProxy
|
||||
{
|
||||
|
@ -10,8 +12,8 @@ class CommentViewProxy extends AbstractViewProxy
|
|||
const FETCH_OWN_SCORE = 'fetchOwnScore';
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\ScoreService $scoreService,
|
||||
AuthService $authService,
|
||||
ScoreService $scoreService,
|
||||
UserViewProxy $userViewProxy)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -20,11 +28,11 @@ class PostViewProxy extends AbstractViewProxy
|
|||
private $snapshotViewProxy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\HistoryService $historyService,
|
||||
\Szurubooru\Services\FavoritesService $favoritesService,
|
||||
\Szurubooru\Services\ScoreService $scoreService,
|
||||
PrivilegeService $privilegeService,
|
||||
AuthService $authService,
|
||||
HistoryService $historyService,
|
||||
FavoritesService $favoritesService,
|
||||
ScoreService $scoreService,
|
||||
TagViewProxy $tagViewProxy,
|
||||
UserViewProxy $userViewProxy,
|
||||
SnapshotViewProxy $snapshotViewProxy)
|
||||
|
@ -50,11 +58,11 @@ class PostViewProxy extends AbstractViewProxy
|
|||
$result->name = $post->getName();
|
||||
$result->uploadTime = $post->getUploadTime();
|
||||
$result->lastEditTime = $post->getLastEditTime();
|
||||
$result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety());
|
||||
$result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType());
|
||||
$result->safety = EnumHelper::postSafetyToString($post->getSafety());
|
||||
$result->contentType = EnumHelper::postTypeToString($post->getContentType());
|
||||
$result->contentChecksum = $post->getContentChecksum();
|
||||
$result->contentMimeType = $post->getContentMimeType();
|
||||
$result->contentExtension = \Szurubooru\Helpers\MimeHelper::getExtension($post->getContentMimeType());
|
||||
$result->contentExtension = MimeHelper::getExtension($post->getContentMimeType());
|
||||
$result->source = $post->getSource();
|
||||
$result->imageWidth = $post->getImageWidth();
|
||||
$result->imageHeight = $post->getImageHeight();
|
||||
|
@ -76,7 +84,7 @@ class PostViewProxy extends AbstractViewProxy
|
|||
|
||||
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));
|
||||
else
|
||||
$result->history = [];
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers\ViewProxies;
|
||||
use Szurubooru\Helpers\EnumHelper;
|
||||
use Szurubooru\Privilege;
|
||||
use Szurubooru\Services\PrivilegeService;
|
||||
|
||||
class UserViewProxy extends AbstractViewProxy
|
||||
{
|
||||
private $privilegeService;
|
||||
|
||||
public function __construct(\Szurubooru\Services\PrivilegeService $privilegeService)
|
||||
public function __construct(PrivilegeService $privilegeService)
|
||||
{
|
||||
$this->privilegeService = $privilegeService;
|
||||
}
|
||||
|
@ -17,10 +20,10 @@ class UserViewProxy extends AbstractViewProxy
|
|||
{
|
||||
$result->id = $user->getId();
|
||||
$result->name = $user->getName();
|
||||
$result->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankToString($user->getAccessRank());
|
||||
$result->accessRank = EnumHelper::accessRankToString($user->getAccessRank());
|
||||
$result->registrationTime = $user->getRegistrationTime();
|
||||
$result->lastLoginTime = $user->getLastLoginTime();
|
||||
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
||||
$result->avatarStyle = EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
||||
$result->banned = $user->isBanned();
|
||||
|
||||
if ($this->privilegeService->isLoggedIn($user))
|
||||
|
@ -28,7 +31,7 @@ class UserViewProxy extends AbstractViewProxy
|
|||
$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))
|
||||
{
|
||||
$result->email = $user->getEmail();
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,9 +19,9 @@ abstract class AbstractDao implements ICrudDao
|
|||
protected $driver;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
DatabaseConnection $databaseConnection,
|
||||
$tableName,
|
||||
\Szurubooru\Dao\EntityConverters\IEntityConverter $entityConverter)
|
||||
IEntityConverter $entityConverter)
|
||||
{
|
||||
$this->setDatabaseConnection($databaseConnection);
|
||||
$this->tableName = $tableName;
|
||||
|
@ -70,7 +79,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
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();
|
||||
|
||||
|
@ -90,7 +99,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
$this->decorateQueryFromFilter($query, $searchFilter);
|
||||
$totalRecords = count($query);
|
||||
|
||||
$searchResult = new \Szurubooru\SearchServices\Result();
|
||||
$searchResult = new Result();
|
||||
$searchResult->setSearchFilter($searchFilter);
|
||||
$searchResult->setEntities($entities);
|
||||
$searchResult->setTotalRecords($totalRecords);
|
||||
|
@ -113,14 +122,14 @@ abstract class AbstractDao implements ICrudDao
|
|||
return $this->deleteBy($this->getIdColumn(), $entityId);
|
||||
}
|
||||
|
||||
protected function update(\Szurubooru\Entities\Entity $entity)
|
||||
protected function update(Entity $entity)
|
||||
{
|
||||
$arrayEntity = $this->entityConverter->toArray($entity);
|
||||
$this->fpdo->update($this->tableName)->set($arrayEntity)->where($this->getIdColumn(), $entity->getId())->execute();
|
||||
return $entity;
|
||||
}
|
||||
|
||||
protected function create(\Szurubooru\Entities\Entity $entity)
|
||||
protected function create(Entity $entity)
|
||||
{
|
||||
$arrayEntity = $this->entityConverter->toArray($entity);
|
||||
$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();
|
||||
}
|
||||
|
||||
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();
|
||||
$sqlColumn = $requirement->getType();
|
||||
|
||||
if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementCompositeValue)
|
||||
if ($value instanceof RequirementCompositeValue)
|
||||
{
|
||||
$sql = $sqlColumn;
|
||||
$bindings = [$value->getValues()];
|
||||
|
@ -194,7 +203,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
$sql = 'NOT ' . $sql;
|
||||
}
|
||||
|
||||
else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementRangedValue)
|
||||
else if ($value instanceof RequirementRangedValue)
|
||||
{
|
||||
if ($value->getMinValue() and $value->getMaxValue())
|
||||
{
|
||||
|
@ -218,7 +227,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
$sql = 'NOT (' . $sql . ')';
|
||||
}
|
||||
|
||||
else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementSingleValue)
|
||||
else if ($value instanceof RequirementSingleValue)
|
||||
{
|
||||
$sql = $sqlColumn;
|
||||
$bindings = [$value->getValue()];
|
||||
|
@ -230,7 +239,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
else
|
||||
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)
|
||||
|
@ -244,14 +253,14 @@ abstract class AbstractDao implements ICrudDao
|
|||
return $entities;
|
||||
}
|
||||
|
||||
private function setDatabaseConnection(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
private function setDatabaseConnection(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$this->pdo = $databaseConnection->getPDO();
|
||||
$this->fpdo = new \FluentPDO($this->pdo);
|
||||
$this->driver = $databaseConnection->getDriver();
|
||||
}
|
||||
|
||||
private function decorateQueryFromFilter($query, \Szurubooru\SearchServices\Filters\IFilter $filter)
|
||||
private function decorateQueryFromFilter($query, IFilter $filter)
|
||||
{
|
||||
foreach ($filter->getRequirements() as $requirement)
|
||||
{
|
||||
|
@ -264,7 +273,7 @@ abstract class AbstractDao implements ICrudDao
|
|||
$orderByString = '';
|
||||
foreach ($order as $orderColumn => $orderDir)
|
||||
{
|
||||
if ($orderColumn === \Szurubooru\SearchServices\Filters\BasicFilter::ORDER_RANDOM)
|
||||
if ($orderColumn === IFilter::ORDER_RANDOM)
|
||||
{
|
||||
$driver = $this->driver;
|
||||
if ($driver === 'sqlite')
|
||||
|
@ -276,12 +285,12 @@ abstract class AbstractDao implements ICrudDao
|
|||
$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);
|
||||
}
|
||||
|
||||
private function upsert(\Szurubooru\Entities\Entity $entity)
|
||||
private function upsert(Entity $entity)
|
||||
{
|
||||
if ($entity->getId())
|
||||
{
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -7,36 +14,36 @@ class CommentDao extends AbstractDao implements ICrudDao
|
|||
private $postDao;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Dao\UserDao $userDao,
|
||||
\Szurubooru\Dao\PostDao $postDao)
|
||||
DatabaseConnection $databaseConnection,
|
||||
UserDao $userDao,
|
||||
PostDao $postDao)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'comments',
|
||||
new \Szurubooru\Dao\EntityConverters\CommentEntityConverter());
|
||||
new CommentEntityConverter());
|
||||
|
||||
$this->userDao = $userDao;
|
||||
$this->postDao = $postDao;
|
||||
}
|
||||
|
||||
public function findByPost(\Szurubooru\Entities\Post $post)
|
||||
public function findByPost(Post $post)
|
||||
{
|
||||
return $this->findBy('postId', $post->getId());
|
||||
}
|
||||
|
||||
protected function afterLoad(\Szurubooru\Entities\Entity $comment)
|
||||
protected function afterLoad(Entity $comment)
|
||||
{
|
||||
$comment->setLazyLoader(
|
||||
\Szurubooru\Entities\Comment::LAZY_LOADER_USER,
|
||||
function (\Szurubooru\Entities\Comment $comment)
|
||||
Comment::LAZY_LOADER_USER,
|
||||
function (Comment $comment)
|
||||
{
|
||||
return $this->userDao->findById($comment->getUserId());
|
||||
});
|
||||
|
||||
$comment->setLazyLoader(
|
||||
\Szurubooru\Entities\Comment::LAZY_LOADER_POST,
|
||||
function (\Szurubooru\Entities\Comment $comment)
|
||||
Comment::LAZY_LOADER_POST,
|
||||
function (Comment $comment)
|
||||
{
|
||||
return $this->postDao->findById($comment->getPostId());
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ abstract class AbstractEntityConverter implements IEntityConverter
|
|||
{
|
||||
private $entityDecorator = null;
|
||||
|
||||
public function setEntityDecorator($entityDecorator)
|
||||
public function setEntityDecorator(callable $entityDecorator)
|
||||
{
|
||||
$this->entityDecorator = $entityDecorator;
|
||||
}
|
||||
|
@ -13,8 +13,9 @@ abstract class AbstractEntityConverter implements IEntityConverter
|
|||
public function toEntity(array $array)
|
||||
{
|
||||
$entity = $this->toBasicEntity($array);
|
||||
if ($this->entityDecorator !== null)
|
||||
call_user_func($this->entityDecorator, $entity);
|
||||
$func = $this->entityDecorator;
|
||||
if ($func !== null)
|
||||
$func($entity);
|
||||
return $entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Comment;
|
||||
use Szurubooru\Entities\Entity;
|
||||
|
||||
class CommentEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -18,13 +20,13 @@ class CommentEntityConverter extends AbstractEntityConverter implements IEntityC
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Comment($array['id']);
|
||||
$entity = new Comment($array['id']);
|
||||
$entity->setUserId($array['userId']);
|
||||
$entity->setPostId($array['postId']);
|
||||
$entity->setText($array['text']);
|
||||
$entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime']));
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Favorite;
|
||||
|
||||
class FavoriteEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -16,7 +18,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Favorite($array['id']);
|
||||
$entity = new Favorite($array['id']);
|
||||
$entity->setUserId($array['userId']);
|
||||
$entity->setPostId($array['postId']);
|
||||
$entity->setTime($this->dbTimeToEntityTime($array['time']));
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\GlobalParam;
|
||||
|
||||
class GlobalParamEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -15,7 +17,7 @@ class GlobalParamEntityConverter extends AbstractEntityConverter implements IEnt
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\GlobalParam($array['id']);
|
||||
$entity = new GlobalParam($array['id']);
|
||||
$entity->setKey($array['dataKey']);
|
||||
$entity->setValue($array['dataValue']);
|
||||
return $entity;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
|
||||
interface IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity);
|
||||
public function toArray(Entity $entity);
|
||||
|
||||
public function toEntity(array $array);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Post;
|
||||
|
||||
class PostEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -28,7 +30,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Post(intval($array['id']));
|
||||
$entity = new Post(intval($array['id']));
|
||||
$entity->setName($array['name']);
|
||||
$entity->setUserId($array['userId']);
|
||||
$entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime']));
|
||||
|
@ -44,10 +46,10 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
|||
$entity->setOriginalFileName($array['originalFileName']);
|
||||
$entity->setFeatureCount(intval($array['featureCount']));
|
||||
$entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime']));
|
||||
$entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount']));
|
||||
$entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount']));
|
||||
$entity->setMeta(\Szurubooru\Entities\Post::META_COMMENT_COUNT, intval($array['commentCount']));
|
||||
$entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score']));
|
||||
$entity->setMeta(Post::META_TAG_COUNT, intval($array['tagCount']));
|
||||
$entity->setMeta(Post::META_FAV_COUNT, intval($array['favCount']));
|
||||
$entity->setMeta(Post::META_COMMENT_COUNT, intval($array['commentCount']));
|
||||
$entity->setMeta(Post::META_SCORE, intval($array['score']));
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Score;
|
||||
|
||||
class ScoreEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -18,7 +20,7 @@ class ScoreEntityConverter extends AbstractEntityConverter implements IEntityCon
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Score($array['id']);
|
||||
$entity = new Score($array['id']);
|
||||
$entity->setUserId($array['userId']);
|
||||
$entity->setPostId($array['postId']);
|
||||
$entity->setCommentId($array['commentId']);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Snapshot;
|
||||
|
||||
class SnapshotEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -20,7 +22,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
|
|||
|
||||
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->setType(intval($array['type']));
|
||||
$entity->setPrimaryKey($array['primaryKey']);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Tag;
|
||||
|
||||
class TagEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -15,10 +17,10 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Tag($array['id']);
|
||||
$entity = new Tag($array['id']);
|
||||
$entity->setName($array['name']);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\Token;
|
||||
|
||||
class TokenEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -16,7 +18,7 @@ class TokenEntityConverter extends AbstractEntityConverter implements IEntityCon
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\Token(intval($array['id']));
|
||||
$entity = new Token(intval($array['id']));
|
||||
$entity->setName($array['name']);
|
||||
$entity->setPurpose($array['purpose']);
|
||||
$entity->setAdditionalData($array['additionalData']);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao\EntityConverters;
|
||||
use Szurubooru\Entities\Entity;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
class UserEntityConverter extends AbstractEntityConverter implements IEntityConverter
|
||||
{
|
||||
public function toArray(\Szurubooru\Entities\Entity $entity)
|
||||
public function toArray(Entity $entity)
|
||||
{
|
||||
return
|
||||
[
|
||||
|
@ -25,7 +27,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
|||
|
||||
public function toBasicEntity(array $array)
|
||||
{
|
||||
$entity = new \Szurubooru\Entities\User(intval($array['id']));
|
||||
$entity = new User(intval($array['id']));
|
||||
$entity->setName($array['name']);
|
||||
$entity->setEmail($array['email']);
|
||||
$entity->setEmailUnconfirmed($array['emailUnconfirmed']);
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Services\TimeService $timeService)
|
||||
DatabaseConnection $databaseConnection,
|
||||
TimeService $timeService)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'favorites',
|
||||
new \Szurubooru\Dao\EntityConverters\FavoriteEntityConverter());
|
||||
new FavoriteEntityConverter());
|
||||
|
||||
$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());
|
||||
else
|
||||
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);
|
||||
if (!$favorite)
|
||||
{
|
||||
$favorite = new \Szurubooru\Entities\Favorite();
|
||||
$favorite = new Favorite();
|
||||
$favorite->setTime($this->timeService->getCurrentTime());
|
||||
$favorite->setUserId($user->getId());
|
||||
|
||||
if ($entity instanceof \Szurubooru\Entities\Post)
|
||||
if ($entity instanceof Post)
|
||||
$favorite->setPostId($entity->getId());
|
||||
else
|
||||
throw new \InvalidArgumentException();
|
||||
|
@ -44,18 +51,18 @@ class FavoritesDao extends AbstractDao implements ICrudDao
|
|||
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);
|
||||
if ($favorite)
|
||||
$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());
|
||||
|
||||
if ($entity instanceof \Szurubooru\Entities\Post)
|
||||
if ($entity instanceof Post)
|
||||
$query->where('postId', $entity->getId());
|
||||
else
|
||||
throw new \InvalidArgumentException();
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao;
|
||||
use Szurubooru\Dao\EntityConverters\GlobalParamEntityConverter;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class GlobalParamDao extends AbstractDao implements ICrudDao
|
||||
{
|
||||
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function __construct(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'globals',
|
||||
new \Szurubooru\Dao\EntityConverters\GlobalParamEntityConverter());
|
||||
new GlobalParamEntityConverter());
|
||||
}
|
||||
|
||||
public function save(&$entity)
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -9,16 +19,16 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
private $thumbnailService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Dao\TagDao $tagDao,
|
||||
\Szurubooru\Dao\UserDao $userDao,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Services\ThumbnailService $thumbnailService)
|
||||
DatabaseConnection $databaseConnection,
|
||||
TagDao $tagDao,
|
||||
UserDao $userDao,
|
||||
FileService $fileService,
|
||||
ThumbnailService $thumbnailService)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'posts',
|
||||
new \Szurubooru\Dao\EntityConverters\PostEntityConverter());
|
||||
new PostEntityConverter());
|
||||
|
||||
$this->tagDao = $tagDao;
|
||||
$this->userDao = $userDao;
|
||||
|
@ -47,45 +57,45 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
return $this->findOneBy('contentChecksum', $checksum);
|
||||
}
|
||||
|
||||
protected function afterLoad(\Szurubooru\Entities\Entity $post)
|
||||
protected function afterLoad(Entity $post)
|
||||
{
|
||||
$post->setLazyLoader(
|
||||
\Szurubooru\Entities\Post::LAZY_LOADER_CONTENT,
|
||||
function (\Szurubooru\Entities\Post $post)
|
||||
Post::LAZY_LOADER_CONTENT,
|
||||
function (Post $post)
|
||||
{
|
||||
return $this->fileService->load($post->getContentPath());
|
||||
});
|
||||
|
||||
$post->setLazyLoader(
|
||||
\Szurubooru\Entities\Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT,
|
||||
function (\Szurubooru\Entities\Post $post)
|
||||
Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT,
|
||||
function (Post $post)
|
||||
{
|
||||
return $this->fileService->load($post->getThumbnailSourceContentPath());
|
||||
});
|
||||
|
||||
$post->setLazyLoader(
|
||||
\Szurubooru\Entities\Post::LAZY_LOADER_USER,
|
||||
function (\Szurubooru\Entities\Post $post)
|
||||
Post::LAZY_LOADER_USER,
|
||||
function (Post $post)
|
||||
{
|
||||
return $this->getUser($post);
|
||||
});
|
||||
|
||||
$post->setLazyLoader(
|
||||
\Szurubooru\Entities\Post::LAZY_LOADER_TAGS,
|
||||
function (\Szurubooru\Entities\Post $post)
|
||||
Post::LAZY_LOADER_TAGS,
|
||||
function (Post $post)
|
||||
{
|
||||
return $this->getTags($post);
|
||||
});
|
||||
|
||||
$post->setLazyLoader(
|
||||
\Szurubooru\Entities\Post::LAZY_LOADER_RELATED_POSTS,
|
||||
function (\Szurubooru\Entities\Post $post)
|
||||
Post::LAZY_LOADER_RELATED_POSTS,
|
||||
function (Post $post)
|
||||
{
|
||||
return $this->getRelatedPosts($post);
|
||||
});
|
||||
}
|
||||
|
||||
protected function afterSave(\Szurubooru\Entities\Entity $post)
|
||||
protected function afterSave(Entity $post)
|
||||
{
|
||||
$this->syncContent($post);
|
||||
$this->syncThumbnailSourceContent($post);
|
||||
|
@ -93,9 +103,9 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
$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 (
|
||||
SELECT 1 FROM postTags
|
||||
|
@ -110,24 +120,24 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
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('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('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');
|
||||
}
|
||||
|
||||
elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE)
|
||||
elseif ($requirement->getType() === PostFilter::REQUIREMENT_USER_SCORE)
|
||||
{
|
||||
$values = $requirement->getValue()->getValues();
|
||||
$userName = $values[0];
|
||||
|
@ -147,17 +157,17 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
parent::decorateQueryFromRequirement($query, $requirement);
|
||||
}
|
||||
|
||||
private function getTags(\Szurubooru\Entities\Post $post)
|
||||
private function getTags(Post $post)
|
||||
{
|
||||
return $this->tagDao->findByPostId($post->getId());
|
||||
}
|
||||
|
||||
private function getUser(\Szurubooru\Entities\Post $post)
|
||||
private function getUser(Post $post)
|
||||
{
|
||||
return $this->userDao->findById($post->getUserId());
|
||||
}
|
||||
|
||||
private function getRelatedPosts(\Szurubooru\Entities\Post $post)
|
||||
private function getRelatedPosts(Post $post)
|
||||
{
|
||||
$query = $this->fpdo
|
||||
->from('postRelations')
|
||||
|
@ -179,7 +189,7 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
return $this->findByIds($relatedPostIds);
|
||||
}
|
||||
|
||||
private function syncContent(\Szurubooru\Entities\Post $post)
|
||||
private function syncContent(Post $post)
|
||||
{
|
||||
$targetPath = $post->getContentPath();
|
||||
$content = $post->getContent();
|
||||
|
@ -190,7 +200,7 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||
}
|
||||
|
||||
private function syncThumbnailSourceContent(\Szurubooru\Entities\Post $post)
|
||||
private function syncThumbnailSourceContent(Post $post)
|
||||
{
|
||||
$targetPath = $post->getThumbnailSourceContentPath();
|
||||
$content = $post->getThumbnailSourceContent();
|
||||
|
@ -201,7 +211,7 @@ class PostDao extends AbstractDao implements ICrudDao
|
|||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||
}
|
||||
|
||||
private function syncTags(\Szurubooru\Entities\Post $post)
|
||||
private function syncTags(Post $post)
|
||||
{
|
||||
$tagIds = array_map(
|
||||
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('post2id', $post->getId())->execute();
|
||||
|
|
|
@ -1,29 +1,37 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Services\TimeService $timeService)
|
||||
DatabaseConnection $databaseConnection,
|
||||
TimeService $timeService)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'scores',
|
||||
new \Szurubooru\Dao\EntityConverters\ScoreEntityConverter());
|
||||
new ScoreEntityConverter());
|
||||
|
||||
$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());
|
||||
|
||||
if ($entity instanceof \Szurubooru\Entities\Post)
|
||||
if ($entity instanceof Post)
|
||||
$query->where('postId', $entity->getId());
|
||||
elseif ($entity instanceof \Szurubooru\Entities\Comment)
|
||||
elseif ($entity instanceof Comment)
|
||||
$query->where('commentId', $entity->getId());
|
||||
else
|
||||
throw new \InvalidArgumentException();
|
||||
|
@ -33,18 +41,18 @@ class ScoreDao extends AbstractDao implements ICrudDao
|
|||
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);
|
||||
if (!$score)
|
||||
{
|
||||
$score = new \Szurubooru\Entities\Score();
|
||||
$score = new Score();
|
||||
$score->setTime($this->timeService->getCurrentTime());
|
||||
$score->setUserId($user->getId());
|
||||
|
||||
if ($entity instanceof \Szurubooru\Entities\Post)
|
||||
if ($entity instanceof Post)
|
||||
$score->setPostId($entity->getId());
|
||||
elseif ($entity instanceof \Szurubooru\Entities\Comment)
|
||||
elseif ($entity instanceof Comment)
|
||||
$score->setCommentId($entity->getId());
|
||||
else
|
||||
throw new \InvalidArgumentException();
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
private $userDao;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Dao\UserDao $userDao)
|
||||
DatabaseConnection $databaseConnection,
|
||||
UserDao $userDao)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'snapshots',
|
||||
new \Szurubooru\Dao\EntityConverters\SnapshotEntityConverter());
|
||||
new SnapshotEntityConverter());
|
||||
|
||||
$this->userDao = $userDao;
|
||||
}
|
||||
|
@ -27,17 +32,17 @@ class SnapshotDao extends AbstractDao
|
|||
return $this->arrayToEntities(iterator_to_array($query));
|
||||
}
|
||||
|
||||
public function afterLoad(\Szurubooru\Entities\Entity $snapshot)
|
||||
public function afterLoad(Entity $snapshot)
|
||||
{
|
||||
$snapshot->setLazyLoader(
|
||||
\Szurubooru\Entities\Snapshot::LAZY_LOADER_USER,
|
||||
function (\Szurubooru\Entities\Snapshot $snapshot)
|
||||
Snapshot::LAZY_LOADER_USER,
|
||||
function (Snapshot $snapshot)
|
||||
{
|
||||
return $this->getUser($snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
private function getUser(\Szurubooru\Entities\Snapshot $snapshot)
|
||||
private function getUser(Snapshot $snapshot)
|
||||
{
|
||||
$userId = $snapshot->getUserId();
|
||||
return $this->userDao->findById($userId);
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao;
|
||||
use Szurubooru\Dao\EntityConverters\TagEntityConverter;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class TagDao extends AbstractDao implements ICrudDao
|
||||
{
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function __construct(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'tags',
|
||||
new \Szurubooru\Dao\EntityConverters\TagEntityConverter());
|
||||
new TagEntityConverter());
|
||||
}
|
||||
|
||||
public function findByNames($tagNames)
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao;
|
||||
use Szurubooru\Dao\EntityConverters\TokenEntityConverter;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class TokenDao extends AbstractDao
|
||||
{
|
||||
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function __construct(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'tokens',
|
||||
new \Szurubooru\Dao\EntityConverters\TokenEntityConverter());
|
||||
new TokenEntityConverter());
|
||||
}
|
||||
|
||||
public function findByName($tokenName)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
namespace Szurubooru\Dao;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class TransactionManager
|
||||
{
|
||||
private $databaseConnection;
|
||||
|
||||
public function __construct(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function __construct(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,14 +16,14 @@ class UserDao extends AbstractDao implements ICrudDao
|
|||
private $thumbnailService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Services\ThumbnailService $thumbnailService)
|
||||
DatabaseConnection $databaseConnection,
|
||||
FileService $fileService,
|
||||
ThumbnailService $thumbnailService)
|
||||
{
|
||||
parent::__construct(
|
||||
$databaseConnection,
|
||||
'users',
|
||||
new \Szurubooru\Dao\EntityConverters\UserEntityConverter());
|
||||
new UserEntityConverter());
|
||||
|
||||
$this->fileService = $fileService;
|
||||
$this->thumbnailService = $thumbnailService;
|
||||
|
@ -49,18 +55,18 @@ class UserDao extends AbstractDao implements ICrudDao
|
|||
$this->fpdo->deleteFrom('tokens')->where('additionalData', $userName);
|
||||
}
|
||||
|
||||
protected function afterLoad(\Szurubooru\Entities\Entity $user)
|
||||
protected function afterLoad(Entity $user)
|
||||
{
|
||||
$user->setLazyLoader(
|
||||
\Szurubooru\Entities\User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT,
|
||||
function(\Szurubooru\Entities\User $user)
|
||||
User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT,
|
||||
function(User $user)
|
||||
{
|
||||
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
||||
return $this->fileService->load($avatarSource);
|
||||
});
|
||||
}
|
||||
|
||||
protected function afterSave(\Szurubooru\Entities\Entity $user)
|
||||
protected function afterSave(Entity $user)
|
||||
{
|
||||
$targetPath = $user->getCustomAvatarSourceContentPath();
|
||||
$content = $user->getCustomAvatarSourceContent();
|
||||
|
@ -71,7 +77,7 @@ class UserDao extends AbstractDao implements ICrudDao
|
|||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||
}
|
||||
|
||||
protected function afterDelete(\Szurubooru\Entities\Entity $user)
|
||||
protected function afterDelete(Entity $user)
|
||||
{
|
||||
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
||||
$this->fileService->delete($avatarSource);
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
namespace Szurubooru;
|
||||
use Szurubooru\Config;
|
||||
|
||||
class DatabaseConnection
|
||||
{
|
||||
private $pdo;
|
||||
private $config;
|
||||
|
||||
public function __construct(\Szurubooru\Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,13 +18,13 @@ final class Dispatcher
|
|||
private $tokenService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Router $router,
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Helpers\HttpHelper $httpHelper,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\TokenService $tokenService,
|
||||
\Szurubooru\ControllerRepository $controllerRepository)
|
||||
Router $router,
|
||||
Config $config,
|
||||
DatabaseConnection $databaseConnection,
|
||||
HttpHelper $httpHelper,
|
||||
AuthService $authService,
|
||||
TokenService $tokenService,
|
||||
ControllerRepository $controllerRepository)
|
||||
{
|
||||
$this->router = $router;
|
||||
$this->config = $config;
|
||||
|
@ -52,7 +60,7 @@ final class Dispatcher
|
|||
];
|
||||
}
|
||||
$end = microtime(true);
|
||||
$json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime();
|
||||
$json['__time'] = $end - Bootstrap::getStartTime();
|
||||
if ($this->config->misc->dumpSqlIntoQueries)
|
||||
{
|
||||
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
namespace Szurubooru\Entities;
|
||||
use Szurubooru\Entities\Post;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
final class Comment extends Entity
|
||||
{
|
||||
|
@ -69,7 +71,7 @@ final class Comment extends Entity
|
|||
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->userId = $user ? $user->getId() : null;
|
||||
|
@ -80,7 +82,7 @@ final class Comment extends Entity
|
|||
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->postId = $post->getId();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
namespace Szurubooru\Entities;
|
||||
use Szurubooru\Entities\Post;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
final class Favorite extends Entity
|
||||
{
|
||||
|
@ -45,7 +47,7 @@ final class Favorite extends Entity
|
|||
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->userId = $user->getId();
|
||||
|
@ -56,7 +58,7 @@ final class Favorite extends Entity
|
|||
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->postId = $post->getId();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Entities;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
final class Post extends Entity
|
||||
{
|
||||
|
@ -220,7 +221,7 @@ final class Post extends Entity
|
|||
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->userId = $user ? $user->getId() : null;
|
||||
|
|
|
@ -4,10 +4,10 @@ namespace Szurubooru\Entities;
|
|||
final class Score extends Entity
|
||||
{
|
||||
private $postId;
|
||||
private $userId;
|
||||
private $commentId;
|
||||
private $time;
|
||||
private $score;
|
||||
private $time;
|
||||
private $userId;
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Entities;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
final class Snapshot extends Entity
|
||||
{
|
||||
|
@ -93,7 +94,7 @@ final class Snapshot extends Entity
|
|||
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->userId = $user ? $user->getId() : null;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\FormData;
|
||||
use Szurubooru\IValidatable;
|
||||
use Szurubooru\Validator;
|
||||
|
||||
class LoginFormData implements \Szurubooru\IValidatable
|
||||
class LoginFormData implements IValidatable
|
||||
{
|
||||
public $userNameOrEmail;
|
||||
public $password;
|
||||
|
@ -15,7 +17,7 @@ class LoginFormData implements \Szurubooru\IValidatable
|
|||
}
|
||||
}
|
||||
|
||||
public function validate(\Szurubooru\Validator $validator)
|
||||
public function validate(Validator $validator)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
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 $thumbnail;
|
||||
|
@ -18,7 +21,7 @@ class PostEditFormData implements \Szurubooru\IValidatable
|
|||
{
|
||||
$this->content = $inputReader->decodeBase64($inputReader->content);
|
||||
$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->tags = preg_split('/[\s+]/', $inputReader->tags);
|
||||
$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);
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\FormData;
|
||||
use Szurubooru\IValidatable;
|
||||
use Szurubooru\Validator;
|
||||
|
||||
class RegistrationFormData implements \Szurubooru\IValidatable
|
||||
class RegistrationFormData implements IValidatable
|
||||
{
|
||||
public $userName;
|
||||
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->validatePassword($this->password);
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
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 $content;
|
||||
|
@ -19,13 +22,13 @@ class UploadFormData implements \Szurubooru\IValidatable
|
|||
$this->content = $inputReader->decodeBase64($inputReader->content);
|
||||
$this->url = $inputReader->url;
|
||||
$this->anonymous = $inputReader->anonymous;
|
||||
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety);
|
||||
$this->safety = EnumHelper::postSafetyFromString($inputReader->safety);
|
||||
$this->source = $inputReader->source;
|
||||
$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)
|
||||
throw new \DomainException('Neither data or URL provided.');
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<?php
|
||||
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 $email;
|
||||
|
@ -20,16 +24,16 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
|||
$this->email = $inputReader->email;
|
||||
$this->password = $inputReader->password;
|
||||
if ($inputReader->accessRank !== null)
|
||||
$this->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankFromString($inputReader->accessRank);
|
||||
$this->accessRank = EnumHelper::accessRankFromString($inputReader->accessRank);
|
||||
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->browsingSettings = json_decode($inputReader->browsingSettings);
|
||||
$this->banned = boolval($inputReader->banned);
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(\Szurubooru\Validator $validator)
|
||||
public function validate(Validator $validator)
|
||||
{
|
||||
if ($this->userName !== null)
|
||||
$validator->validateUserName($this->userName);
|
||||
|
@ -45,8 +49,8 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
|||
|
||||
if ($this->avatarContent)
|
||||
{
|
||||
$avatarContentMimeType = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($this->avatarContent);
|
||||
if (!\Szurubooru\Helpers\MimeHelper::isImage($avatarContentMimeType))
|
||||
$avatarContentMimeType = MimeHelper::getMimeTypeFromBuffer($this->avatarContent);
|
||||
if (!MimeHelper::isImage($avatarContentMimeType))
|
||||
throw new \DomainException('Avatar must be an image (detected: ' . $avatarContentMimeType . ').');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,43 +1,46 @@
|
|||
<?php
|
||||
namespace Szurubooru\Helpers;
|
||||
use Szurubooru\Entities\Post;
|
||||
use Szurubooru\Entities\Snapshot;
|
||||
use Szurubooru\Entities\User;
|
||||
|
||||
class EnumHelper
|
||||
{
|
||||
private static $accessRankMap =
|
||||
[
|
||||
'anonymous' => \Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS,
|
||||
'regularUser' => \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER,
|
||||
'powerUser' => \Szurubooru\Entities\User::ACCESS_RANK_POWER_USER,
|
||||
'moderator' => \Szurubooru\Entities\User::ACCESS_RANK_MODERATOR,
|
||||
'administrator' => \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR,
|
||||
'anonymous' => User::ACCESS_RANK_ANONYMOUS,
|
||||
'regularUser' => User::ACCESS_RANK_REGULAR_USER,
|
||||
'powerUser' => User::ACCESS_RANK_POWER_USER,
|
||||
'moderator' => User::ACCESS_RANK_MODERATOR,
|
||||
'administrator' => User::ACCESS_RANK_ADMINISTRATOR,
|
||||
];
|
||||
|
||||
private static $avatarStyleMap =
|
||||
[
|
||||
'gravatar' => \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR,
|
||||
'manual' => \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL,
|
||||
'none' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK,
|
||||
'blank' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK,
|
||||
'gravatar' => User::AVATAR_STYLE_GRAVATAR,
|
||||
'manual' => User::AVATAR_STYLE_MANUAL,
|
||||
'none' => User::AVATAR_STYLE_BLANK,
|
||||
'blank' => User::AVATAR_STYLE_BLANK,
|
||||
];
|
||||
|
||||
private static $postSafetyMap =
|
||||
[
|
||||
'safe' => \Szurubooru\Entities\Post::POST_SAFETY_SAFE,
|
||||
'sketchy' => \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY,
|
||||
'unsafe' => \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE,
|
||||
'safe' => Post::POST_SAFETY_SAFE,
|
||||
'sketchy' => Post::POST_SAFETY_SKETCHY,
|
||||
'unsafe' => Post::POST_SAFETY_UNSAFE,
|
||||
];
|
||||
|
||||
private static $postTypeMap =
|
||||
[
|
||||
'image' => \Szurubooru\Entities\Post::POST_TYPE_IMAGE,
|
||||
'video' => \Szurubooru\Entities\Post::POST_TYPE_VIDEO,
|
||||
'flash' => \Szurubooru\Entities\Post::POST_TYPE_FLASH,
|
||||
'youtube' => \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE,
|
||||
'image' => Post::POST_TYPE_IMAGE,
|
||||
'video' => Post::POST_TYPE_VIDEO,
|
||||
'flash' => Post::POST_TYPE_FLASH,
|
||||
'youtube' => Post::POST_TYPE_YOUTUBE,
|
||||
];
|
||||
|
||||
private static $snapshotTypeMap =
|
||||
[
|
||||
'post' => \Szurubooru\Entities\Snapshot::TYPE_POST,
|
||||
'post' => Snapshot::TYPE_POST,
|
||||
];
|
||||
|
||||
public static function accessRankToString($accessRank)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
namespace Szurubooru;
|
||||
use Szurubooru\Validator;
|
||||
|
||||
interface IValidatable
|
||||
{
|
||||
public function validate(\Szurubooru\Validator $validator);
|
||||
public function validate(Validator $validator);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
namespace Szurubooru;
|
||||
use DI\ContainerBuilder;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
|
||||
final class Injector
|
||||
{
|
||||
|
@ -12,8 +14,8 @@ final class Injector
|
|||
. DIRECTORY_SEPARATOR . 'src'
|
||||
. DIRECTORY_SEPARATOR . 'di.php';
|
||||
|
||||
$builder = new \DI\ContainerBuilder();
|
||||
$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->setDefinitionCache(new ArrayCache());
|
||||
$builder->addDefinitions($definitionsPath);
|
||||
self::$container = $builder->build();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ final class Route
|
|||
public $query;
|
||||
public $route;
|
||||
|
||||
public function __construct($query, $route)
|
||||
public function __construct($query, callable $route)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->route = $route;
|
||||
|
@ -19,7 +19,8 @@ final class Route
|
|||
if (!preg_match($this->regex, $query, $matches))
|
||||
return false;
|
||||
$routeArguments = $this->getRouteArguments($matches);
|
||||
$output = call_user_func_array($this->route, $routeArguments);
|
||||
$func = $this->route;
|
||||
$output = $func(...array_values($routeArguments));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,27 +5,27 @@ class Router
|
|||
{
|
||||
private $routes;
|
||||
|
||||
public function get($query, $route)
|
||||
public function get($query, callable $route)
|
||||
{
|
||||
$this->route('GET', $query, $route);
|
||||
}
|
||||
|
||||
public function put($query, $route)
|
||||
public function put($query, callable $route)
|
||||
{
|
||||
$this->route('PUT', $query, $route);
|
||||
}
|
||||
|
||||
public function delete($query, $route)
|
||||
public function delete($query, callable $route)
|
||||
{
|
||||
$this->route('DELETE', $query, $route);
|
||||
}
|
||||
|
||||
public function post($query, $route)
|
||||
public function post($query, callable $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);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\SearchServices\Filters;
|
||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||
|
||||
class BasicFilter implements IFilter
|
||||
{
|
||||
const ORDER_RANDOM = 'random';
|
||||
|
||||
private $order = [];
|
||||
private $requirements = [];
|
||||
private $pageNumber;
|
||||
|
@ -20,7 +19,7 @@ class BasicFilter implements IFilter
|
|||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function addRequirement(\Szurubooru\SearchServices\Requirements\Requirement $requirement)
|
||||
public function addRequirement(Requirement $requirement)
|
||||
{
|
||||
$this->requirements[] = $requirement;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
namespace Szurubooru\SearchServices\Filters;
|
||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||
|
||||
interface IFilter
|
||||
{
|
||||
const ORDER_RANDOM = 'random';
|
||||
|
||||
const ORDER_ASC = 1;
|
||||
const ORDER_DESC = -1;
|
||||
|
||||
|
@ -12,7 +15,7 @@ interface IFilter
|
|||
|
||||
public function getRequirements();
|
||||
|
||||
public function addRequirement(\Szurubooru\SearchServices\Requirements\Requirement $requirement);
|
||||
public function addRequirement(Requirement $requirement);
|
||||
|
||||
public function getPageSize();
|
||||
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
const ALLOW_COMPOSITE = 1;
|
||||
const ALLOW_RANGES = 2;
|
||||
|
||||
public function createFilterFromInputReader(\Szurubooru\Helpers\InputReader $inputReader)
|
||||
public function createFilterFromInputReader(InputReader $inputReader)
|
||||
{
|
||||
$filter = $this->createFilter();
|
||||
$filter->setOrder($this->getOrder($inputReader->order) + $filter->getOrder());
|
||||
|
@ -21,14 +29,14 @@ abstract class AbstractSearchParser
|
|||
|
||||
foreach ($tokens as $token)
|
||||
{
|
||||
if ($token instanceof \Szurubooru\SearchServices\Tokens\NamedSearchToken)
|
||||
if ($token instanceof NamedSearchToken)
|
||||
{
|
||||
if ($token->getKey() === 'order')
|
||||
$filter->setOrder($this->getOrder($token->getValue()) + $filter->getOrder());
|
||||
else
|
||||
$this->decorateFilterFromNamedToken($filter, $token);
|
||||
}
|
||||
elseif ($token instanceof \Szurubooru\SearchServices\Tokens\SearchToken)
|
||||
elseif ($token instanceof SearchToken)
|
||||
$this->decorateFilterFromToken($filter, $token);
|
||||
else
|
||||
throw new \RuntimeException('Invalid search token type: ' . get_class($token));
|
||||
|
@ -39,13 +47,13 @@ abstract class AbstractSearchParser
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -60,7 +68,7 @@ abstract class AbstractSearchParser
|
|||
list ($minValue, $maxValue) = explode('..', $text);
|
||||
$minValue = $valueDecorator($minValue);
|
||||
$maxValue = $valueDecorator($maxValue);
|
||||
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementRangedValue();
|
||||
$tokenValue = new RequirementRangedValue();
|
||||
$tokenValue->setMinValue($minValue);
|
||||
$tokenValue->setMaxValue($maxValue);
|
||||
return $tokenValue;
|
||||
|
@ -69,18 +77,18 @@ abstract class AbstractSearchParser
|
|||
{
|
||||
$values = explode(',', $text);
|
||||
$values = array_map($valueDecorator, $values);
|
||||
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue();
|
||||
$tokenValue = new RequirementCompositeValue();
|
||||
$tokenValue->setValues($values);
|
||||
return $tokenValue;
|
||||
}
|
||||
|
||||
$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->setValue($this->createRequirementValue($token->getValue(), $flags, $valueDecorator));
|
||||
$requirement->setNegated($token->isNegated());
|
||||
|
@ -99,14 +107,14 @@ abstract class AbstractSearchParser
|
|||
|
||||
if (count($token) === 1)
|
||||
{
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC;
|
||||
$orderDir = IFilter::ORDER_DESC;
|
||||
}
|
||||
elseif (count($token) === 2)
|
||||
{
|
||||
if ($token[1] === 'desc')
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC;
|
||||
$orderDir = IFilter::ORDER_DESC;
|
||||
elseif ($token[1] === 'asc')
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC;
|
||||
$orderDir = IFilter::ORDER_ASC;
|
||||
else
|
||||
throw new \Exception('Wrong search order direction');
|
||||
}
|
||||
|
@ -139,14 +147,14 @@ abstract class AbstractSearchParser
|
|||
$colonPosition = strpos($tokenText, ':');
|
||||
if (($colonPosition !== false) and ($colonPosition > 0))
|
||||
{
|
||||
$searchToken = new \Szurubooru\SearchServices\Tokens\NamedSearchToken();
|
||||
$searchToken = new NamedSearchToken();
|
||||
list ($tokenKey, $tokenValue) = explode(':', $tokenText, 2);
|
||||
$searchToken->setKey($tokenKey);
|
||||
$searchToken->setValue($tokenValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
$searchToken = new \Szurubooru\SearchServices\Tokens\SearchToken();
|
||||
$searchToken = new SearchToken();
|
||||
$searchToken->setValue($tokenText);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -7,8 +17,8 @@ class PostSearchParser extends AbstractSearchParser
|
|||
private $privilegeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\PrivilegeService $privilegeService)
|
||||
AuthService $authService,
|
||||
PrivilegeService $privilegeService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
$this->privilegeService = $privilegeService;
|
||||
|
@ -16,19 +26,19 @@ class PostSearchParser extends AbstractSearchParser
|
|||
|
||||
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->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_TAG);
|
||||
$requirement->setValue($this->createRequirementValue($token->getValue()));
|
||||
$requirement->setNegated($token->isNegated());
|
||||
$filter->addRequirement($requirement);
|
||||
}
|
||||
|
||||
protected function decorateFilterFromNamedToken($filter, $token)
|
||||
protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $token)
|
||||
{
|
||||
if ($token->getKey() === 'id')
|
||||
$this->addIdRequirement($filter, $token);
|
||||
|
@ -81,53 +91,53 @@ class PostSearchParser extends AbstractSearchParser
|
|||
elseif ($token->getKey() === 'special' and $token->getValue() === 'fav')
|
||||
{
|
||||
$this->privilegeService->assertLoggedIn();
|
||||
$token = new \Szurubooru\SearchServices\Tokens\NamedSearchToken();
|
||||
$token = new NamedSearchToken();
|
||||
$token->setKey('fav');
|
||||
$token->setValue($this->authService->getLoggedInUser()->getName());
|
||||
$this->decorateFilterFromNamedToken($filter, $token);
|
||||
}
|
||||
|
||||
else
|
||||
throw new \Szurubooru\NotSupportedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected function getOrderColumn($token)
|
||||
protected function getOrderColumn($tokenText)
|
||||
{
|
||||
if ($token === 'id')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_ID;
|
||||
if ($tokenText === 'id')
|
||||
return PostFilter::ORDER_ID;
|
||||
|
||||
elseif ($token === 'fav_time')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME;
|
||||
elseif ($tokenText === 'fav_time')
|
||||
return PostFilter::ORDER_FAV_TIME;
|
||||
|
||||
elseif ($token === 'fav_count')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_COUNT;
|
||||
elseif ($tokenText === 'fav_count')
|
||||
return PostFilter::ORDER_FAV_COUNT;
|
||||
|
||||
elseif ($token === 'tag_count')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_TAG_COUNT;
|
||||
elseif ($tokenText === 'tag_count')
|
||||
return PostFilter::ORDER_TAG_COUNT;
|
||||
|
||||
elseif ($token === 'time')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_EDIT_TIME;
|
||||
elseif ($tokenText === 'time')
|
||||
return PostFilter::ORDER_LAST_EDIT_TIME;
|
||||
|
||||
elseif ($token === 'score')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_SCORE;
|
||||
elseif ($tokenText === 'score')
|
||||
return PostFilter::ORDER_SCORE;
|
||||
|
||||
elseif ($token === 'file_size')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FILE_SIZE;
|
||||
elseif ($tokenText === 'file_size')
|
||||
return PostFilter::ORDER_FILE_SIZE;
|
||||
|
||||
elseif ($token === 'random')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_RANDOM;
|
||||
elseif ($tokenText === 'random')
|
||||
return PostFilter::ORDER_RANDOM;
|
||||
|
||||
elseif ($token === 'feature_time')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FEATURE_TIME;
|
||||
elseif ($tokenText === 'feature_time')
|
||||
return PostFilter::ORDER_LAST_FEATURE_TIME;
|
||||
|
||||
elseif ($token === 'comment_time')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME;
|
||||
elseif ($tokenText === 'comment_time')
|
||||
return PostFilter::ORDER_LAST_COMMENT_TIME;
|
||||
|
||||
elseif ($token === 'fav_time')
|
||||
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FAV_TIME;
|
||||
elseif ($tokenText === 'fav_time')
|
||||
return PostFilter::ORDER_LAST_FAV_TIME;
|
||||
|
||||
else
|
||||
throw new \Szurubooru\NotSupportedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private function addIdRequirement($filter, $token)
|
||||
|
@ -135,7 +145,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID,
|
||||
PostFilter::REQUIREMENT_ID,
|
||||
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -144,7 +154,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH,
|
||||
PostFilter::REQUIREMENT_HASH,
|
||||
self::ALLOW_COMPOSITE);
|
||||
}
|
||||
|
||||
|
@ -173,7 +183,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE,
|
||||
PostFilter::REQUIREMENT_DATE,
|
||||
self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -182,7 +192,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT,
|
||||
PostFilter::REQUIREMENT_TAG_COUNT,
|
||||
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -191,7 +201,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT,
|
||||
PostFilter::REQUIREMENT_FAV_COUNT,
|
||||
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -200,7 +210,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT,
|
||||
PostFilter::REQUIREMENT_COMMENT_COUNT,
|
||||
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -209,7 +219,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SCORE,
|
||||
PostFilter::REQUIREMENT_SCORE,
|
||||
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||
}
|
||||
|
||||
|
@ -218,7 +228,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER,
|
||||
PostFilter::REQUIREMENT_UPLOADER,
|
||||
self::ALLOW_COMPOSITE);
|
||||
}
|
||||
|
||||
|
@ -227,11 +237,11 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY,
|
||||
PostFilter::REQUIREMENT_SAFETY,
|
||||
self::ALLOW_COMPOSITE,
|
||||
function ($value)
|
||||
{
|
||||
return \Szurubooru\Helpers\EnumHelper::postSafetyFromString($value);
|
||||
return EnumHelper::postSafetyFromString($value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -240,7 +250,7 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE,
|
||||
PostFilter::REQUIREMENT_FAVORITE,
|
||||
self::ALLOW_COMPOSITE);
|
||||
}
|
||||
|
||||
|
@ -249,11 +259,11 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TYPE,
|
||||
PostFilter::REQUIREMENT_TYPE,
|
||||
self::ALLOW_COMPOSITE,
|
||||
function ($value)
|
||||
{
|
||||
return \Szurubooru\Helpers\EnumHelper::postTypeFromSTring($value);
|
||||
return EnumHelper::postTypeFromString($value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -262,16 +272,16 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$this->addRequirementFromToken(
|
||||
$filter,
|
||||
$token,
|
||||
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT,
|
||||
PostFilter::REQUIREMENT_COMMENT,
|
||||
self::ALLOW_COMPOSITE);
|
||||
}
|
||||
|
||||
private function addUserScoreRequirement($filter, $userName, $score, $isNegated)
|
||||
{
|
||||
$tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue();
|
||||
$tokenValue = new RequirementCompositeValue();
|
||||
$tokenValue->setValues([$userName, $score]);
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement->setValue($tokenValue);
|
||||
$requirement->setNegated($isNegated);
|
||||
$filter->addRequirement($requirement);
|
||||
|
|
|
@ -1,41 +1,48 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
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)
|
||||
throw new \BadMethodCallException('Not supported');
|
||||
throw new NotSupportedException();
|
||||
|
||||
if ($token->isNegated())
|
||||
throw new \BadMethodCallException('Not supported');
|
||||
throw new NotSupportedException();
|
||||
|
||||
list ($type, $primaryKey) = explode(',', $token->getValue());
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement->setValue($this->createRequirementValue($primaryKey));
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue($this->createRequirementValue(\Szurubooru\Helpers\EnumHelper::snapshotTypeFromString($type)));
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue($this->createRequirementValue(EnumHelper::snapshotTypeFromString($type)));
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +1,43 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
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')
|
||||
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_ID;
|
||||
if ($tokenText === 'id')
|
||||
return TagFilter::ORDER_ID;
|
||||
|
||||
elseif ($token === 'name')
|
||||
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_NAME;
|
||||
elseif ($tokenText === 'name')
|
||||
return TagFilter::ORDER_NAME;
|
||||
|
||||
elseif ($token === 'creation_time')
|
||||
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_CREATION_TIME;
|
||||
elseif ($tokenText === 'creation_time')
|
||||
return TagFilter::ORDER_CREATION_TIME;
|
||||
|
||||
elseif ($token === 'usage_count')
|
||||
return \Szurubooru\SearchServices\Filters\TagFilter::ORDER_USAGE_COUNT;
|
||||
elseif ($tokenText === 'usage_count')
|
||||
return TagFilter::ORDER_USAGE_COUNT;
|
||||
|
||||
else
|
||||
throw new \Szurubooru\NotSupportedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,37 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
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')
|
||||
return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME;
|
||||
if ($tokenText === 'name')
|
||||
return UserFilter::ORDER_NAME;
|
||||
|
||||
elseif ($token === 'registration_time')
|
||||
return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME;
|
||||
elseif ($tokenText === 'registration_time')
|
||||
return UserFilter::ORDER_REGISTRATION_TIME;
|
||||
|
||||
else
|
||||
throw new \Szurubooru\NotSupportedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\SearchServices;
|
||||
use Szurubooru\SearchServices\Filters\IFilter;
|
||||
|
||||
class Result
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ class Result
|
|||
public $entities;
|
||||
public $totalRecords;
|
||||
|
||||
public function setSearchFilter(Filters\IFilter $searchFilter = null)
|
||||
public function setSearchFilter(IFilter $searchFilter = null)
|
||||
{
|
||||
$this->searchFilter = $searchFilter;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -13,11 +20,11 @@ class AuthService
|
|||
private $tokenService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Services\PasswordService $passwordService,
|
||||
\Szurubooru\Services\TimeService $timeService,
|
||||
\Szurubooru\Services\TokenService $tokenService,
|
||||
\Szurubooru\Services\UserService $userService)
|
||||
Config $config,
|
||||
PasswordService $passwordService,
|
||||
TimeService $timeService,
|
||||
TokenService $tokenService,
|
||||
UserService $userService)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->passwordService = $passwordService;
|
||||
|
@ -60,9 +67,9 @@ class AuthService
|
|||
$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.');
|
||||
|
||||
$user = $this->userService->getById($token->getAdditionalData());
|
||||
|
@ -74,10 +81,10 @@ class AuthService
|
|||
|
||||
public function getAnonymousUser()
|
||||
{
|
||||
$user = new \Szurubooru\Entities\User();
|
||||
$user = new User();
|
||||
$user->setName('Anonymous user');
|
||||
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS);
|
||||
$user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_BLANK);
|
||||
$user->setAccessRank(User::ACCESS_RANK_ANONYMOUS);
|
||||
$user->setAvatarStyle(User::AVATAR_STYLE_BLANK);
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
@ -96,9 +103,9 @@ class AuthService
|
|||
$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)
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +18,11 @@ class CommentService
|
|||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Validator $validator,
|
||||
\Szurubooru\Dao\CommentDao $commentDao,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\TimeService $timeService)
|
||||
Validator $validator,
|
||||
CommentDao $commentDao,
|
||||
TransactionManager $transactionManager,
|
||||
AuthService $authService,
|
||||
TimeService $timeService)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
$this->commentDao = $commentDao;
|
||||
|
@ -35,7 +43,7 @@ class CommentService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getByPost(\Szurubooru\Entities\Post $post)
|
||||
public function getByPost(Post $post)
|
||||
{
|
||||
$transactionFunc = function() use ($post)
|
||||
{
|
||||
|
@ -44,7 +52,7 @@ class CommentService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getFiltered(\Szurubooru\SearchServices\Filters\CommentFilter $filter)
|
||||
public function getFiltered(CommentFilter $filter)
|
||||
{
|
||||
$transactionFunc = function() use ($filter)
|
||||
{
|
||||
|
@ -53,11 +61,11 @@ class CommentService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function createComment(\Szurubooru\Entities\Post $post, $text)
|
||||
public function createComment(Post $post, $text)
|
||||
{
|
||||
$transactionFunc = function() use ($post, $text)
|
||||
{
|
||||
$comment = new \Szurubooru\Entities\Comment();
|
||||
$comment = new Comment();
|
||||
$comment->setCreationTime($this->timeService->getCurrentTime());
|
||||
$comment->setLastEditTime($this->timeService->getCurrentTime());
|
||||
$comment->setUser($this->authService->isLoggedIn() ? $this->authService->getLoggedInUser() : null);
|
||||
|
@ -70,7 +78,7 @@ class CommentService
|
|||
return $this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function updateComment(\Szurubooru\Entities\Comment $comment, $newText)
|
||||
public function updateComment(Comment $comment, $newText)
|
||||
{
|
||||
$transactionFunc = function() use ($comment, $newText)
|
||||
{
|
||||
|
@ -82,7 +90,7 @@ class CommentService
|
|||
return $this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function deleteComment(\Szurubooru\Entities\Comment $comment)
|
||||
public function deleteComment(Comment $comment)
|
||||
{
|
||||
$transactionFunc = function() use ($comment)
|
||||
{
|
||||
|
@ -91,7 +99,7 @@ class CommentService
|
|||
$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');
|
||||
$comment->setText($text);
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use \Szurubooru\Config;
|
||||
use \Szurubooru\Entities\Token;
|
||||
use \Szurubooru\Entities\User;
|
||||
|
||||
class EmailService
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct(\Szurubooru\Config $config)
|
||||
public function __construct(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())
|
||||
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);
|
||||
}
|
||||
|
||||
public function sendActivationEmail(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Token $token)
|
||||
public function sendActivationEmail(User $user, Token $token)
|
||||
{
|
||||
if (!$user->getEmailUnconfirmed())
|
||||
throw new \BadMethodCallException('An e-mail address is needed to activate the account.');
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +17,11 @@ class FavoritesService
|
|||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\FavoritesDao $favoritesDao,
|
||||
\Szurubooru\Dao\ScoreDao $scoreDao,
|
||||
\Szurubooru\Dao\UserDao $userDao,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Services\TimeService $timeService)
|
||||
FavoritesDao $favoritesDao,
|
||||
ScoreDao $scoreDao,
|
||||
UserDao $userDao,
|
||||
TransactionManager $transactionManager,
|
||||
TimeService $timeService)
|
||||
{
|
||||
$this->favoritesDao = $favoritesDao;
|
||||
$this->scoreDao = $scoreDao;
|
||||
|
@ -23,7 +30,7 @@ class FavoritesService
|
|||
$this->timeService = $timeService;
|
||||
}
|
||||
|
||||
public function getFavoriteUsers(\Szurubooru\Entities\Entity $entity)
|
||||
public function getFavoriteUsers(Entity $entity)
|
||||
{
|
||||
$transactionFunc = function() use ($entity)
|
||||
{
|
||||
|
@ -38,7 +45,7 @@ class FavoritesService
|
|||
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)
|
||||
{
|
||||
|
@ -49,7 +56,7 @@ class FavoritesService
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\Helpers\HttpHelper;
|
||||
|
||||
class FileService
|
||||
{
|
||||
private $dataDirectory;
|
||||
private $httpHelper;
|
||||
|
||||
public function __construct(\Szurubooru\Config $config, \Szurubooru\Helpers\HttpHelper $httpHelper)
|
||||
public function __construct(Config $config, HttpHelper $httpHelper)
|
||||
{
|
||||
$this->dataDirectory = $config->getPublicDataDirectory();
|
||||
$this->httpHelper = $httpHelper;
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -11,12 +24,12 @@ class HistoryService
|
|||
private $transactionManager;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Validator $validator,
|
||||
\Szurubooru\Dao\SnapshotDao $snapshotDao,
|
||||
\Szurubooru\Dao\GlobalParamDao $globalParamDao,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Services\TimeService $timeService,
|
||||
\Szurubooru\Services\AuthService $authService)
|
||||
Validator $validator,
|
||||
SnapshotDao $snapshotDao,
|
||||
GlobalParamDao $globalParamDao,
|
||||
TransactionManager $transactionManager,
|
||||
TimeService $timeService,
|
||||
AuthService $authService)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
$this->snapshotDao = $snapshotDao;
|
||||
|
@ -26,7 +39,7 @@ class HistoryService
|
|||
$this->transactionManager = $transactionManager;
|
||||
}
|
||||
|
||||
public function getFiltered(\Szurubooru\SearchServices\Filters\SnapshotFilter $filter)
|
||||
public function getFiltered(SnapshotFilter $filter)
|
||||
{
|
||||
$transactionFunc = function() use ($filter)
|
||||
{
|
||||
|
@ -35,24 +48,24 @@ class HistoryService
|
|||
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->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId()));
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement->setValue(new RequirementSingleValue($post->getId()));
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST));
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST));
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
return $this->getFiltered($filter)->getEntities();
|
||||
}
|
||||
|
||||
public function saveSnapshot(\Szurubooru\Entities\Snapshot $snapshot)
|
||||
public function saveSnapshot(Snapshot $snapshot)
|
||||
{
|
||||
$transactionFunc = function() use ($snapshot)
|
||||
{
|
||||
|
@ -79,23 +92,23 @@ class HistoryService
|
|||
return $this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function getPostDeleteSnapshot(\Szurubooru\Entities\Post $post)
|
||||
public function getPostDeleteSnapshot(Post $post)
|
||||
{
|
||||
$snapshot = $this->getPostSnapshot($post);
|
||||
$snapshot->setData([]);
|
||||
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_DELETE);
|
||||
$snapshot->setOperation(Snapshot::OPERATION_DELETE);
|
||||
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());
|
||||
|
||||
$data =
|
||||
[
|
||||
'source' => $post->getSource(),
|
||||
'safety' => \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()),
|
||||
'safety' => EnumHelper::postSafetyToString($post->getSafety()),
|
||||
'contentChecksum' => $post->getContentChecksum(),
|
||||
'featured' => $isFeatured,
|
||||
|
||||
|
@ -118,7 +131,7 @@ class HistoryService
|
|||
];
|
||||
|
||||
$snapshot = $this->getPostSnapshot($post);
|
||||
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE);
|
||||
$snapshot->setOperation(Snapshot::OPERATION_CHANGE);
|
||||
$snapshot->setData($data);
|
||||
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->setType(\Szurubooru\Entities\Snapshot::TYPE_POST);
|
||||
$snapshot = new Snapshot();
|
||||
$snapshot->setType(Snapshot::TYPE_POST);
|
||||
$snapshot->setPrimaryKey($post->getId());
|
||||
return $snapshot;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ImageManipulation;
|
||||
use Szurubooru\Services\ImageManipulation\GdImageManipulator;
|
||||
use Szurubooru\Services\ImageManipulation\ImagickImageManipulator;
|
||||
|
||||
class ImageManipulator implements IImageManipulator
|
||||
{
|
||||
private $strategy;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Services\ImageManipulation\ImagickImageManipulator $imagickImageManipulator,
|
||||
\Szurubooru\Services\ImageManipulation\GdImageManipulator $gdImageManipulator)
|
||||
ImagickImageManipulator $imagickImageManipulator,
|
||||
GdImageManipulator $gdImageManipulator)
|
||||
{
|
||||
if (extension_loaded('imagick'))
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
|
||||
class PasswordService
|
||||
{
|
||||
|
@ -7,7 +8,7 @@ class PasswordService
|
|||
private $alphabet;
|
||||
private $pattern;
|
||||
|
||||
public function __construct(\Szurubooru\Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->alphabet =
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -16,17 +37,17 @@ class PostService
|
|||
private $imageManipulator;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Validator $validator,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Dao\PostDao $postDao,
|
||||
\Szurubooru\Dao\GlobalParamDao $globalParamDao,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
\Szurubooru\Services\TimeService $timeService,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Services\TagService $tagService,
|
||||
\Szurubooru\Services\HistoryService $historyService,
|
||||
\Szurubooru\Services\ImageManipulation\ImageManipulator $imageManipulator)
|
||||
Config $config,
|
||||
Validator $validator,
|
||||
TransactionManager $transactionManager,
|
||||
PostDao $postDao,
|
||||
GlobalParamDao $globalParamDao,
|
||||
AuthService $authService,
|
||||
TimeService $timeService,
|
||||
FileService $fileService,
|
||||
TagService $tagService,
|
||||
HistoryService $historyService,
|
||||
ImageManipulator $imageManipulator)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->validator = $validator;
|
||||
|
@ -67,7 +88,7 @@ class PostService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getFiltered(\Szurubooru\SearchServices\Filters\PostFilter $filter)
|
||||
public function getFiltered(PostFilter $filter)
|
||||
{
|
||||
$transactionFunc = function() use ($filter)
|
||||
{
|
||||
|
@ -80,7 +101,7 @@ class PostService
|
|||
{
|
||||
$transactionFunc = function()
|
||||
{
|
||||
$globalParam = $this->globalParamDao->findByKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST);
|
||||
$globalParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST);
|
||||
if (!$globalParam)
|
||||
return null;
|
||||
return $this->getByNameOrId($globalParam->getValue());
|
||||
|
@ -88,20 +109,20 @@ class PostService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getHistory(\Szurubooru\Entities\Post $post)
|
||||
public function getHistory(Post $post)
|
||||
{
|
||||
$transactionFunc = function() use ($post)
|
||||
{
|
||||
$filter = new \Szurubooru\SearchServices\Filters\SnapshotFilter();
|
||||
$filter = new SnapshotFilter();
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId()));
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY);
|
||||
$requirement->setValue(new RequirementSingleValue($post->getId()));
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||
$requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST));
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(SnapshotFilter::REQUIREMENT_TYPE);
|
||||
$requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST));
|
||||
$filter->addRequirement($requirement);
|
||||
|
||||
return $this->historyService->getFiltered($filter)->getEntities();
|
||||
|
@ -109,13 +130,13 @@ class PostService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function createPost(\Szurubooru\FormData\UploadFormData $formData)
|
||||
public function createPost(UploadFormData $formData)
|
||||
{
|
||||
$transactionFunc = function() use ($formData)
|
||||
{
|
||||
$formData->validate($this->validator);
|
||||
|
||||
$post = new \Szurubooru\Entities\Post();
|
||||
$post = new Post();
|
||||
$post->setUploadTime($this->timeService->getCurrentTime());
|
||||
$post->setLastEditTime($this->timeService->getCurrentTime());
|
||||
$post->setUser($formData->anonymous ? null : $this->authService->getLoggedInUser());
|
||||
|
@ -138,7 +159,7 @@ class PostService
|
|||
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)
|
||||
{
|
||||
|
@ -176,17 +197,17 @@ class PostService
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety)
|
||||
private function updatePostSafety(Post $post, $newSafety)
|
||||
{
|
||||
$post->setSafety($newSafety);
|
||||
}
|
||||
|
||||
private function updatePostSource(\Szurubooru\Entities\Post $post, $newSource)
|
||||
private function updatePostSource(Post $post, $newSource)
|
||||
{
|
||||
$post->setSource($newSource);
|
||||
}
|
||||
|
||||
private function updatePostContentFromStringOrUrl(\Szurubooru\Entities\Post $post, $content, $url)
|
||||
private function updatePostContentFromStringOrUrl(Post $post, $content, $url)
|
||||
{
|
||||
if ($url)
|
||||
$this->updatePostContentFromUrl($post, $url);
|
||||
|
@ -196,7 +217,7 @@ class PostService
|
|||
throw new \DomainException('No content specified');
|
||||
}
|
||||
|
||||
private function updatePostContentFromString(\Szurubooru\Entities\Post $post, $content)
|
||||
private function updatePostContentFromString(Post $post, $content)
|
||||
{
|
||||
if (!$content)
|
||||
throw new \DomainException('File cannot be empty.');
|
||||
|
@ -204,15 +225,15 @@ class PostService
|
|||
if (strlen($content) > $this->config->database->maxPostSize)
|
||||
throw new \DomainException('Upload is too big.');
|
||||
|
||||
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content);
|
||||
$mime = MimeHelper::getMimeTypeFromBuffer($content);
|
||||
$post->setContentMimeType($mime);
|
||||
|
||||
if (\Szurubooru\Helpers\MimeHelper::isFlash($mime))
|
||||
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_FLASH);
|
||||
elseif (\Szurubooru\Helpers\MimeHelper::isImage($mime))
|
||||
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_IMAGE);
|
||||
elseif (\Szurubooru\Helpers\MimeHelper::isVideo($mime))
|
||||
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_VIDEO);
|
||||
if (MimeHelper::isFlash($mime))
|
||||
$post->setContentType(Post::POST_TYPE_FLASH);
|
||||
elseif (MimeHelper::isImage($mime))
|
||||
$post->setContentType(Post::POST_TYPE_IMAGE);
|
||||
elseif (MimeHelper::isVideo($mime))
|
||||
$post->setContentType(Post::POST_TYPE_VIDEO);
|
||||
else
|
||||
throw new \DomainException('Unhandled file type: "' . $mime . '"');
|
||||
|
||||
|
@ -228,7 +249,7 @@ class PostService
|
|||
$post->setOriginalFileSize(strlen($content));
|
||||
}
|
||||
|
||||
private function updatePostContentFromUrl(\Szurubooru\Entities\Post $post, $url)
|
||||
private function updatePostContentFromUrl(Post $post, $url)
|
||||
{
|
||||
if (!preg_match('/^https?:\/\//', $url))
|
||||
throw new \InvalidArgumentException('Invalid URL "' . $url . '"');
|
||||
|
@ -239,7 +260,7 @@ class PostService
|
|||
|
||||
if ($youtubeId)
|
||||
{
|
||||
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE);
|
||||
$post->setContentType(Post::POST_TYPE_YOUTUBE);
|
||||
$post->setImageWidth(null);
|
||||
$post->setImageHeight(null);
|
||||
$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)
|
||||
throw new \DomainException('Thumbnail is too big.');
|
||||
|
@ -267,12 +288,12 @@ class PostService
|
|||
$post->setThumbnailSourceContent($newThumbnail);
|
||||
}
|
||||
|
||||
private function updatePostTags(\Szurubooru\Entities\Post $post, array $newTagNames)
|
||||
private function updatePostTags(Post $post, array $newTagNames)
|
||||
{
|
||||
$tags = [];
|
||||
foreach ($newTagNames as $tagName)
|
||||
{
|
||||
$tag = new \Szurubooru\Entities\Tag();
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
@ -280,7 +301,7 @@ class PostService
|
|||
$post->setTags($tags);
|
||||
}
|
||||
|
||||
private function updatePostRelations(\Szurubooru\Entities\Post $post, array $newRelatedPostIds)
|
||||
private function updatePostRelations(Post $post, array $newRelatedPostIds)
|
||||
{
|
||||
$relatedPosts = $this->postDao->findByIds($newRelatedPostIds);
|
||||
foreach ($newRelatedPostIds as $postId)
|
||||
|
@ -292,7 +313,7 @@ class PostService
|
|||
$post->setRelatedPosts($relatedPosts);
|
||||
}
|
||||
|
||||
public function deletePost(\Szurubooru\Entities\Post $post)
|
||||
public function deletePost(Post $post)
|
||||
{
|
||||
$transactionFunc = function() use ($post)
|
||||
{
|
||||
|
@ -302,7 +323,7 @@ class PostService
|
|||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function featurePost(\Szurubooru\Entities\Post $post)
|
||||
public function featurePost(Post $post)
|
||||
{
|
||||
$transactionFunc = function() use ($post)
|
||||
{
|
||||
|
@ -311,8 +332,8 @@ class PostService
|
|||
$post->setLastFeatureTime($this->timeService->getCurrentTime());
|
||||
$post->setFeatureCount($post->getFeatureCount() + 1);
|
||||
$this->postDao->save($post);
|
||||
$globalParam = new \Szurubooru\Entities\GlobalParam();
|
||||
$globalParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST);
|
||||
$globalParam = new GlobalParam();
|
||||
$globalParam->setKey(GlobalParam::KEY_FEATURED_POST);
|
||||
$globalParam->setValue($post->getId());
|
||||
$this->globalParamDao->save($globalParam);
|
||||
|
||||
|
@ -327,20 +348,20 @@ class PostService
|
|||
{
|
||||
$transactionFunc = function()
|
||||
{
|
||||
$countParam = new \Szurubooru\Entities\GlobalParam();
|
||||
$countParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_COUNT);
|
||||
$countParam = new GlobalParam();
|
||||
$countParam->setKey(GlobalParam::KEY_POST_COUNT);
|
||||
$countParam->setValue($this->postDao->getCount());
|
||||
$this->globalParamDao->save($countParam);
|
||||
|
||||
$fileSizeParam = new \Szurubooru\Entities\GlobalParam();
|
||||
$fileSizeParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_SIZE);
|
||||
$fileSizeParam = new GlobalParam();
|
||||
$fileSizeParam->setKey(GlobalParam::KEY_POST_SIZE);
|
||||
$fileSizeParam->setValue($this->postDao->getTotalFileSize());
|
||||
$this->globalParamDao->save($fileSizeParam);
|
||||
};
|
||||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
private function assertNoPostWithThisContentChecksum(\Szurubooru\Entities\Post $parent)
|
||||
private function assertNoPostWithThisContentChecksum(Post $parent)
|
||||
{
|
||||
$checksumToCheck = $parent->getContentChecksum();
|
||||
$postWithThisChecksum = $this->postDao->findByContentChecksum($checksumToCheck);
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Helpers\EnumHelper;
|
||||
use Szurubooru\Services\AuthService;
|
||||
|
||||
class PrivilegeService
|
||||
{
|
||||
|
@ -7,8 +11,8 @@ class PrivilegeService
|
|||
private $privilegeMap;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Services\AuthService $authService)
|
||||
Config $config,
|
||||
AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
|
||||
|
@ -30,7 +34,7 @@ class PrivilegeService
|
|||
public function getCurrentPrivileges()
|
||||
{
|
||||
$currentAccessRank = $this->authService->getLoggedInUser()->getAccessRank();
|
||||
$currentAccessRankName = \Szurubooru\Helpers\EnumHelper::accessRankToString($currentAccessRank);
|
||||
$currentAccessRankName = EnumHelper::accessRankToString($currentAccessRank);
|
||||
if (!isset($this->privilegeMap[$currentAccessRankName]))
|
||||
return [];
|
||||
return $this->privilegeMap[$currentAccessRankName];
|
||||
|
@ -64,7 +68,7 @@ class PrivilegeService
|
|||
public function isLoggedIn($userIdentifier)
|
||||
{
|
||||
$loggedInUser = $this->authService->getLoggedInUser();
|
||||
if ($userIdentifier instanceof \Szurubooru\Entities\User)
|
||||
if ($userIdentifier instanceof User)
|
||||
{
|
||||
return $loggedInUser->getId() and ($loggedInUser->getId() === $userIdentifier->getId());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -10,11 +18,11 @@ class ScoreService
|
|||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\ScoreDao $scoreDao,
|
||||
\Szurubooru\Dao\FavoritesDao $favoritesDao,
|
||||
\Szurubooru\Dao\UserDao $userDao,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Services\TimeService $timeService)
|
||||
ScoreDao $scoreDao,
|
||||
FavoritesDao $favoritesDao,
|
||||
UserDao $userDao,
|
||||
TransactionManager $transactionManager,
|
||||
TimeService $timeService)
|
||||
{
|
||||
$this->scoreDao = $scoreDao;
|
||||
$this->favoritesDao = $favoritesDao;
|
||||
|
@ -23,7 +31,7 @@ class ScoreService
|
|||
$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)
|
||||
{
|
||||
|
@ -32,7 +40,7 @@ class ScoreService
|
|||
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);
|
||||
if (!$score)
|
||||
|
@ -40,14 +48,14 @@ class ScoreService
|
|||
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)
|
||||
throw new \DomainException('Bad score');
|
||||
|
||||
$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);
|
||||
|
||||
return $this->scoreDao->setScore($user, $entity, $scoreValue);
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -9,10 +15,10 @@ class TagService
|
|||
private $timeService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Dao\TagDao $tagDao,
|
||||
\Szurubooru\Services\TimeService $timeService,
|
||||
\Szurubooru\Services\FileService $fileService)
|
||||
TransactionManager $transactionManager,
|
||||
TagDao $tagDao,
|
||||
TimeService $timeService,
|
||||
FileService $fileService)
|
||||
{
|
||||
$this->transactionManager = $transactionManager;
|
||||
$this->tagDao = $tagDao;
|
||||
|
@ -20,7 +26,7 @@ class TagService
|
|||
$this->fileService = $fileService;
|
||||
}
|
||||
|
||||
public function getFiltered(\Szurubooru\SearchServices\Filters\TagFilter $filter)
|
||||
public function getFiltered(TagFilter $filter)
|
||||
{
|
||||
$transactionFunc = function() use ($filter)
|
||||
{
|
||||
|
@ -68,7 +74,7 @@ class TagService
|
|||
$tagsToCreate = [];
|
||||
foreach ($tagNamesToCreate as $tagName)
|
||||
{
|
||||
$tag = new \Szurubooru\Entities\Tag;
|
||||
$tag = new Tag;
|
||||
$tag->setName($tagName);
|
||||
$tag->setCreationTime($this->timeService->getCurrentTime());
|
||||
$tagsToCreate[] = $tag;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use Szurubooru\Helpers\ProgramExecutor;
|
||||
|
||||
class FlashThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
|
@ -19,9 +20,9 @@ class FlashThumbnailGenerator implements IThumbnailGenerator
|
|||
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
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,
|
||||
[
|
||||
'--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,
|
||||
[
|
||||
'swfrender',
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use Szurubooru\Services\ImageManipulation\IImageManipulator;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
|
||||
class ImageThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
private $imageManipulator;
|
||||
|
||||
public function __construct(\Szurubooru\Services\ImageManipulation\ImageManipulator $imageManipulator)
|
||||
public function __construct(ImageManipulator $imageManipulator)
|
||||
{
|
||||
$this->imageManipulator = $imageManipulator;
|
||||
}
|
||||
|
@ -34,7 +36,7 @@ class ImageThumbnailGenerator implements IThumbnailGenerator
|
|||
|
||||
return $this->imageManipulator->saveToBuffer(
|
||||
$image,
|
||||
\Szurubooru\Services\ImageManipulation\IImageManipulator::FORMAT_JPEG);
|
||||
IImageManipulator::FORMAT_JPEG);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use Szurubooru\Helpers\MimeHelper;
|
||||
|
||||
class SmartThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
|
@ -19,15 +20,15 @@ class SmartThumbnailGenerator implements IThumbnailGenerator
|
|||
|
||||
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);
|
||||
|
||||
if (\Szurubooru\Helpers\MimeHelper::isVideo($mime))
|
||||
if (MimeHelper::isVideo($mime))
|
||||
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 null;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use \Szurubooru\Helpers\ProgramExecutor;
|
||||
|
||||
class VideoThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
|
@ -19,9 +20,9 @@ class VideoThumbnailGenerator implements IThumbnailGenerator
|
|||
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
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,
|
||||
[
|
||||
'-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,
|
||||
'-vframes', '1',
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\Services\FileService;
|
||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||
|
||||
class ThumbnailService
|
||||
{
|
||||
|
@ -8,9 +12,9 @@ class ThumbnailService
|
|||
private $thumbnailGenerator;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator $thumbnailGenerator)
|
||||
Config $config,
|
||||
FileService $fileService,
|
||||
SmartThumbnailGenerator $thumbnailGenerator)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->fileService = $fileService;
|
||||
|
@ -40,11 +44,11 @@ class ThumbnailService
|
|||
switch ($this->config->misc->thumbnailCropStyle)
|
||||
{
|
||||
case 'outside':
|
||||
$cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE;
|
||||
$cropStyle = IThumbnailGenerator::CROP_OUTSIDE;
|
||||
break;
|
||||
|
||||
case 'inside':
|
||||
$cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_INSIDE;
|
||||
$cropStyle = IThumbnailGenerator::CROP_INSIDE;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Dao\TokenDao;
|
||||
use Szurubooru\Dao\TransactionManager;
|
||||
use Szurubooru\Entities\Token;
|
||||
|
||||
class TokenService
|
||||
{
|
||||
|
@ -7,8 +10,8 @@ class TokenService
|
|||
private $tokenDao;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Dao\TokenDao $tokenDao)
|
||||
TransactionManager $transactionManager,
|
||||
TokenDao $tokenDao)
|
||||
{
|
||||
$this->transactionManager = $transactionManager;
|
||||
$this->tokenDao = $tokenDao;
|
||||
|
@ -52,7 +55,7 @@ class TokenService
|
|||
|
||||
if (!$token)
|
||||
{
|
||||
$token = new \Szurubooru\Entities\Token();
|
||||
$token = new Token();
|
||||
$token->setName(sha1(date('r') . uniqid() . microtime(true)));
|
||||
$token->setAdditionalData($additionalData);
|
||||
$token->setPurpose($tokenPurpose);
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
use Szurubooru\Upgrades\IUpgrade;
|
||||
use Szurubooru\Upgrades\UpgradeRepository;
|
||||
|
||||
final class UpgradeService
|
||||
{
|
||||
|
@ -9,9 +13,9 @@ final class UpgradeService
|
|||
private $executedUpgradeNames = [];
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Upgrades\UpgradeRepository $upgradeRepository)
|
||||
Config $config,
|
||||
DatabaseConnection $databaseConnection,
|
||||
UpgradeRepository $upgradeRepository)
|
||||
{
|
||||
$this->config = $config;
|
||||
$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);
|
||||
}
|
||||
|
||||
private function runUpgrade(\Szurubooru\Upgrades\IUpgrade $upgrade)
|
||||
private function runUpgrade(IUpgrade $upgrade)
|
||||
{
|
||||
$upgrade->run($this->databaseConnection);
|
||||
$this->executedUpgradeNames[] = get_class($upgrade);
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -15,16 +31,16 @@ class UserService
|
|||
private $tokenService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\Validator $validator,
|
||||
\Szurubooru\Dao\TransactionManager $transactionManager,
|
||||
\Szurubooru\Dao\UserDao $userDao,
|
||||
\Szurubooru\Services\PasswordService $passwordService,
|
||||
\Szurubooru\Services\EmailService $emailService,
|
||||
\Szurubooru\Services\FileService $fileService,
|
||||
\Szurubooru\Services\ThumbnailService $thumbnailService,
|
||||
\Szurubooru\Services\TimeService $timeService,
|
||||
\Szurubooru\Services\TokenService $tokenService)
|
||||
Config $config,
|
||||
Validator $validator,
|
||||
TransactionManager $transactionManager,
|
||||
UserDao $userDao,
|
||||
PasswordService $passwordService,
|
||||
EmailService $emailService,
|
||||
FileService $fileService,
|
||||
ThumbnailService $thumbnailService,
|
||||
TimeService $timeService,
|
||||
TokenService $tokenService)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->validator = $validator;
|
||||
|
@ -79,7 +95,7 @@ class UserService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getFiltered(\Szurubooru\SearchServices\Filters\UserFilter $filter)
|
||||
public function getFiltered(UserFilter $filter)
|
||||
{
|
||||
$transactionFunc = function() use ($filter)
|
||||
{
|
||||
|
@ -88,30 +104,30 @@ class UserService
|
|||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function createUser(\Szurubooru\FormData\RegistrationFormData $formData)
|
||||
public function createUser(RegistrationFormData $formData)
|
||||
{
|
||||
$transactionFunc = function() use ($formData)
|
||||
{
|
||||
$formData->validate($this->validator);
|
||||
|
||||
$user = new \Szurubooru\Entities\User();
|
||||
$user = new User();
|
||||
$user->setRegistrationTime($this->timeService->getCurrentTime());
|
||||
$user->setLastLoginTime(null);
|
||||
$user->setAccessRank($this->userDao->hasAnyUsers()
|
||||
? \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER
|
||||
: \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR);
|
||||
? User::ACCESS_RANK_REGULAR_USER
|
||||
: User::ACCESS_RANK_ADMINISTRATOR);
|
||||
$user->setPasswordSalt($this->passwordService->getRandomPassword());
|
||||
|
||||
$this->updateUserName($user, $formData->userName);
|
||||
$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);
|
||||
return $this->userDao->save($user);
|
||||
};
|
||||
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)
|
||||
{
|
||||
|
@ -146,7 +162,7 @@ class UserService
|
|||
return $this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function deleteUser(\Szurubooru\Entities\User $user)
|
||||
public function deleteUser(User $user)
|
||||
{
|
||||
$transactionFunc = function() use ($user)
|
||||
{
|
||||
|
@ -155,21 +171,21 @@ class UserService
|
|||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function sendPasswordResetEmail(\Szurubooru\Entities\User $user)
|
||||
public function sendPasswordResetEmail(User $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->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function finishPasswordReset(\Szurubooru\Entities\Token $token)
|
||||
public function finishPasswordReset(Token $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.');
|
||||
|
||||
$user = $this->getByName($token->getAdditionalData());
|
||||
|
@ -182,21 +198,21 @@ class UserService
|
|||
return $this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function sendActivationEmail(\Szurubooru\Entities\User $user)
|
||||
public function sendActivationEmail(User $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->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function finishActivation(\Szurubooru\Entities\Token $token)
|
||||
public function finishActivation(Token $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.');
|
||||
|
||||
$user = $this->getByName($token->getAdditionalData());
|
||||
|
@ -207,15 +223,15 @@ class UserService
|
|||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
private function updateUserAvatarStyle(\Szurubooru\Entities\User $user, $newAvatarStyle)
|
||||
private function updateUserAvatarStyle(User $user, $newAvatarStyle)
|
||||
{
|
||||
$user->setAvatarStyle($newAvatarStyle);
|
||||
}
|
||||
|
||||
private function updateUserAvatarContent(\Szurubooru\Entities\User $user, $newAvatarContent)
|
||||
private function updateUserAvatarContent(User $user, $newAvatarContent)
|
||||
{
|
||||
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($newAvatarContent);
|
||||
if (!\Szurubooru\Helpers\MimeHelper::isImage($mime))
|
||||
$mime = MimeHelper::getMimeTypeFromBuffer($newAvatarContent);
|
||||
if (!MimeHelper::isImage($mime))
|
||||
throw new \DomainException('Avatar must be an image.');
|
||||
|
||||
if (strlen($newAvatarContent) > $this->config->database->maxCustomThumbnailSize)
|
||||
|
@ -224,18 +240,18 @@ class UserService
|
|||
$user->setCustomAvatarSourceContent($newAvatarContent);
|
||||
}
|
||||
|
||||
private function updateUserName(\Szurubooru\Entities\User $user, $newName)
|
||||
private function updateUserName(User $user, $newName)
|
||||
{
|
||||
$this->assertNoUserWithThisName($user, $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()));
|
||||
}
|
||||
|
||||
private function updateUserEmail(\Szurubooru\Entities\User $user, $newEmail)
|
||||
private function updateUserEmail(User $user, $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);
|
||||
}
|
||||
|
||||
private function updateUserBrowsingSettings(\Szurubooru\Entities\User $user, $newBrowsingSettings)
|
||||
private function updateUserBrowsingSettings(User $user, $newBrowsingSettings)
|
||||
{
|
||||
$user->setBrowsingSettings($newBrowsingSettings);
|
||||
}
|
||||
|
||||
public function updateUserLastLoginTime(\Szurubooru\Entities\User $user)
|
||||
public function updateUserLastLoginTime(User $user)
|
||||
{
|
||||
$transactionFunc = function() use ($user)
|
||||
{
|
||||
|
@ -269,9 +285,9 @@ class UserService
|
|||
$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)
|
||||
{
|
||||
$user = $this->confirmUserEmail($user);
|
||||
|
@ -283,7 +299,7 @@ class UserService
|
|||
return $user;
|
||||
}
|
||||
|
||||
private function confirmUserEmail(\Szurubooru\Entities\User $user)
|
||||
private function confirmUserEmail(User $user)
|
||||
{
|
||||
//security issue:
|
||||
//1. two users set their unconfirmed mail to godzilla@empire.gov
|
||||
|
@ -301,14 +317,14 @@ class UserService
|
|||
return $user;
|
||||
}
|
||||
|
||||
private function assertNoUserWithThisName(\Szurubooru\Entities\User $owner, $nameToCheck)
|
||||
private function assertNoUserWithThisName(User $owner, $nameToCheck)
|
||||
{
|
||||
$userWithThisName = $this->userDao->findByName($nameToCheck);
|
||||
if ($userWithThisName and $userWithThisName->getId() !== $owner->getId())
|
||||
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)
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
interface IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection);
|
||||
public function run(DatabaseConnection $databaseConnection);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade01 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade02 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$databaseConnection->getPDO()->exec('
|
||||
ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade03 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
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
|
||||
{
|
||||
|
@ -8,26 +14,26 @@ class Upgrade04 implements IUpgrade
|
|||
private $fileService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\PostDao $postDao,
|
||||
\Szurubooru\Services\PostService $postService,
|
||||
\Szurubooru\Services\FileService $fileService)
|
||||
PostDao $postDao,
|
||||
PostService $postService,
|
||||
FileService $fileService)
|
||||
{
|
||||
$this->postDao = $postDao;
|
||||
$this->postService = $postService;
|
||||
$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');
|
||||
|
||||
$posts = $this->postDao->findAll();
|
||||
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());
|
||||
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath);
|
||||
$mime = MimeHelper::getMimeTypeFromFile($fullPath);
|
||||
$post->setContentMimeType($mime);
|
||||
$this->postDao->save($post);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade05 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade06 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade07 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade08 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\Dao\PostDao;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
use Szurubooru\Services\HistoryService;
|
||||
|
||||
class Upgrade09 implements IUpgrade
|
||||
{
|
||||
|
@ -7,14 +10,14 @@ class Upgrade09 implements IUpgrade
|
|||
private $historyService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Dao\PostDao $postDao,
|
||||
\Szurubooru\Services\HistoryService $historyService)
|
||||
PostDao $postDao,
|
||||
HistoryService $historyService)
|
||||
{
|
||||
$this->postDao = $postDao;
|
||||
$this->historyService = $historyService;
|
||||
}
|
||||
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade10 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade11 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
use Szurubooru\Services\TagService;
|
||||
|
||||
class Upgrade12 implements IUpgrade
|
||||
{
|
||||
private $tagService;
|
||||
|
||||
public function __construct(\Szurubooru\Services\TagService $tagService)
|
||||
public function __construct(TagService $tagService)
|
||||
{
|
||||
$this->tagService = $tagService;
|
||||
}
|
||||
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$this->tagService->exportJson();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade13 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade14 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade15 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$driver = $databaseConnection->getDriver();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade16 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
|
||||
class Upgrade17 implements IUpgrade
|
||||
{
|
||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue