Skip to content

Commit

Permalink
[Task][Application Logger] Remove PIMCORE_LOG_FILEOBJECT_DIRECTORY (p…
Browse files Browse the repository at this point in the history
…imcore#15175)

* Removed PIMCORE_LOG_FILEOBJECT_DIRECTORY constant, adapted code

* Update bundles/ApplicationLoggerBundle/src/Controller/LogController.php

Co-authored-by: lukmzig <[email protected]>

---------

Co-authored-by: lukmzig <[email protected]>
  • Loading branch information
mcop1 and lukmzig authored May 11, 2023
1 parent 1c83754 commit 944ca73
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 59 deletions.
3 changes: 1 addition & 2 deletions bundles/ApplicationLoggerBundle/config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ flysystem:
adapter: 'local'
visibility: private
options:
# TODO: revert default to `var/application-logger` when PIMCORE_LOG_FILEOBJECT_DIRECTORY is deprecated
directory: "%log.fileobject%"
directory: "%kernel.project_dir%/var/application-logger"
43 changes: 4 additions & 39 deletions bundles/ApplicationLoggerBundle/src/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Tool\Storage;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -219,14 +220,8 @@ public function componentJsonAction(Request $request): JsonResponse

/**
* @Route("/log/show-file-object", name="pimcore_admin_bundle_applicationlogger_log_showfileobject", methods={"GET"})
*
* @param Request $request
*
* @return StreamedResponse|Response
*
* @throws \Exception
*/
public function showFileObjectAction(Request $request): StreamedResponse|Response
public function showFileObjectAction(Request $request): StreamedResponse
{
$this->checkPermission('application_logging');

Expand All @@ -241,40 +236,10 @@ static function () use ($fileData) {
}
);
$response->headers->set('Content-Type', 'text/plain');
} else {
// Fallback to local path when file is not found in flysystem that might still be using the constant

if (!filter_var($filePath, FILTER_VALIDATE_URL)) {
if (!file_exists($filePath)) {
$filePath = PIMCORE_PROJECT_ROOT.DIRECTORY_SEPARATOR.$filePath;
}
$filePath = realpath($filePath);
$fileObjectPath = realpath(PIMCORE_LOG_FILEOBJECT_DIRECTORY);
} else {
$fileObjectPath = PIMCORE_LOG_FILEOBJECT_DIRECTORY;
}

if (!str_starts_with($filePath, $fileObjectPath)) {
throw new AccessDeniedHttpException('Accessing file out of scope');
}

if (file_exists($filePath)) {
$response = new StreamedResponse(
static function () use ($filePath) {
$handle = fopen($filePath, 'rb');
fpassthru($handle);
fclose($handle);
}
);
$response->headers->set('Content-Type', 'text/plain');
} else {
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
$response->setContent('Path `'.$filePath.'` not found.');
$response->setStatusCode(404);
}
return $response;
}

return $response;
throw new FileNotFoundException($filePath);
}
}
12 changes: 0 additions & 12 deletions bundles/ApplicationLoggerBundle/src/Maintenance/LogArchiveTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ public function execute(): void
if ($filePath !== null) {
if ($storage->fileExists($filePath)) {
$storage->delete($filePath);
} else {
// Fallback, if is not found and deleted in the flysystem, tries to delete from local
$fileRealPath = realpath($filePath);
if (str_starts_with(realpath($fileRealPath), PIMCORE_LOG_FILEOBJECT_DIRECTORY)) {
@unlink($fileRealPath);
}
}
}
}
Expand All @@ -121,12 +115,6 @@ public function execute(): void

if ($storage->directoryExists($folderName)) {
$storage->deleteDirectory($folderName);
} else {
// Fallback, if is not found and deleted in the flysystem, tries to delete from local
$folderRealPath = realpath(PIMCORE_LOG_FILEOBJECT_DIRECTORY . DIRECTORY_SEPARATOR . $folderName);
if (str_starts_with(realpath($folderRealPath), PIMCORE_LOG_FILEOBJECT_DIRECTORY)) {
@unlink($folderRealPath);
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions bundles/CoreBundle/config/pimcore/flysystem.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
parameters:
# TODO: remove this BC layer in 11 or as soon as PIMCORE_LOG_FILEOBJECT_DIRECTORY is deprecated
log.fileobject: !php/const PIMCORE_LOG_FILEOBJECT_DIRECTORY

flysystem:
storages:
pimcore.document_static.storage:
Expand Down
1 change: 1 addition & 0 deletions doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ pimcore_seo:
## Tools
#### [Application Logger] :

- Removed deprecated `PIMCORE_LOG_FILEOBJECT_DIRECTORY` constant, since flysystem is used to save/get fileobjects. Please make sure to adapt your code and migrate your fileobjects manually.
- Table names of archive tables are now named with year-month rather than month-year see [#8237](https://github.com/pimcore/pimcore/issues/8237).


Expand Down
1 change: 0 additions & 1 deletion lib/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public static function defineConstants(): void
$resolveConstant('PIMCORE_CONFIGURATION_DIRECTORY', PIMCORE_PRIVATE_VAR . '/config');
$resolveConstant('PIMCORE_LOG_DIRECTORY', PIMCORE_PRIVATE_VAR . '/log');
$resolveConstant('PIMCORE_CACHE_DIRECTORY', PIMCORE_PRIVATE_VAR . '/cache/pimcore');
$resolveConstant('PIMCORE_LOG_FILEOBJECT_DIRECTORY', PIMCORE_PRIVATE_VAR . '/application-logger');
$resolveConstant('PIMCORE_SYMFONY_CACHE_DIRECTORY', PIMCORE_PRIVATE_VAR . '/cache');
$resolveConstant('PIMCORE_CLASS_DIRECTORY', PIMCORE_PRIVATE_VAR . '/classes');
$resolveConstant('PIMCORE_CLASS_DEFINITION_DIRECTORY', PIMCORE_CLASS_DIRECTORY);
Expand Down
1 change: 0 additions & 1 deletion stubs/dynamic-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
define('PIMCORE_CONFIGURATION_DIRECTORY', '');
define('PIMCORE_LOG_DIRECTORY', '');
define('PIMCORE_CACHE_DIRECTORY', '');
define('PIMCORE_LOG_FILEOBJECT_DIRECTORY', '');
define('PIMCORE_SYSTEM_TEMP_DIRECTORY', '');
define('PIMCORE_PROJECT_ROOT', '');
define('PIMCORE_SYMFONY_CACHE_DIRECTORY', '');
Expand Down

0 comments on commit 944ca73

Please sign in to comment.