Skip to content

Commit

Permalink
Stop using _data (conf data_location) and use media_cache_directory
Browse files Browse the repository at this point in the history
instead.
Cope with #72
  • Loading branch information
nikrou committed Mar 20, 2021
1 parent 36e4f36 commit 879be2a
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 151 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/phyxo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ jobs:
- name: Unit tests
run: ./bin/atoum

- name: PHPUnit tests
run: ./bin/simple-phpunit --testdox

- name: Create database
run: ./bin/console doctrine:database:create -vvv

Expand All @@ -70,6 +67,9 @@ jobs:
- name: Create guest user
run: ./bin/console phyxo:user:create --username guest --password '' --mail_address '' --status guest

- name: PHPUnit tests
run: ./bin/simple-phpunit --testdox

- name: Run Behat tests
run: ./bin/behat --colors --no-interaction -vvv -c behat.yml.dist --suite=web

Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
/public/bundles/
/var/
/vendor/

/media/*
/tests/media
/tests/upload

###< symfony/framework-bundle ###

###> behat/symfony2-extension ###
Expand All @@ -70,10 +75,7 @@ behat.yml
/.php_cs
/.php_cs.cache
###< friendsofphp/php-cs-fixer ###
/install/queries.sql

/tests/media
/tests/upload

###> symfony/phpunit-bridge ###
.phpunit
Expand Down
2 changes: 1 addition & 1 deletion config/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parameters:
default_config_file: '%kernel.project_dir%/include/config_default.inc.php'
default_theme: 'treflez'
user_config_file: '%local_dir%/config/config.inc.php'
media_cache_dir: '%kernel.project_dir%/_data/i'
media_cache_dir: '%kernel.project_dir%/media'
root_project_dir: '%kernel.project_dir%'

start_param: 'start'
Expand Down
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:
$rememberMeCookie: '%remember_cookie%'
$databaseYamlFile: '%database_yaml_file%'
$localDir: '%local_dir%'
$configDir: '%kernel.project_dir%/config'
$varDir: '%kernel.project_dir%/var'
$uploadDir: '%upload_dir%'
$themesDir: '%themes_dir%'
$pluginsDir: '%plugins_dir%'
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/Admin/BatchManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use App\Repository\ImageAlbumRepository;
use App\Repository\ImageTagRepository;
use App\Repository\TagRepository;
use App\Services\DerivativeService;
use Phyxo\Conf;
use Phyxo\Functions\Utils;
use Phyxo\Image\DerivativeImage;
Expand All @@ -37,7 +38,7 @@

class BatchManagerController extends AbstractController
{
private $translator;
private $translator, $derivativeService;

protected function setTabsheet(string $section = 'global')
{
Expand Down Expand Up @@ -69,13 +70,14 @@ protected function getFilter()
return $filter;
}

public function global(Request $request, string $filter = null, int $start = 0, Conf $conf, AlbumMapper $albumMapper,
public function global(Request $request, string $filter = null, int $start = 0, Conf $conf, AlbumMapper $albumMapper, DerivativeService $derivativeService,
ImageStandardParams $image_std_params, SearchMapper $searchMapper, TagMapper $tagMapper, ImageMapper $imageMapper, CaddieRepository $caddieRepository,
UserMapper $userMapper, Metadata $metadata, TranslatorInterface $translator, AlbumRepository $albumRepository, ImageTagRepository $imageTagRepository,
ImageAlbumRepository $imageAlbumRepository, FavoriteRepository $favoriteRepository, TagRepository $tagRepository)
{
$tpl_params = [];
$this->translator = $translator;
$this->derivativeService = $derivativeService;

$_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath();
$tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_batch_manager_global');
Expand Down Expand Up @@ -544,7 +546,7 @@ protected function actionOnCollection(Request $request, array $collection = [],
} elseif ($action === 'delete_derivatives' && $request->request->get('del_derivatives_type')) {
foreach ($imageMapper->getRepository()->find($collection) as $image) {
foreach ($request->request->get('del_derivatives_type') as $type) {
Utils::delete_element_derivatives($image->toArray(), $type);
$this->derivativeService->deleteForElement($image->toArray(), $type);
}
}
} elseif ($action === 'generate_derivatives') {
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/Admin/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use App\Repository\LanguageRepository;
use App\Repository\ThemeRepository;
use App\Repository\UserInfosRepository;
use App\Services\DerivativeService;
use Phyxo\Conf;
use Phyxo\Functions\Utils;
use Phyxo\Image\Image;
use Phyxo\Image\ImageStandardParams;
use Phyxo\Image\WatermarkParams;
Expand Down Expand Up @@ -196,10 +196,10 @@ public function index(Request $request, string $section, Conf $conf, ParameterBa
return $this->render('configuration_' . $section . '.html.twig', $tpl_params);
}

public function sizeRestore(ImageStandardParams $image_std_params, Conf $conf, TranslatorInterface $translator)
public function sizeRestore(ImageStandardParams $image_std_params, Conf $conf, TranslatorInterface $translator, DerivativeService $derivativeService)
{
$image_std_params->setAndSave($image_std_params->getDefaultSizes());
Utils::clear_derivative_cache($image_std_params->getAllTypes(), $image_std_params->getAllTypes());
$derivativeService->clearCache($image_std_params->getAllTypes(), $image_std_params->getAllTypes());
$this->addFlash('info', $translator->trans('Your configuration settings have been saved', [], 'admin'));
unset($conf['disabled_derivatives']);

Expand Down Expand Up @@ -430,7 +430,7 @@ protected function defaultConfiguration(Conf $conf, UserMapper $userMapper, Them
}

public function update(Request $request, string $section, Conf $conf, ThemeRepository $themeRepository, string $localDir, ImageStandardParams $image_std_params,
UserMapper $userMapper, UserInfosRepository $userInfosRepository, LanguageRepository $languageRepository)
UserMapper $userMapper, UserInfosRepository $userInfosRepository, LanguageRepository $languageRepository, DerivativeService $derivativeService)
{
$conf_updated = false;
$error = false;
Expand Down Expand Up @@ -769,7 +769,7 @@ public function update(Request $request, string $section, Conf $conf, ThemeRepos
$image_std_params->save();

if (count($changed_types)) {
\Phyxo\Functions\Utils::clear_derivative_cache($changed_types, $image_std_params->getAllTypes());
$derivativeService->clearCache($changed_types, $image_std_params->getAllTypes());
}

$this->addFlash('info', $this->translator->trans('Your configuration settings have been saved', [], 'admin'));
Expand Down Expand Up @@ -956,7 +956,7 @@ public function update(Request $request, string $section, Conf $conf, ThemeRepos
}

if (count($changed_types)) {
\Phyxo\Functions\Utils::clear_derivative_cache($changed_types, $image_std_params->getAllTypes());
$derivativeService->clearCache($changed_types, $image_std_params->getAllTypes());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Admin/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use App\Repository\HistorySummaryRepository;
use App\Repository\SearchRepository;
use App\Repository\UserFeedRepository;
use App\Services\DerivativeService;
use Phyxo\Conf;
use Phyxo\Functions\Utils;
use Phyxo\Image\ImageStandardParams;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand Down Expand Up @@ -223,9 +223,9 @@ public function index(Request $request, ?string $action, Conf $conf, ParameterBa
return $this->render('maintenance.html.twig', $tpl_params);
}

public function derivatives(string $type, ImageStandardParams $image_std_params)
public function derivatives(string $type, ImageStandardParams $image_std_params, DerivativeService $derivativeService)
{
Utils::clear_derivative_cache([$type], $image_std_params->getAllTypes());
$derivativeService->clearCache([$type], $image_std_params->getAllTypes());

return $this->redirectToRoute('admin_maintenance');
}
Expand Down
11 changes: 6 additions & 5 deletions src/Controller/Admin/PhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Repository\ImageAlbumRepository;
use App\Repository\RateRepository;
use App\Repository\UserRepository;
use App\Services\DerivativeService;
use Phyxo\Conf;
use Phyxo\Functions\Utils;
use Phyxo\Image\DerivativeImage;
Expand Down Expand Up @@ -266,7 +267,7 @@ public function syncMetadata(int $image_id, int $category_id = null, TagMapper $
}

public function coi(Request $request, int $image_id, int $category_id = null, ImageStandardParams $image_std_params, Conf $conf,
ImageMapper $imageMapper, TranslatorInterface $translator)
ImageMapper $imageMapper, TranslatorInterface $translator, DerivativeService $derivativeService)
{
$tpl_params = [];
$this->translator = $translator;
Expand All @@ -288,11 +289,11 @@ public function coi(Request $request, int $image_id, int $category_id = null, Im
$imageMapper->getRepository()->addOrUpdateImage($image);

foreach ($image_std_params->getDefinedTypeMap() as $std_params) {
if ($std_params->sizing->max_crop != 0) {
Utils::delete_element_derivatives($image->toArray(), $std_params->type);
if ($std_params->sizing->max_crop !== 0) {
$derivativeService->deleteForElement($image->toArray(), $std_params->type);
}
}
Utils::delete_element_derivatives($image->toArray(), ImageStandardParams::IMG_CUSTOM);
$derivativeService->deleteForElement($image->toArray(), ImageStandardParams::IMG_CUSTOM);

return $this->redirectToRoute('admin_photo_coi', ['image_id' => $image_id, 'category_id' => $category_id]);
}
Expand All @@ -312,7 +313,7 @@ public function coi(Request $request, int $image_id, int $category_id = null, Im
}

foreach ($image_std_params->getDefinedTypeMap() as $std_params) {
if ($std_params->sizing->max_crop !== 0) {
if ($std_params->sizing->max_crop != 0) {
$derivative = new DerivativeImage($src_image, $std_params, $image_std_params);
$tpl_params['cropped_derivatives'][] = [
'U_IMG' => $derivative->getUrl(),
Expand Down
32 changes: 20 additions & 12 deletions src/Controller/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,27 @@ class InstallController extends AbstractController
'success' => ['label' => 'Installation completed']
];

private $languages_options, $passwordEncoder, $default_language, $default_theme, $translationsDir;
private $rootProjectDir, $translator, $databaseYamlFile, $phyxoInstaller;
private $languages_options, $passwordEncoder, $default_language, $default_theme, $translationsDir, $mediaCacheDir, $localDir;
private $rootProjectDir, $translator, $databaseYamlFile, $phyxoInstaller, $pluginsDir, $themesDir, $uploadDir, $varDir, $configDir;
private $default_prefix = 'phyxo_';

public function __construct(string $translationsDir, string $defaultLanguage, string $defaultTheme, PhyxoInstaller $phyxoInstaller,
string $databaseYamlFile, UserPasswordEncoderInterface $passwordEncoder, TranslatorInterface $translator, string $rootProjectDir)
public function __construct(string $translationsDir, string $defaultLanguage, string $defaultTheme, PhyxoInstaller $phyxoInstaller, string $mediaCacheDir,
string $themesDir, string $pluginsDir, string $databaseYamlFile, UserPasswordEncoderInterface $passwordEncoder, string $uploadDir,
TranslatorInterface $translator, string $rootProjectDir, string $varDir, string $configDir, string $localDir)
{
$this->translationsDir = $translationsDir;
$this->databaseYamlFile = $databaseYamlFile;
$this->default_language = $defaultLanguage;
$this->default_theme = $defaultTheme;
$this->passwordEncoder = $passwordEncoder;
$this->translator = $translator;
$this->themesDir = $themesDir;
$this->pluginsDir = $pluginsDir;
$this->uploadDir = $uploadDir;
$this->localDir = $localDir;
$this->varDir = $varDir;
$this->configDir = $configDir;
$this->mediaCacheDir = $mediaCacheDir;
$this->rootProjectDir = $rootProjectDir;
$this->phyxoInstaller = $phyxoInstaller;
}
Expand Down Expand Up @@ -121,40 +129,40 @@ protected function checkStep(Request $request)
'plugins' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../plugins'),
'path' => $this->pluginsDir,
],
'themes' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../themes'),
'path' => $this->themesDir,
],
];

$write_directories = [
'_data' => [
'media' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../_data'),
'path' => $this->mediaCacheDir,
],
'config' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../config'),
'path' => $this->configDir,
],
'local' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../local'),
'path' => $this->localDir,
],
'upload' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../upload'),
'path' => $this->uploadDir,
],
'var' => [
'readable' => false,
'writable' => false,
'path' => realpath(__DIR__ . '/../../var'),
'path' => $this->varDir,
],
];

Expand Down
9 changes: 6 additions & 3 deletions src/DataMapper/ImageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Repository\ImageTagRepository;
use App\Repository\ImageRepository;
use App\Repository\RateRepository;
use App\Services\DerivativeService;
use Phyxo\Functions\URL;
use Phyxo\Functions\Utils;
use Phyxo\Image\SrcImage;
Expand All @@ -31,11 +32,12 @@
class ImageMapper
{
private $router, $conf, $userMapper, $image_std_params, $albumMapper, $imageRepository, $imageTagRepository, $historyRepository;
private $translator, $imageAlbumRepository, $commentRepository, $caddieRepository, $favoriteRepository, $rateRepository;
private $translator, $imageAlbumRepository, $commentRepository, $caddieRepository, $favoriteRepository, $rateRepository, $derivativeService;

public function __construct(RouterInterface $router, UserMapper $userMapper, Conf $conf, ImageStandardParams $image_std_params, AlbumMapper $albumMapper, HistoryRepository $historyRepository,
TranslatorInterface $translator, ImageRepository $imageRepository, ImageAlbumRepository $imageAlbumRepository, CommentRepository $commentRepository,
CaddieRepository $caddieRepository, FavoriteRepository $favoriteRepository, RateRepository $rateRepository, ImageTagRepository $imageTagRepository)
CaddieRepository $caddieRepository, FavoriteRepository $favoriteRepository, RateRepository $rateRepository, ImageTagRepository $imageTagRepository,
DerivativeService $derivativeService)
{
$this->router = $router;
$this->userMapper = $userMapper;
Expand All @@ -51,6 +53,7 @@ public function __construct(RouterInterface $router, UserMapper $userMapper, Con
$this->favoriteRepository = $favoriteRepository;
$this->rateRepository = $rateRepository;
$this->historyRepository = $historyRepository;
$this->derivativeService = $derivativeService;
}

public function getRepository(): ImageRepository
Expand Down Expand Up @@ -316,7 +319,7 @@ public function deleteElementFiles(array $ids = [])
}

if ($ok) {
Utils::delete_element_derivatives($image->toArray());
$this->derivativeService->deleteForElement($image->toArray());
$new_ids[] = $image->getId();
} else {
break;
Expand Down
Loading

0 comments on commit 879be2a

Please sign in to comment.