mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Fix #1127 : Update permalinks API to expose a file extension
This commit is contained in:
@@ -155,9 +155,7 @@ return call_user_func(
|
||||
return $deliver_content($app['request'], $session, $record, $subdef, $watermark, $stamp, $app);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef) use($app) {
|
||||
|
||||
$deliverPermaview = function ($sbas_id, $record_id, $subdef, $key, $app) {
|
||||
$databox = \databox::get_instance((int) $sbas_id);
|
||||
|
||||
$record = \media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
|
||||
@@ -177,10 +175,21 @@ return call_user_func(
|
||||
);
|
||||
|
||||
return $twig->render('overview.twig', $params);
|
||||
};
|
||||
|
||||
$app->get('/permalink/v1/{sbas_id}/{record_id}/{subdef}/', function (Request $request, $sbas_id, $record_id, $subdef) use ($app, $deliverPermaview) {
|
||||
$key = $request->query->get('token');
|
||||
|
||||
return $deliverPermaview($sbas_id, $record_id, $subdef, $key, $app);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef) use ($app, $session, $deliver_content) {
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef) use ($app, $deliverPermaview) {
|
||||
return $deliverPermaview($sbas_id, $record_id, $subdef, $key, $app);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$deliverPermalink = function ($label, $sbas_id, $record_id, $key, $subdef, $app, $session, $deliver_content) {
|
||||
|
||||
$databox = \databox::get_instance((int) $sbas_id);
|
||||
$record = \media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
|
||||
|
||||
@@ -225,6 +234,21 @@ return call_user_func(
|
||||
}
|
||||
|
||||
return $deliver_content($app['request'], $session, $record, $subdef, $watermark, $stamp, $app);
|
||||
};
|
||||
|
||||
$app->get('/permalink/v1/{sbas_id}/{record_id}/{subdef}/{label}',
|
||||
function (Request $request, $sbas_id, $record_id, $subdef, $label) use ($app, $deliverPermalink, $session, $deliver_content) {
|
||||
|
||||
$key = $request->query->get('token');
|
||||
|
||||
return $deliverPermalink($label, $sbas_id, $record_id, $key, $subdef, $app, $session, $deliver_content);
|
||||
})
|
||||
->assert('sbas_id', '\d+')
|
||||
->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef) use ($app, $deliverPermalink, $session, $deliver_content) {
|
||||
return $deliverPermalink($label, $sbas_id, $record_id, $key, $subdef, $app, $session, $deliver_content);
|
||||
}
|
||||
)
|
||||
->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
@@ -9,6 +9,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package subdefs
|
||||
@@ -144,13 +146,14 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
return sprintf('%spermalink/v1/%s/%d/%d/%s/%s/'
|
||||
, $registry->get('GV_ServerName')
|
||||
, $this->get_label()
|
||||
, $this->media_subdef->get_sbas_id()
|
||||
, $this->media_subdef->get_record_id()
|
||||
, $this->get_token()
|
||||
, $this->media_subdef->get_name()
|
||||
return sprintf('%spermalink/v1/%d/%d/%s/%s.%s?token=%s',
|
||||
$registry->get('GV_ServerName'),
|
||||
$this->media_subdef->get_sbas_id(),
|
||||
$this->media_subdef->get_record_id(),
|
||||
$this->media_subdef->get_name(),
|
||||
$this->get_label(),
|
||||
pathinfo($this->media_subdef->get_record()->get_original_name(), PATHINFO_EXTENSION),
|
||||
$this->get_token()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,13 +164,12 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
||||
*/
|
||||
public function get_page(registryInterface $registry)
|
||||
{
|
||||
return sprintf('%spermalink/v1/%s/%d/%d/%s/%s/view/'
|
||||
, $registry->get('GV_ServerName')
|
||||
, $this->get_label()
|
||||
, $this->media_subdef->get_sbas_id()
|
||||
, $this->media_subdef->get_record_id()
|
||||
, $this->get_token()
|
||||
, $this->media_subdef->get_name()
|
||||
return sprintf('%spermalink/v1/%d/%d/%s/?token=%s',
|
||||
$registry->get('GV_ServerName'),
|
||||
$this->media_subdef->get_sbas_id(),
|
||||
$this->media_subdef->get_record_id(),
|
||||
$this->media_subdef->get_name(),
|
||||
$this->get_token()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
||||
{
|
||||
$unicode_processor = new unicode();
|
||||
|
||||
$label = trim($label);
|
||||
$label = trim($label) ? trim($label) : 'untitled';
|
||||
while (strpos($label, ' ') !== false)
|
||||
$label = str_replace(' ', ' ', $label);
|
||||
|
||||
@@ -333,13 +335,21 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
||||
, ':activated' => '1'
|
||||
);
|
||||
|
||||
$error = null;
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
try {
|
||||
$stmt->execute($params);
|
||||
} catch (\PDOException $e) {
|
||||
$error = $e;
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
unset($stmt);
|
||||
|
||||
if ($error) {
|
||||
throw new RuntimeException('Permalink already exists', $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$permalink = self::getPermalink($databox, $media_subdef);
|
||||
$permalink->set_label(strip_tags($media_subdef->get_record()->get_title()));
|
||||
$permalink->set_label(strip_tags($media_subdef->get_record()->get_title(false, null, true)));
|
||||
|
||||
return $permalink;
|
||||
}
|
||||
|
62
lib/classes/patch/379.class.php
Normal file
62
lib/classes/patch/379.class.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class patch_379 implements patchInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $release = '3.7.9';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
private $concern = array(base::DATA_BOX);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param base $databox
|
||||
*/
|
||||
public function apply(base &$appbox)
|
||||
{
|
||||
$sql = 'UPDATE permalinks SET label = "untitled" WHERE label = ""';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -96,6 +96,7 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$this->assertTrue($appbox->get_session()->is_authenticated());
|
||||
$this->get_a_permalinkBCcompatibility();
|
||||
$this->get_a_permalink();
|
||||
}
|
||||
|
||||
@@ -104,6 +105,7 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$appbox->get_session()->logout();
|
||||
$this->assertFalse($appbox->get_session()->is_authenticated());
|
||||
$this->get_a_permalinkBCcompatibility();
|
||||
$this->get_a_permalink();
|
||||
}
|
||||
|
||||
@@ -129,8 +131,7 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
protected function get_a_permalink()
|
||||
protected function get_a_permalinkBCcompatibility()
|
||||
{
|
||||
$token = static::$records['record_1']->get_preview()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/whateverIwannt/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/' . $token . '/preview/';
|
||||
@@ -145,4 +146,21 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
protected function get_a_permalink()
|
||||
{
|
||||
$token = static::$records['record_1']->get_preview()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/preview/whateverIwannt.jpg?token=' . $token . '';
|
||||
|
||||
$crawler = $this->client->request('GET', $url);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
$url = '/permalink/v1/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/preview/?token=' . $token . '';
|
||||
$crawler = $this->client->request('GET', $url);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
|
||||
}
|
||||
}
|
||||
|
@@ -550,7 +550,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
$is_thumbnail = false;
|
||||
$record = $entry_item->get_record();
|
||||
|
||||
if (substr($current_attributes["url"], 0 - strlen("/preview/")) == "/preview/") {
|
||||
if (false !== strpos($current_attributes["url"], 'preview')) {
|
||||
$ressource = $record->get_subdef('preview');
|
||||
} else {
|
||||
$ressource = $record->get_thumbnail();
|
||||
|
@@ -16,6 +16,12 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract
|
||||
static::$object = media_Permalink_Adapter::getPermalink($databox, static::$records['record_1']->get_subdef('document'));
|
||||
}
|
||||
|
||||
public function testGet_label()
|
||||
{
|
||||
$this->assertInternalType('string', static::$object->get_label());
|
||||
$this->assertEquals('test001', static::$object->get_label());
|
||||
}
|
||||
|
||||
public function testGetPermalink()
|
||||
{
|
||||
$this->assertTrue((static::$object instanceof media_Permalink_Adapter));
|
||||
@@ -36,7 +42,7 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract
|
||||
static::$object->set_label('coucou les chicos');
|
||||
$this->assertEquals('coucou-les-chicos', static::$object->get_label());
|
||||
static::$object->set_label('');
|
||||
$this->assertEquals('', static::$object->get_label());
|
||||
$this->assertEquals('untitled', static::$object->get_label());
|
||||
static::$object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
|
||||
$this->assertEquals('JE-ANp-raeu234567890-e_ca', static::$object->get_label());
|
||||
}
|
||||
@@ -44,98 +50,59 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract
|
||||
public function testGet_url()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$url = $registry->get('GV_ServerName') . 'permalink/v1/' . static::$object->get_label() . '/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/' .
|
||||
static::$object->get_token() . '/document/';
|
||||
$url = $registry->get('GV_ServerName') . 'permalink/v1/'
|
||||
. static::$records['record_1']->get_sbas_id() . '/'
|
||||
. static::$records['record_1']->get_record_id()
|
||||
. '/document/' . static::$object->get_label()
|
||||
. '.' . pathinfo(static::$records['record_1']->get_original_name(), PATHINFO_EXTENSION)
|
||||
. '?token=' . static::$object->get_token();
|
||||
|
||||
$this->assertEquals($url, static::$object->get_url($registry));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_page().
|
||||
*/
|
||||
public function testGet_page()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$registry = registry::get_instance();
|
||||
$url = $registry->get('GV_ServerName') . 'permalink/v1/'
|
||||
. static::$records['record_1']->get_sbas_id() . '/'
|
||||
. static::$records['record_1']->get_record_id()
|
||||
. '/document/'
|
||||
. '?token=' . static::$object->get_token();
|
||||
|
||||
$this->assertEquals($url, static::$object->get_page($registry));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_id().
|
||||
*/
|
||||
public function testGet_id()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$this->assertInternalType('integer', static::$object->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_token().
|
||||
*/
|
||||
public function testGet_token()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$this->assertInternalType('string', static::$object->get_token());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_is_activated().
|
||||
*/
|
||||
public function testGet_is_activated()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$this->assertTrue(is_bool(static::$object->get_is_activated));
|
||||
$this->assertInternalType('boolean', static::$object->get_is_activated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_created_on().
|
||||
*/
|
||||
public function testGet_created_on()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$this->assertInstanceOf('DateTime', static::$object->get_created_on());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_last_modified().
|
||||
*/
|
||||
public function testGet_last_modified()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$this->assertInstanceOf('DateTime', static::$object->get_last_modified());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_label().
|
||||
* @expectedException Alchemy\Phrasea\Exception\RuntimeException
|
||||
*/
|
||||
public function testGet_label()
|
||||
public function testCreateAPermalinkAlreadyCreated()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCreate().
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$databox = static::$records['record_1']->get_databox();
|
||||
media_Permalink_Adapter::create($databox, static::$records['record_1']->get_subdef('document'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user