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 {
'updated_at' => 1]);
if ($attribs['fullsize'])
$attribs['fullsize'] = (new Url)->absolute($attribs['fullsize']);
$attribs['fullsize'] = (new Url)->absoluteMedia($attribs['fullsize']);
return $attribs;
}
......@@ -76,8 +76,7 @@ class Media extends ModelAbstract {
public function _getFilePathFromIdentifier($identifier = '') {
return '/' . implode('/',
array_merge(['images',
$this->getSize(),
array_merge([$this->getSize(),
$this->getType()],
$this->splitId($identifier)))
. '/'. $identifier;
......
......@@ -32,6 +32,11 @@ class ElectreRest2 extends Provider {
}
public function providerName() {
return 'Electre';
}
public function fetchRecord() {
if (!$this->_id || !$this->_secret)
return $this->_newError(StatusCodeInterface::STATUS_UNAUTHORIZED, 'invalid_credentials');
......
<?php
namespace Pellicule;
use \Pellicule\FileSystem;
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) {
if ($this->_hasScheme($path))
return $path;
return $this->_hasScheme($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 {
Media::getFileSystem()->whenCalled('fileExists')->answers(true);
FileSystem::setBasePath('./images');
FileSystem::getFileSystem()
->whenCalled('fileExists')->answers(true)
->whenCalled('filePutContents')->answers(null)
......@@ -45,7 +47,7 @@ class MediaElectreRest2Test extends TestCase {
$call_params = FileSystem::getFileSystem()
->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]);
}
......
......@@ -3,6 +3,7 @@ namespace Pellicule\Tests;
use \Pellicule\Models\Record;
use \Pellicule\Models\Media;
use \Pellicule\FileSystem;
class MediaLocalRecordTest extends TestCase {
......@@ -134,6 +135,7 @@ abstract class MediaWithElectreTestCase extends TestCase {
public function setUp(){
parent::setUp();
FileSystem::setBasePath('./images');
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
$this->_http_client
......@@ -406,6 +408,7 @@ abstract class MediaWithOrbTestCase extends TestCase {
public function setUp(){
parent::setUp();
FileSystem::setBasePath('./images');
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
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