Commit 7aca376d authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

dev#105493 websvc integration

Adding fullsize entry management
Adding created_at and update_at management
parent 071efbb8
Pipeline #10839 passed with stage
in 54 seconds
'105493' =>
['Label' => $this->_('utilisation dans le serveur de cache websvc'),
'Desc' => '',
'Image' => '',
'Video' => '',
'Category' => '',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => '',
'Test' => '',
'Date' => '2020-07-10'],
\ No newline at end of file
- ticket #105493 : utilisation dans le serveur de cache websvc
\ No newline at end of file
<?php
return [
'URL_BASE' => 'https://localhost/pellicule'
];
?>
\ No newline at end of file
create table if not exists `records` (
`id` int(11) unsigned not null auto_increment,
`ean` varchar(255),
`isbn` varchar(255),
`ark` varchar(255),
`ean` varchar(255) null,
`isbn` varchar(255) null,
`ark` varchar(255) null,
`created_at` datetime not null,
`updated_at` datetime not null,
primary key (`id`),
......
alter table `media`
add column `fullsize` varchar(255) null default '';
......@@ -7,7 +7,18 @@ use \Slim\Psr7\Factory\RequestFactory;
class FileSystem {
use HttpClientAware;
protected static $_base_path;
protected static $_base_path,
$_base_url;
public static function setBaseUrl($url_base) {
static::$_base_url = $url_base;
}
public static function baseUrl(){
return static::$_base_url;
}
public static function setBasePath($path) {
static::$_base_path = $path;
......
......@@ -14,7 +14,12 @@ class Media extends ModelAbstract {
protected
$_table_name = 'media',
$_belongs_to = [ 'record' => ['model' => Record::class ] ];
$_belongs_to = [ 'record' => ['model' => Record::class ] ],
$_default_attribute_values = [ 'id' => 0,
'created_at' => '',
'updated_at' => ''
];
/** @category testing */
......@@ -34,12 +39,22 @@ class Media extends ModelAbstract {
return array_intersect_key($this->getRawAttributes(),
['type' => 1,
'url' => 1,
'fullsize' => 1,
'provider' => 1,
'created_at' => 1,
'updated_at' => 1]);
}
public function beforeSave() {
$this->setFullsize( \Pellicule\FileSystem::baseUrl() . $this->getFilePath());
$datenow = (new \DateTime())->format('Y-m-d H:i:s');
if (!$this->getCreatedAt())
$this->setCreatedAt($datenow);
$this->setUpdatedAt($datenow);
}
public function afterSave() {
if (!$this->fileExists())
$this->getFileSystem()->download($this->getUrl(), $this->getFilePath());
......
......@@ -13,7 +13,18 @@ class Record extends ModelAbstract {
'model' => Media::class,
'role' => 'record'
]
];
],
$_default_attribute_values = [ 'id' => 0,
'created_at' => '',
'updated_at' => ''];
public function beforeSave(){
$datenow = (new \DateTime())->format('Y-m-d H:i:s');
if (!$this->getCreatedAt())
$this->setCreatedAt($datenow);
$this->setUpdatedAt($datenow);
}
public function asJSON() {
......
......@@ -29,6 +29,7 @@ class Electre extends Provider {
return $this;
$this->_client_secret = $data['client_secret'];
return $this;
}
......
......@@ -47,10 +47,10 @@ abstract class Provider {
$first_credentials = array_shift($credentials);
if ($first_credentials['provider'] == 'electre')
return new Electre($credentials);
return new Electre($first_credentials);
if ($first_credentials['provider'] == 'orb')
return new Orb($credentials);
return new Orb($first_credentials);
return new Error(StatusCodeInterface::STATUS_BAD_REQUEST,
'no valid params provided');
......@@ -77,7 +77,8 @@ abstract class Provider {
public function setSearchArgs($args) {
$this->_search_args = $args;
if (isset($args['isbn'])|| isset($args['ean']))
$this->_search_args = $args;
return $this;
}
......
......@@ -18,7 +18,9 @@ class MediaLocalRecordTest extends TestCase {
public function setUp(){
parent::setUp();
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
Media::setFileSystem($this->mock()
->whenCalled('fileExists')->answers(true)
->whenCalled('baseUrl')->answers('https://localhost/pellicule/'));
$this->fixture(Record::class,
['id' => 1,
......@@ -33,7 +35,7 @@ class MediaLocalRecordTest extends TestCase {
'url' => 'http://image.org/city.jpg',
'provider' => 'Me',
'created_at' => '2020-01-13 08:00:00',
'updated_at' => '2020-01-16 08:00:00'
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
]);
$this->fixture(Media::class,
......@@ -43,8 +45,9 @@ class MediaLocalRecordTest extends TestCase {
'url' => 'http://image.org/cityback.jpg',
'provider' => 'Me',
'created_at' => '2020-01-21 08:00:00',
'updated_at' => '2020-02-14 08:00:00'
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
]);
}
......@@ -63,15 +66,17 @@ class MediaLocalRecordTest extends TestCase {
$expected = [ 'media'=>
[
[ 'url' => 'http://image.org/city.jpg',
'fullsize' => FileSystem::baseUrl() . Media::find(135)->getFilePath(),
'provider' => 'Me',
'created_at' => '2020-01-13 08:00:00',
'updated_at' => '2020-01-16 08:00:00',
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s'),
'type' => 'cover'],
[ 'url' => 'http://image.org/cityback.jpg',
'type' => 'back_cover',
'provider' => 'Me',
'fullsize' => FileSystem::baseUrl() . Media::find(147)->getFilePath(),
'created_at' => '2020-01-21 08:00:00',
'updated_at' => '2020-02-14 08:00:00'
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
]
]
];
......@@ -143,10 +148,18 @@ abstract class MediaWithElectreTestCase extends TestCase {
[ 'media' => [
['url'=> 'http://image.org/city.jpg',
'provider' => 'Electre',
'type' => 'cover'],
'fullsize' => '',
'type' => 'cover',
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
],
['url' => 'http://image.org/cityback.jpg',
'provider' => 'Electre',
'type' => 'back_cover']
'fullsize' => '',
'type' => 'back_cover',
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
]
]
];
......@@ -167,6 +180,7 @@ class MediaWithElectreOnIsbnTest extends MediaWithElectreTestCase {
$headers = ['Authorization' => ['Pellicule ' . $payload]];
$this->_response = $this->httpGet('/1.0/media/isbn/2259228194', $headers);
}
......@@ -183,6 +197,7 @@ class MediaWithElectreOnIsbnTest extends MediaWithElectreTestCase {
class MediaWithElectreOnEanTest extends MediaWithElectreTestCase {
public function setUp() {
parent::setUp();
$this->_response = $this->httpGet('/1.0/media/ean/2259228194',
['Authorization' => ['Pellicule ' . base64_encode(json_encode(['provider'=> 'electre',
'client_secret'=>'leeloo',
......@@ -203,6 +218,7 @@ class MediaWithElectreWithSearchError extends TestCase {
public function setUp(){
parent::setUp();
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
$this->_http_client
->whenCalled('post')
->answers($this->_forgePSR7Response(['content' => '{"access_token":"MyPr3ttyT0k3n","expires_in":3600,"token_type":"Bearer"}']))
......@@ -239,6 +255,7 @@ class MediaWithElectreWithInvalidCredentialsTest extends TestCase {
public function setUp(){
parent::setUp();
Media::setFileSystem($this->mock()->whenCalled('fileExists')->answers(true));
$this->_http_client
->whenCalled('post')
->answers($this->_forgePSR7Response(['status'=> '400', 'content' => '{"error": "invalid_client"}']));
......@@ -408,7 +425,11 @@ abstract class MediaWithOrbTestCase extends TestCase {
[ 'media' => [
['url'=> 'https://products-images.di-static.com/image/orb-9162f416a0b7b2e64a1f5480db8d4394/2259228234-475x500-1.jpg',
'provider' => 'Orb',
'type' => 'cover']
'fullsize' => '',
'type' => 'cover',
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
]
]
];
......
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