Commit 54c44a8a authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

fix images base path versus images urls

parent 9c340ba4
Pipeline #11869 passed with stage
in 44 seconds
...@@ -46,7 +46,7 @@ class Media extends ModelAbstract { ...@@ -46,7 +46,7 @@ class Media extends ModelAbstract {
'updated_at' => 1]); 'updated_at' => 1]);
if ($attribs['fullsize']) if ($attribs['fullsize'])
$attribs['fullsize'] = (new Url)->absolute($attribs['fullsize']); $attribs['fullsize'] = (new Url)->absoluteMedia($attribs['fullsize']);
return $attribs; return $attribs;
} }
...@@ -76,8 +76,7 @@ class Media extends ModelAbstract { ...@@ -76,8 +76,7 @@ class Media extends ModelAbstract {
public function _getFilePathFromIdentifier($identifier = '') { public function _getFilePathFromIdentifier($identifier = '') {
return '/' . implode('/', return '/' . implode('/',
array_merge(['images', array_merge([$this->getSize(),
$this->getSize(),
$this->getType()], $this->getType()],
$this->splitId($identifier))) $this->splitId($identifier)))
. '/'. $identifier; . '/'. $identifier;
......
...@@ -32,6 +32,11 @@ class ElectreRest2 extends Provider { ...@@ -32,6 +32,11 @@ class ElectreRest2 extends Provider {
} }
public function providerName() {
return 'Electre';
}
public function fetchRecord() { public function fetchRecord() {
if (!$this->_id || !$this->_secret) if (!$this->_id || !$this->_secret)
return $this->_newError(StatusCodeInterface::STATUS_UNAUTHORIZED, 'invalid_credentials'); return $this->_newError(StatusCodeInterface::STATUS_UNAUTHORIZED, 'invalid_credentials');
......
<?php <?php
namespace Pellicule; namespace Pellicule;
use \Pellicule\FileSystem;
class Url { class Url {
public function absoluteMedia($path) {
if (!$base_path = (new FileSystem)->getBasePath())
return $this->absolute($path);
if (!preg_match('|([^./]+)|', $base_path, $matches, PREG_OFFSET_CAPTURE))
return $this->absolute($path);
$base_path = $this->_ensureSlash(substr($base_path, $matches[1][1]));
if ('/' == substr($base_path, -1))
$base_path = substr($base_path, 0, strlen($base_path)-1);
return $this->absolute($base_path . $this->_ensureSlash($path));
}
public function absolute($path) { public function absolute($path) {
if ($this->_hasScheme($path)) return $this->_hasScheme($path)
return $path; ? $path
: $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $path;
}
if ('/' != substr($path, 0, 1))
$path = '/' . $path;
return $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $path; protected function _ensureSlash($path) {
return ('/' != substr($path, 0, 1))
? '/' . $path
: $path;
} }
......
...@@ -14,6 +14,8 @@ class MediaElectreRest2Test extends TestCase { ...@@ -14,6 +14,8 @@ class MediaElectreRest2Test extends TestCase {
Media::getFileSystem()->whenCalled('fileExists')->answers(true); Media::getFileSystem()->whenCalled('fileExists')->answers(true);
FileSystem::setBasePath('./images');
FileSystem::getFileSystem() FileSystem::getFileSystem()
->whenCalled('fileExists')->answers(true) ->whenCalled('fileExists')->answers(true)
->whenCalled('filePutContents')->answers(null) ->whenCalled('filePutContents')->answers(null)
...@@ -45,7 +47,7 @@ class MediaElectreRest2Test extends TestCase { ...@@ -45,7 +47,7 @@ class MediaElectreRest2Test extends TestCase {
$call_params = FileSystem::getFileSystem() $call_params = FileSystem::getFileSystem()
->getAttributesForLastCallOn('filePutContents'); ->getAttributesForLastCallOn('filePutContents');
$this->assertEquals('vfs://myDir/images/fullsize/cover/9/7/8/2/9782818976173.jpg', $this->assertEquals('./images/fullsize/cover/9/7/8/2/9782818976173.jpg',
$call_params[0]); $call_params[0]);
} }
......
...@@ -3,6 +3,7 @@ namespace Pellicule\Tests; ...@@ -3,6 +3,7 @@ namespace Pellicule\Tests;
use \Pellicule\Models\Record; use \Pellicule\Models\Record;
use \Pellicule\Models\Media; use \Pellicule\Models\Media;
use \Pellicule\FileSystem;
class MediaLocalRecordTest extends TestCase { class MediaLocalRecordTest extends TestCase {
...@@ -134,6 +135,7 @@ abstract class MediaWithElectreTestCase extends TestCase { ...@@ -134,6 +135,7 @@ abstract class MediaWithElectreTestCase extends TestCase {
public function setUp(){ public function setUp(){
parent::setUp(); parent::setUp();
FileSystem::setBasePath('./images');
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true)); Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
$this->_http_client $this->_http_client
...@@ -406,6 +408,7 @@ abstract class MediaWithOrbTestCase extends TestCase { ...@@ -406,6 +408,7 @@ abstract class MediaWithOrbTestCase extends TestCase {
public function setUp(){ public function setUp(){
parent::setUp(); parent::setUp();
FileSystem::setBasePath('./images');
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true)); Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
Media::setTimeSource(new TimeSourceForTest('2020-01-01 00:00:00')); Media::setTimeSource(new TimeSourceForTest('2020-01-01 00:00:00'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment