Skip to content

Commit

Permalink
[ticket/15253] Use path from adapter
Browse files Browse the repository at this point in the history
PHPBB3-15253
  • Loading branch information
rubencm committed Jul 20, 2017
1 parent 334b440 commit 0d14c85
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 52 deletions.
2 changes: 2 additions & 0 deletions phpBB/config/default/container/services_storage.yml
Expand Up @@ -2,8 +2,10 @@ services:
storage.adapter.avatar:
class: phpbb\storage\adapter\local
arguments:
- '@config'
- '@filesystem'
- '%core.root_path%'
- 'avatar_path'
storage.avatar:
class: phpbb\storage\storage
arguments:
Expand Down
31 changes: 18 additions & 13 deletions phpBB/phpbb/storage/adapter/local.php
Expand Up @@ -25,31 +25,36 @@ class local implements adapter_interface
*/
protected $filesystem;

/** @var string phpBB root path */
protected $phpbb_root_path;
/** @var string path */
protected $root_path;

/**
* Constructor
*/
public function __construct($filesystem, $phpbb_root_path)
public function __construct(\phpbb\config\config $config, \phpbb\filesystem\filesystem $filesystem, $root_path, $path_key)
{
$this->filesystem = $filesystem;
$this->phpbb_root_path = $phpbb_root_path;
$this->root_path = $root_path.$config[$path_key];

if(substr($this->root_path, -1, 1) != DIRECTORY_SEPARATOR)
{
$this->root_path = $this->root_path.DIRECTORY_SEPARATOR;
}
}

/**
* {@inheritdoc}
*/
public function put_contents($path, $content)
{
if ($this->exists($this->phpbb_root_path.$path))
if ($this->exists($this->root_path.$path))
{
throw new exception('', $path); // FILE_EXISTS
}

try
{
$this->filesystem->dump_file($this->phpbb_root_path.$path, $content);
$this->filesystem->dump_file($this->root_path.$path, $content);
}
catch (filesystem_exception $e)
{
Expand All @@ -62,12 +67,12 @@ public function put_contents($path, $content)
*/
public function get_contents($path)
{
if (!$this->exists($this->phpbb_root_path.$path))
if (!$this->exists($this->root_path.$path))
{
throw new exception('', $path); // FILE_DONT_EXIST
}

if (($content = @file_get_contents($this->phpbb_root_path.$path)) === false)
if (($content = @file_get_contents($this->root_path.$path)) === false)
{
throw new exception('', $path); // CANNOT READ FILE
}
Expand All @@ -80,7 +85,7 @@ public function get_contents($path)
*/
public function exists($path)
{
return $this->filesystem->exists($this->phpbb_root_path.$path);
return $this->filesystem->exists($this->root_path.$path);
}

/**
Expand All @@ -90,7 +95,7 @@ public function delete($path)
{
try
{
$this->filesystem->remove($this->phpbb_root_path.$path);
$this->filesystem->remove($this->root_path.$path);
}
catch (filesystem_exception $e)
{
Expand All @@ -105,7 +110,7 @@ public function rename($path_orig, $path_dest)
{
try
{
$this->filesystem->rename($this->phpbb_root_path.$path_orig, $this->phpbb_root_path.$path_dest, false);
$this->filesystem->rename($this->root_path.$path_orig, $this->root_path.$path_dest, false);
}
catch (filesystem_exception $e)
{
Expand All @@ -120,7 +125,7 @@ public function copy($path_orig, $path_dest)
{
try
{
$this->filesystem->copy($this->phpbb_root_path.$path_orig, $this->phpbb_root_path.$path_dest, false);
$this->filesystem->copy($this->root_path.$path_orig, $this->root_path.$path_dest, false);
}
catch (filesystem_exception $e)
{
Expand All @@ -135,7 +140,7 @@ public function create_dir($path)
{
try
{
$this->filesystem->mkdir($this->phpbb_root_path.$path);
$this->filesystem->mkdir($this->root_path.$path);
}
catch (filesystem_exception $e)
{
Expand Down
39 changes: 0 additions & 39 deletions phpBB/phpbb/storage/controller.php

This file was deleted.

0 comments on commit 0d14c85

Please sign in to comment.